1、创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至单独数据/data目录;

(1)新建立一个分区

[root@centos6 wuzhibin]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

         switch off the mode (command 'c') and change display units to

         sectors (command 'u').

Command (m for help): n

(2)设置为主分区

Command action

   e   extended

   p   primary partition (1-4)

p

(3)设置为第3个主分区

Partition number (1-4): 3

(4)设置分区容量为10G

First cylinder (2811-26108, default 2811): 2811

Last cylinder, +cylinders or +size{K,M,G} (2811-26108, default 26108): +10G

(5)保存设置退出

Command (m for help): w

(6)使用partx -a命令激活新划分的分区,这样可以不用重新启动电脑

[root@centos6 wuzhibin]# partx -a /dev/sda

(7)格式化新分区为EXT4

[root@centos6 wuzhibin]# mke2fs -t ext4 /dev/sda3

(8)建立/data目录

[root@centos6 ~]# mkdir /data

(9)设置新分区的卷标为/data

[root@centos6 ~]# e2label /dev/sda3 /data

(10)设置将新分区开机自动挂载至/data目录

[root@centos6 ~]# vi /etc/fstab

将/dev/sda3   /data    ext4    default  0 0添加到最后一行,保存退出即可完成开机自动挂载/data目录

2、显示`netstat -tan`命令结果中以‘LISTEN’后跟0个、1个或者多个空白字符结尾的行;

linux运维实战练习案例-2015年12月20日-12月31日(第一次)_linux

 

3、添加用户nginx、zabbix、tomcat、nologin以及hadoop用户(nologin用户的shell为/sbin/nologin);而后找出/etc/passwd文件中用户名与其shell名相同的行;

(1)新建立用户

[root@centos6 wuzhibin]# useradd nginx

[root@centos6 wuzhibin]# useradd zabbix

[root@centos6 wuzhibin]# useradd tomcat

[root@centos6 wuzhibin]# useradd hadoop

[root@centos6 wuzhibin]# useradd -s /sbin/nologin nologin

(2)找出用户名与SHELL名相同的行

[root@centos6 wuzhibin]# grep "^\([[:alnum:]]\+\>\).*\1$" /etc/passwd

(这个是抄写的,我目前还是不懂的怎么去用,好多命令还是不熟悉,新手入门,这段时间都忙着看视频,视频讲的命令好多都没来的及练习,后续还是努力跟上进度,多多练习。)

4、找出/etc/rc.d/init.d/functions文件中某单词(单词中间可以存在下划线)后面跟着一组小括号的行;

[root@centos6 wuzhibin]# egrep -o "\<[[[:alnum:]_]+\>\(\)" /etc/rc.d/init.d/functions

(这是抄写的)

5、使用echo输出一个路径,而后egrep找出其路径基名;进一步的使用egrep取出其目录名(注意是目录名,而非目录路径);

[root@centos6 wuzhibin]# echo /etc/init.d/functions/ | egrep -o "[[:alnum:]]*/?$" | cut -d/ -f1

(这是抄写的)

6、查找/usr目录下不属于root、bin或hadoop的所有文件;

[root@centos6 wuzhibin]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls

(这是抄写的)

7、某天系统被入侵了,黑客在你系统下留下木马文件:

现需要查找当前系统上没有属主或属组,且最近一周内曾被访问过的所有文件;

另外,需要查找/etc目录下大于20k且类型为普通文件的所有文件;

(1)找出1周内被访问的文件,没有属主或者属组的。

[root@centos6 wuzhibin]# find / -nouser -o -nogroup -atime -7

(2)查找/etc下大于20K类型为普通的所有文件

[root@centos6 wuzhibin]# find /etc -size +20k -type f -exec ls -lh {} \;

(抄写的)

8、创建目录/test/data,让某组内普通用户对其有写权限,且创建的所有文件的属组为目录所属的组;此外,每个用户仅能删除自己的文件。

[root@centos6 wuzhibin]# mkdir -p /test/data

[root@centos6 data]# chmod g+ws,o+t /test/data

(抄写的)