馬哥linux運維實戰練習案例-2015年(第一次作業)

一、實戰案例(練習)

 

假如你學習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 

wKioL1aDraTDtjxWAAAtmfwuAFo874.png

wKiom1aDrYfSN19LAAAoFkgAqmc113.png


2`netstat -tan`命令果中以‘LISTEN’後跟01或者多空白字符尾的行;

命令如下:netstat -tan |grep "LISTEN[[:space:]]*$"

wKiom1aDrbHANjvSAAAbo1w90XY296.png

3、添加用nginx、zabbix、tomcat、nologin以及hadoop用nologinshell/sbin/nologin);而後找出/etc/passwd文件中用shell名相同的行;

1、添加用nginx、zabbix、tomcat、nologin以及hadoop用nologinshell/sbin/nologin

wKiom1aDrcbxy1r0AAAPvcvgK_w138.png

2、修改nologin的shell路

wKioL1aDrfGhR5ZvAAALYySJuLE918.png

3、找出/etc/passwd文件中用shell名相同的行

wKiom1aDrf7wi3uxAAAUXXpaJvY768.png

4、找出/etc/rc.d/init.d/functions文件中某單詞單詞可以存在下劃線)後面跟着一小括的行;

cat /etc/rc.d/init.d/functions | grep -E"\<[[:alpha:]]*_?[[:alpha:]]*[(][)]"

wKioL1aDrjnRc6jtAAApopoGbgg627.png

5、使用echo出一,而後egrep找出其路基名;一步的使用egrep取出其目名(注意是目名,而非目);

路徑基名:echo"/etc/rc.d/init.d/" | egrep -o "[^/]+/?$" | cut -d"/" -f1

wKiom1aDrl2SfkQvAAAIxsluum0204.png

 

6/usr下不root、bin或hadoop的所有文件;

[root@localhost ~]# find /usr -not \( -userroot -o -user bin -o -user hadoop \)

wKioL1aDrpWTw33eAAAPczJ6rkA210.png

7、某天系被***了,***在下留下木文件:

需要前系主或屬組,且最近一週曾被訪問過的所有文件;

1)# find / -nouser -a -nogroup -a -atime -7

 

另外,需要/etc下大於20k普通文件的所有文件;

2)#find /etc -size +20k  -type f

wKiom1aDrpqxcfs4AACW-0MmWB8768.png

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/

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章