一、实战案例(练习)

 

假如你学习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/