1、创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至单独数据/data目录;
分析:1)、为服务器添加一块硬盘
2)、创建挂载点
3)、分区格式化(指定文件系统类型)
4)、配置fstab文件开机自动挂载
配置实现:
[root@Python ~]# mkdir /data 创建挂载点 [root@Python ~]# fdisk -l /dev/sd[a-z] 查看 Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000cf831 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2614 20480000 83 Linux /dev/sda3 2614 5164 20480000 83 Linux /dev/sda4 5164 15666 84356096 5 Extended …… …… Disk /dev/sdb: 21.5 GB, 21474836480 bytes 发现sdb 21.5GB可用空间, 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@Python ~]# fdisk /dev/sdb Command (m for help): n 新建分区 Command action e extended p primary partition (1-4) p Partition number (1-4):1 创建第一个主分区 First cylinder (1-2610, default 1): +10G Last cylinder, +cylinders or +size{K,M,G} (1305-2610, default 2610): +10G Command (m for help): w The partition table has been altered! [root@Python ~]# mkfs.ext4 /dev/sdb1 创建文件系统(ext4) mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) ……… ……… 8096 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 28 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@Python ~]# blkid /dev/sdb1 /dev/sdb1: UUID="b9543cc7-b7e3-4ecb-81b1-15858a9ff8b8" TYPE="ext4" [root@Python ~]# fdisk -l /dev/sdb1 查看是否创建成功 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xe3688f7a Device Boot Start End Blocks Id System /dev/sdb1 1305 2610 10490445 83 Linux [root@Python ~]# vim /etc/fstab 添加到fstab文件中,使其开机自动挂载 # # /etc/fstab # Created by anaconda on Sat Dec 19 04:05:20 2015 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=4703f9bc-3b00-4856-ac54-e0682dcdc09f / ext4 defaults 1 1 ………… UUID=8ec90e29-1263-48be-bb41-313c0dacd63b /var ext4 defaults 1 2 UUID=07ff66fb-50c5-45b6-843f-928c2ad6325a swap swap defaults 0 0 UUID=b9543cc7-b7e3-4ecb-81b1-15858a9ff8b8 /data ext4 defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0
2、显示`netstat -tan`命令结果中以‘LISTEN’后跟0个、1个或者多个空白字符结尾的行;
分享:1)、使用提到的`netstat -tan`查看结果
2)、显示每一行以'LISTEN'后跟0、1、多个空白字符结尾的行
配置实现:
[root@Python ~]# netstat -tan 查看信息 Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:40374 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 192.168.10.200:22 192.168.10.1:7033 ESTABLISHED tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:631 :::* LISTEN tcp 0 0 ::1:25 :::* LISTEN tcp 0 0 :::42318 :::* LISTEN tcp 0 0 :::111 :::* LISTEN [root@Python ~]# netstat -tan | grep -E "\<LISTEN\>[[:space:]]*$" 实现结果 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:40374 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN ………… …………
3、添加用户nginx、zabbix、tomcat、nologin以及hadoop用户(nologin用户的shell为/sbin/nologin);而后找出/etc/passwd文件中用户名与其shell名相同的行;
分析:1)、添加nginx、zabbix、tomcat、nologin、hadoop,注意nologin的shell
2)、验证是否添加成功
3)、查找/etc/passwd配置文件中用户名与其shell同名的行
配置实现:
[root@Python ~]#useradd nginx 添加指定用户 [root@Python ~]#useradd zabbix [root@Python ~]#useradd tomcat [root@Python ~]#useradd hadoop [root@Python ~]#useradd -s /sbin/nologin nologin [root@Python ~]#cat /etc/passwd 验证是否添加成功 [root@Python ~]#cat /etc/passwd | grep "^\<([[:alunm:]])\+\>.*\1$" sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt bash:x:503:505::/home/bash:/bin/bash nologin:x:506:508::/home/nologin:/sbin/nologin
4、找出/etc/rc.d/init.d/functions文件中某单词(单词中间可以存在下划线)后面跟着一组小括号的行;
分享:1)、查找/etc/rc.d/init.d/functions 文件中有小括号的所有行
配置实现:
[root@Python ~]#cat /etc/rc.d/init.d/functions |grep -E "\<[[:alpha:]]+_.*[[:alpha:]]+\>\(\)"
5、使用echo输出一个路径,而后egrep找出其路径基名;进一步的使用egrep取出其目录名(注意是目录名,而非目录路径);
分析:1)、随意给echo一个路径并输出的结果使用egrep找出其路径基名
2)、同样使用egrep取出其目录名
配置实现:
[root@Python ~]# echo /etc/sysconfig/network-scripts/ifcfg-eth0 |grep -o -E '[^/]+/?$' | cut -d"/" -f1 取出基本 ifcfg-eth0 [root@Python ~]# echo /etc/sysconfig/network-scripts/ifcfg-eth0 | egrep -o "^[/].*[/]" | cut -d"/" -f4 network-scripts
6、查找/usr目录下不属于root、bin或hadoop的所有文件;
[root@Python ~]# find /usr -not -user bin -a -not -user root -a -not -user hadoop
7、某天系统被入侵了,黑客在你系统下留下木马文件:
现需要查找当前系统上没有属主或属组,且最近一周内曾被访问过的所有文件;
另外,需要查找/etc目录下大于20k且类型为普通文件的所有文件;
[root@Python ~]# find / -nouser -a -nogroup -a -atime -7 [root@Python ~]# find /etc -size +20k -type -f
8、创建目录/test/data,让某组内普通用户对其有写权限,且创建的所有文件的属组为目录所属的组;此外,每个用户仅能删除自己的文件。
[root@Python ~]#mkdir /test/data [root@Python ~]#chmod u+s /test/data [root@Python ~]#chmod g+s /test/data [root@Python ~]#chmod o+t /test/data [root@Python ~]# ls -dl /test/data 验证 drwsr-sr-t. 2 root root 4096 Jan 1 04:57 /test/data