您的位置:首页 > 运维架构 > Linux

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

2015-12-27 17:19 507 查看
一、实战案例(练习)内容 假如你学习完Linux,想找一份儿Linux相关的运维工作,某天你接到一家公司给出的邀请,你来到该公司面试,面试前,运维主管给你出了一些简单的笔试题,题目如下: 1、创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至单独数据/data目录;操作步骤:(1).使用fdisk工具创建一个10G的分区[root@localhost ~]# fdisk /dev/sda 欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。使用写入命令前请三思。命令(输入 m 获取帮助):nAll primary partitions are in use添加逻辑分区 8起始 扇区 (42991616-125829119,默认为 42991616):将使用默认值 42991616Last 扇区, +扇区 or +size{K,M,G} (42991616-125829119,默认为 125829119):+10G分区 8 已设置为 Linux 类型,大小设为 10 GiB命令(输入 m 获取帮助):w(2).更新分区表,让内核识别新增加的分区[root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-7[root@localhost ~]# partx -a /dev/sda partx: /dev/sda: error adding partitions 1-8然后可以通过:[root@localhost ~]# cat /proc/partitions 查看新添加分区是否已经被内核识别 。(3).使用mke2fs 对已经创建好的分区进行格式化,文件系统为ext4 mke2fs -t ext4 /dev/sda8格式化完成后可以通过blkid工具查看分区文件系统的类型 blkid /dev/sda8 (4).将创建好的分区挂载到data目录下: mkdir /datamount /dev/sda8 /data(5).将/dev/sda8设置为重启后自动挂载到/data目录: vim /etc/fstab在最后一行写入写入内容: /dev/sda8 /data Over!
2、显示`netstat -tan`命令结果中以‘LISTEN’后跟0个、1个或者多个空白字符结尾的行;[root@localhost ~]# netstat -tan |grep "LISTEN[[:space:]]*$" 3、添加用户nginx、zabbix、tomcat、nologin以及hadoop用户(nologin用户的shell为/sbin/nologin);而后找出/etc/passwd文件中用户名与其shell名相同的行;(1)添加用户[root@localhost ~]# useradd nginx[root@localhost ~]# useradd zabbix[root@localhost ~]# useradd tomcat[root@localhost ~]# useradd nologin -s /sbin/nologin[root@localhost ~]# useradd hadoop(2)找出/etc/passwd文件中用户名与其shell名相同的行[root@localhost ~]# grep "^\([[:alnum:]]\+\>\).*\1$" /etc/passwd 4、找出/etc/rc.d/init.d/functions文件中某单词(单词中间可以存在下划线)后面跟着一组小括号的行;(1)[root@localhost ~]# grep "_*[[:alpha:]]*\(_*[[:alpha:]]*\)*[[:space:]]*()" /etc/rc.d/init.d/functions (2)[root@localhost ~]# grep -E -o "^[_[:alpha:]]+\(\)" /etc/rc.d/init.d/functions 5、使用echo输出一个路径,而后egrep找出其路径基名;进一步的使用egrep取出其目录名(注意是目录名,而非目录路径);(1)取基名#echo "/mnt/sdcs.d.sdf" | grep -E -o "[^/]+/?$" | cut -d"/" -f1(2)取路径#echo "/mnt/sdcs.d.sdf/school/banji/name.txt" | grep -E -o "^/.*/" 6、查找/usr目录下不属于root、bin或hadoop的所有文件;[root@localhost ~]# find /usr -not -user root -a -not -user bin -a -not -user hadoop7、某天系统被入侵了,黑客在你系统下留下木马文件:现需要查找当前系统上没有属主或属组,且最近一周内曾被访问过的所有文件;另外,需要查找/etc目录下大于20k且类型为普通文件的所有文件;(1)[root@localhost ~]#find / -nouser -o -nogroup -atime -7(2)[root@localhost ~]#find /etc -size +20k -type f 8、创建目录/test/data,让某组内普通用户对其有写权限,且创建的所有文件的属组为目录所属的组;此外,每个用户仅能删除自己的文件。[root@localhost ~]# mkdir -p /test/data[root@localhost ~]# groupadd wgroup[root@localhost ~]# chown :wgroup /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 wgroup 6 12月 27 10:36 /test/data/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: