一、實戰案例(練習)內容
假如你學習完Linux,想找一份兒Linux相關的運維工作,某天你接到一家公司給出的邀請,你來到該公司面試,面試前,運維主管給你出了一些簡單的筆試題,題目如下:
1、創建一個10G的文件系統,類型爲ext4,要求開機可自動掛載至單獨數據/data目錄;
創建一個10GB的分區
1、首先添加一個10GB的分區
[root@localhost mnt]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until youdecide to write them.
Be careful before using the write command.
Device does not contain a recognized partitiontable
Building a new DOS disklabel with diskidentifier 0xd1d7785c.
Command (m for help): n^Hp
Partition type:
p primary (0 primary, 0extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-31457279, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G}(2048-31457279, default 31457279): +10G
Partition 1 of type Linux and of size 10 GiBis set
Command (m for help): p
Disk /dev/sdb: 16.1 GB, 16106127360 bytes,31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk label type: dos
Disk identifier: 0xd1d7785c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partx -s /dev/sdb1
NR START END SECTORS SIZE NAME UUID
1 2048 20973567 20971520 10G
2、格式化爲ext4格式
[root@localhost mnt]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
32768,98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accountinginformation: done
3、創建/data目錄,並將磁盤掛載,同時設置開機自動掛載
[root@localhost ~]# mkdir data/
[root@localhost ~]# mount /dev/sdb1 /root/data
編輯/etc/fstab文件,添加:/dev/sdb1 /root/data/ ext4 defaults 00
2、顯示`netstat -tan`命令結果中以‘LISTEN’後跟0個、1個或者多個空白字符結尾的行;
命令如下:netstat -tan |grep "LISTEN[[:space:]]*$"
3、添加用戶nginx、zabbix、tomcat、nologin以及hadoop用戶(nologin用戶的shell爲/sbin/nologin);而後找出/etc/passwd文件中用戶名與其shell名相同的行;
1、添加用戶nginx、zabbix、tomcat、nologin以及hadoop用戶(nologin用戶的shell爲/sbin/nologin)
2、修改nologin的shell路徑
3、找出/etc/passwd文件中用戶名與其shell名相同的行
4、找出/etc/rc.d/init.d/functions文件中某單詞(單詞中間可以存在下劃線)後面跟着一組小括號的行;
cat /etc/rc.d/init.d/functions | grep -E"\<[[:alpha:]]*_?[[:alpha:]]*[(][)]"
5、使用echo輸出一個路徑,而後egrep找出其路徑基名;進一步的使用egrep取出其目錄名(注意是目錄名,而非目錄路徑);
路徑基名:echo"/etc/rc.d/init.d/" | egrep -o "[^/]+/?$" | cut -d"/" -f1
6、查找/usr目錄下不屬於root、bin或hadoop的所有文件;
[root@localhost ~]# find /usr -not \( -userroot -o -user bin -o -user hadoop \)
7、某天系統被***了,***在你系統下留下木馬文件:
現需要查找當前系統上沒有屬主或屬組,且最近一週內曾被訪問過的所有文件;
1)# find / -nouser -a -nogroup -a -atime -7
另外,需要查找/etc目錄下大於20k且類型爲普通文件的所有文件;
2)#find /etc -size +20k -type f
8、創建目錄/test/data,讓某組內普通用戶對其有寫權限,且創建的所有文件的屬組爲目錄所屬的組;此外,每個用戶僅能刪除自己的文件。
[root@localhost ~]# mkdir -p /test/data
[root@localhost ~]# groupadd test
[root@localhost ~]# chown :test/test/data
[root@localhost ~]# chmod g+w/test/data
[root@localhost ~]# chmod g+s/test/data
[root@localhost ~]# chmod o+t/test/data
[root@localhost~]# ls -ld /test/data/
drwxrwsr-t. 2 root test 6 Dec 30 16:53/test/data/