Linux rhcsa认证考试试题模拟

声明: 此套试题是2017年rhcsa考试题库,本题库需配合相对应的机器操作,实验环境在我的网盘下载

考试环境:

RHCSA Requirements

完成下列操作,当您收到成绩时,这部分的成绩会标识为RHCSA,并且另有一个总分。您必须得到300分钟的210分或者210分以上才能获得认证
  •  第一题:重置系统密码并完成网络配置
  •  第二题:配置SeLinux
  •  第三题:配置YUM软件仓库
  •  第四题:调整逻辑卷容量
  •  第五题:创建用户和用户组
  •  第六题:配置文件/var/tmp/fstab的权限
  •  第七题:建立计划任务
  •  第八题:创建共享目录
  •  第九题:升级系统内核
  •  第十题:绑定外部验证服务
  •  第十一题:配置autofs
  •  第十二题:配置NTP
  •  第十三题:创建一个归档
  •  第十四题:配置一个用户账号
  •  第十五题:添加一个swap分区
  •  第十六题:查找文件
  •  第十七题:查找字符串
  •  第十八题:创建一个逻辑卷

第一题:重置系统密码并完成网络配置

重置系统密码

       请修改系统密码为rrhh9708,并且能够正常登陆。

根据以下信息配置网络
  •  主机名:desktop.group8.example.com
  •  IP地址:172.24.8.10
  •  子网掩码:255.255.255.0
  •  网关:172.24.8.254
  •  名称服务:172.24.8.254

参考答案:

  1. 重启系统:在已经开机的Desktop虚拟机上,同时按下Ctrl+Alt+Del三键。
  2. 在Grub Boot Loader 倒计时读秒结束前,按下任意键。
  3. 选中默认的第一个启动条目,并按下字母e键。

image
4、进入启动条目编辑界面后,通过键盘方向键(↓),找到第一个以linux16开头的行,并通过按下Ctrl+e快速把光标定位到该行的行末,输入<空格键> rd.break。

image
5、确定没错之后,按下 Ctrl + x ,以修改后的配置引导系统,系统启动到临时内核shell界面,输入以下指令即可修改密码。
image
注意:修改密码后,首次重启的时间将会比较长,因为系统将对所有文件进行 SeLinux 打标,请耐心等待,整个过程并非死机,请勿在打标过程中手动强制再次重启,否则系统将会永久性损坏导致无法开机。
image

6、成功启动系统后,输入账号root,密码为题目要求修改的密码后,完成网络配置,命令如下。

[root@localhost ~]# nmcli device  ---查看本机的网卡设备
DEVICE  TYPE      STATE         CONNECTION 
eth0    ethernet  disconnected  --         
lo      loopback  unmanaged     --         
[root@localhost ~]# nmcli connection   ---查看本机的连接配置
NAME  UUID                                  TYPE            DEVICE 
eth0  4dc8c88c-69b0-4203-a0a6-3671ceb0cd7e  802-3-ethernet  --     
[root@localhost ~]# 

修改名为eth0连接配置信息

[root@localhost ~]# nmcli connection modify eth0 ipv4.addresses 172.24.8.10/24 ipv4.gateway 172.24.8.254 ipv4.dns 172.24.8.254 ipv4.dns-search group8.example.com ipv4.method manual connection.autoconnect yes connection.interface-name eth0
[root@localhost ~]# 
[root@localhost ~]# nmcli connection reload   ---重新加载连接配置信息
[root@localhost ~]# 
[root@localhost ~]# nmcli connection down  eth0  ---停掉网卡
Connection 'eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
[root@localhost ~]# nmcli connection up  eth0  ---并再次启动
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
[root@localhost ~]# ping server   ---ping 网关来测试是否配置成功
PING server.group8.example.com (172.24.8.254) 56(84) bytes of data.
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=1 ttl=64 time=0.464 ms

修改机器名
使用bash,让终端马上看见修改后的机器名

[root@localhost ~]# hostnamectl set-hostname desktop.group8.example.com
[root@localhost ~]# bash
[root@desktop ~]#

第二题:配置SeLinux

请按照下列要求设定系统
  •  SeLinux的工作模式为enforcing
  •  要求重启系统后仍旧生效

参考答案:

[root@desktop ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing  ------修改成enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

第三题:配置YUM软件仓库

为您的系统配置一个默认的软件仓库
  •  仓库地址为http://server.group8.example.com/yum

参考答案:

直接复制题目中的地址,使用yum命令配置

[root@desktop ~]# yum-config-manager --add-repo="http://server.group8.example.com/yum"
Loaded plugins: langpacks, product-id
adding repo from: http://server.group8.example.com/yum

[server.group8.example.com_yum]
name=added from: http://server.group8.example.com/yum
baseurl=http://server.group8.example.com/yum
enabled=1

如果配置出错,可以手工删除/etc/yum.repos.d/*.repo之后重新进行配置

安装验证KEY,避免因为外部源因为效验而安装中断

[root@desktop ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@desktop ~]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
server.group8.example.com_yum                                                          | 2.9 kB  00:00:00     
server.group8.example.com_yum/primary_db                                               | 103 kB  00:00:00     
repo id                                   repo name                                                     status
server.group8.example.com_yum             added from: http://server.group8.example.com/yum              119
repolist: 119

第四题:调整逻辑卷容量

请按照以下要求调整本地逻辑卷lv0的容量
  •  调整后的逻辑卷及文件系统的容量为290MiB
  •  调整后的文件系统中已存在的内容不能被破坏
  •  调整后允许出现误差,270MiB-320MiB之间都是允许的
  •  调整后保证其挂载目录不变

参考答案:

1、首先查看逻辑卷挂载位置

[root@desktop /]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/sda1           xfs       9.8G  3.3G  6.5G  34% /
devtmpfs            devtmpfs  660M     0  660M   0% /dev
tmpfs               tmpfs     674M     0  674M   0% /dev/shm
tmpfs               tmpfs     674M  8.9M  666M   2% /run
tmpfs               tmpfs     674M     0  674M   0% /sys/fs/cgroup
tmpfs               tmpfs     135M     0  135M   0% /run/user/0
/dev/mapper/vg0-lv0 ext3      180M  1.6M  169M   1% /home

使用lvextend命令进行扩容

[root@desktop /]# lvextend -L 290M /dev/vg0/lv0 
  Rounding size to boundary between physical extents: 292.00 MiB
  Size of logical volume vg0/lv0 changed from 192.00 MiB (48 extents) to 292.00 MiB (73 extents).
  Logical volume lv0 successfully resized.
[root@desktop /]# lvs
  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0  vg0  -wi-a----- 292.00m        

此时已经扩容成功,使用resize2fs命令刷新一下容量
注意:如果文件系统为xfs,那么就需要使用xfs_growfs /dev/vg0/lv0命令刷新

[root@desktop /]# resize2fs /dev/vg0/lv0 
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vg0/lv0' first.
如果多次出现上述问题,直接加-f参数强制刷新
[root@desktop /]# resize2fs -f  /dev/vg0/lv0 
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg0/lv0 to 299008 (1k) blocks.
The filesystem on /dev/vg0/lv0 is now 299008 blocks long.

/home 下的文件还在

[root@desktop /]# ls /home/
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  lost+found

4.2 如果当前容量比题目要求还大,那么需要进行裁剪

裁剪磁盘必须先进行卸载

[root@desktop /]# umount /home/

裁剪容量必须检测文件系统,以免把文件系统错误的扩大

[root@desktop /]# e2fsck -f /dev/vg0/lv0
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg0/lv0: 21/75776 files (0.0% non-contiguous), 15741/299008 blocks

使用resize2fs 来刷新系统容量文件信息,这个与扩容相反,如果顺序错误就会坏。
如果已经检测过文件系统还是提示Please run 'e2fsck -f /dev/vg0/lv0' first.,直接使用resize2fs加-f参数强制刷新

[root@desktop /]# resize2fs /dev/vg0/lv0 150M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg0/lv0 to 153600 (1k) blocks.
The filesystem on /dev/vg0/lv0 is now 153600 blocks long.

使用lvreduce命令进行裁剪容量,输入y确认

[root@desktop /]# lvreduce -L 150M /dev/vg0/lv0 
  Rounding size to boundary between physical extents: 152.00 MiB
  WARNING: Reducing active logical volume to 152.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv0? [y/n]: y
  Size of logical volume vg0/lv0 changed from 292.00 MiB (73 extents) to 152.00 MiB (38 extents).
  Logical volume lv0 successfully resized.
[root@desktop /]# mount /dev/vg0/lv0 /home/
[root@desktop /]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda1            9.8G  3.3G  6.5G  34% /
devtmpfs             660M     0  660M   0% /dev
tmpfs                674M     0  674M   0% /dev/shm
tmpfs                674M  8.9M  666M   2% /run
tmpfs                674M     0  674M   0% /sys/fs/cgroup
tmpfs                135M     0  135M   0% /run/user/0
/dev/mapper/vg0-lv0  142M  1.6M  133M   2% /home

第五题:创建用户和用户组

请按照以下要求创建用户、用户组
  •  新建一个名为adminuser的用户组,组id为40000
  •  新建一个名为natasha的用户,并将adminuser作为其附属组
  •  新建一个名为harry的用户,并将adminuser作为其附属组
  •  新建一个名为sarah的用户,其不属于adminuser组,且在系统同没有任何可交互的shell
  •  natasha、harry、sarah的用户密码均为redhat

参考答案:
使用如下命令创建

[root@desktop /]# groupadd -g 40000 adminuser
[root@desktop /]# useradd -G adminuser natasha
[root@desktop /]# useradd -G adminuser harry
[root@desktop /]# useradd -s /sbin/nologin sarah
[root@desktop /]# echo redhat| passwd --stdin natasha
[root@desktop /]# echo redhat| passwd --stdin harry
[root@desktop /]# echo redhat| passwd --stdin sarah
Changing password for user sarah.
passwd: all authentication tokens updated successfully.
[root@desktop /]# su natasha
[natasha@desktop /]$ su harry
Password: 
[harry@desktop /]$ su natasha
Password: 
[natasha@desktop /]$ su sarah
Password: 
This account is currently not available.
[natasha@desktop /]$

如果创建过程中出现问题,删掉用户的所有信息重新创建

[root@desktop /]# userdel -h
Usage: userdel [options] LOGIN

Options:
  -f, --force                   force some actions that would fail otherwise
                                e.g. removal of user still logged in
                                or files, even if not owned by the user
  -h, --help                    display this help message and exit
  -r, --remove                  remove home directory and mail spool
  -R, --root CHROOT_DIR         directory to chroot into
  -Z, --selinux-user            remove any SELinux user mapping for the user
 
[root@desktop /]# userdel -rfRZ [username]

第六题:配置文件/var/tmp/fstab的权限

复制文件/etc/fstab到/var/tmp/fstab,然后请按照以下要求配置文件权限
  •  该文件所属人为root
  •  该文件所属组为root
  •  该文件对任何人没有执行权限
  •  用户natasha对文件可读可写
  •  用户harry对文件不能读也不能写
  •  所有其他用户(包括已有和未来创建用户),对文件有读的权限

参考答案:

[root@desktop /]# cp /etc/fstab /var/tmp/fstab
[root@desktop /]# cd /var/tmp/
[root@desktop tmp]# ll
-rw-r--r--. 1 root root 451 Dec 11 16:56 fstab

更改文件所属人和所属组

[root@desktop tmp]# chown root:root fstab 

任何人都没有执行权限

[root@desktop tmp]# chmod a-x fstab 

对两个用户分别设定不同的权限,并使用getfacl查看

[root@desktop tmp]# setfacl -m u:natasha:rw-,u:harry:--- /var/tmp/fstab 
[root@desktop tmp]# getfacl /var/tmp/fstab 
getfacl: Removing leading '/' from absolute path names
# file: var/tmp/fstab
# owner: root
# group: root
user::rw-
user:natasha:rw-
user:harry:---
group::r--
mask::rw-
other::r--

第七题:建立计划任务

对用户natasha建立计划任务,要求每天14:23执行以下命令
  •  /bin/echo "rhcsa"

参考答案:

[root@desktop tmp]# crontab -e -u natasha

23 14 * * * /bin/echo "rhcsa"
分 时 日 月 周 

第八题:创建共享目录

在/home下创建名为admins的子目录,并按照以下要求设置权限
  •  /home/admins 所属的组为adminuser
  •  该目录对adminuser组的成员可读可写,其他人没有任何权限,但是root不受限制
  •  在/home/admins下创建的文件组属性自动被更改为adminuser

参考答案:

[root@desktop ~]# mkdir /home/admins

修改所属组

[root@desktop ~]# chgrp adminuser /home/admins/

修改权限

[root@desktop ~]# chmod g=rw-,o=--- /home/admins/

设定特权位,实现创建文件组属性自动更改为adminuser

[root@desktop ~]# chmod g+s /home/admins/

查看权限

[root@desktop ~]# ll -d /home/admins/
drwxrwS---. 2 root adminuser 1024 Dec 11 17:06 /home/admins/

进入目录创建文件测试

[root@desktop ~]# cd /home/admins/
[root@desktop admins]# touch file
[root@desktop admins]# mkdir dir
[root@desktop admins]# ll
total 3
drwxr-sr-x. 2 root adminuser 1024 Dec 11 17:08 dir
-rw-r--r--. 1 root adminuser    0 Dec 11 17:08 file
[root@desktop admins]#

第九题:升级系统内核

 http://server.group8.example.com/pub/ 找到需要升级的内核并满足下列需求
  •  当系统重启之后,升级的内核作为默认的内核
  •  原来的内核要被保留,并且仍然可以正常启动

参考答案:

使用curl访问该地址,并过滤出kernel相关的内容

[root@desktop ~]# curl --silent http://server.group8.example.com/pub/ | grep kernel
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]"></td><td><a href="kernel-3.10.0-327.4.5.el7.x86_64.rpm">kernel-3.10.0-327.4...&gt;</a></td><td align="right">2016-12-30 16:48  </td><td align="right"> 33M</td><td>&nbsp;</td></tr>

kernel-3.10.0-327.4.5.el7.x86_64.rpm 记住这个包名,使用yum安装

[root@desktop ~]# yum install http://server.group8.example.com/pub/kernel-3.10.0-327.4.5.el7.x86_64.rpm 
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
kernel-3.10.0-327.4.5.el7.x86_64.rpm                                                   |  33 MB  00:00:00     
Examining /var/tmp/yum-root-Ioaoyk/kernel-3.10.0-327.4.5.el7.x86_64.rpm: kernel-3.10.0-327.4.5.el7.x86_64
Marking /var/tmp/yum-root-Ioaoyk/kernel-3.10.0-327.4.5.el7.x86_64.rpm as an update to kernel-3.10.0-123.el7.x86_64
Marking /var/tmp/yum-root-Ioaoyk/kernel-3.10.0-327.4.5.el7.x86_64.rpm as an update to kernel-3.10.0-327.el7.x86_64
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-327.4.5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================
 Package         Arch            Version                     Repository                                  Size
==============================================================================================================
Installing:
 kernel          x86_64          3.10.0-327.4.5.el7          /kernel-3.10.0-327.4.5.el7.x86_64          136 M

Transaction Summary
==============================================================================================================
Install  1 Package

Total size: 136 M
Installed size: 136 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : kernel-3.10.0-327.4.5.el7.x86_64                                                           1/1

最后验证一下,没必要为了这个题重启

[root@desktop ~]# grub2-editenv list
saved_entry=Red Hat Enterprise Linux Server (3.10.0-327.4.5.el7.x86_64) 7.2 (Maipo)

第十题:绑定外部验证服务

系统server.group8.example.com提供了一个ldap验证服务。你的系统需要按照一下要求绑定到这个服务上
  •  验证服务器的基本DN是:dc=group8,dc=example,dc=com
  •  账户信息和验证信息都是由LDAP提供
  •  连接需要使用证书加密,证书在下面的连接中下载 http://server.group8.example.com/pub/cacert.pem
  •  当正确完成配置后,用户thales可以登录系统,登录密码是redhat

参考答案:

安装authconfig-tui 和ssd服务

[root@desktop ~]# yum install authconfig-tui sssd -y

创建一个证书存放路径,并下载证书到该路径

[root@desktop ~]# mkdir /etc/openldap/cacerts
[root@desktop ~]# wget -O /etc/openldap/cacerts/ca.pem http://server.group8.example.com/pub/cacert.pem
--2018-12-11 18:33:02--  http://server.group8.example.com/pub/cacert.pem
Resolving server.group8.example.com (server.group8.example.com)... 172.24.8.254
Connecting to server.group8.example.com (server.group8.example.com)|172.24.8.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1350 (1.3K)
Saving to: ‘/etc/openldap/cacerts/ca.pem’

100%[====================================================================>] 1,350       --.-K/s   in 0s      

2018-12-11 18:33:02 (112 MB/s) - ‘/etc/openldap/cacerts/ca.pem’ saved [1350/1350]

执行authconfig-tui

[root@desktop ~]# authconfig-tui 

image
image

[root@desktop ~]# getent passwd thales
thales:*:2001:2001:thales:/home/ldap/thales:/bin/bash

排错,如果getent无法获得用户thales的信息,应该是sssd服务没有启动

[root@desktop ~]# systemctl restart sssd
[root@desktop ~]# systemctl status sssd
● sssd.service - System Security Services Daemon
   Loaded: loaded (/usr/lib/systemd/system/sssd.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/sssd.service.d
           └─journal.conf
   Active: active (running) since Tue 2018-12-11 18:36:44 CST; 4min 40s ago

保证服务状态为active就可以正常使用,并且保证服务开机自启动

[root@desktop ~]# systemctl is-enabled sssd
disabled
[root@desktop ~]# systemctl enable sssd
Created symlink from /etc/systemd/system/multi-user.target.wants/sssd.service to /usr/lib/systemd/system/sssd.service.

第十一题:配置autofs

按照下述要求配置autofs,用来挂载LDAP用户主目录
  •  server.group8.example.comNFS输出了/rhome目录到您的系统,这个文件系统包含了用户thales的主目录,并且已经预先配置好了
  •  thales用户的主目录是 server.group8.example.com:/rhome/thales
  •  thales用户的主目录应该挂载到本地的/home/ldap/thales
  •  用户对其主目录必须是读写的
  •  thales的登录密码是redhat
  •  使用nfs3版本进行挂载 <----这个是最新考试新加的选项,如果有这个就在auto.lpad中加上vers=3

参考答案:

安装autofs
并配置auto.master文件,当系统访问以/home/ldap路径开头的资源是,读取/etc/autp.ldap配置文件进行自动挂载

[root@desktop ~]# yum install autofs
[root@desktop ~]# vim /etc/auto.master

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc   /etc/auto.misc
/home/ldap      /etc/auto.ldap
注意-rw前边的"-"符号,还有最后的"/&" 配置含义:当访问/home/ldap/*(*代表任意路径)的资源时,自动挂载server.group8.example.com:/rhome/对应路径的资源 下边文件的* 等于auto.master中的/home/ldap/* 因为*被这里解释为了注释符号,所以我使用代码框来引住这段话 * -rw,sync,soft,vers=3 server.group8.example.com:/rhome/& 加了vers=3,使用3版本进行挂载 
[root@desktop ~]# vim /etc/auto.ldap
* -rw,sync,soft server.group8.example.com:/rhome/&
另一种写法
*    -fstype=nfs,sync,soft,vers=3    server.group8.example.com:/rhome/&

重启autofs服务,并设置开机自启动,满足题目所说重启生效

[root@desktop ~]# systemctl restart autofs
[root@desktop ~]# systemctl enable autofs
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.

登录验证,pwd路径为thales用户的主目录

[root@desktop ~]# ssh thales@localhost
thales@localhost's password: 
pwLast login: Wed Dec 12 11:23:14 2018 from localhost
[thales@desktop ~]$ pwd
/home/ldap/thales
[thales@desktop ~]$ logout
Connection to localhost closed

第十二题:配置NTP

配置您的系统时间与server.group8.example.com时间同步,并且要求重启生效

参考答案:

把原来的server注释掉,将题目要求的地址添加进去

[root@desktop ~]# vim /etc/chrony.conf 

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst

server server.group8.example.com iburst

重启服务,并设置服务重启生效

[root@desktop ~]# systemctl restart  chronyd
[root@desktop ~]# systemctl enable chronyd

验证,当输入waitsync,看到类似于如下的回复,则表示成功

[root@desktop ~]# chronyc 
chrony version 2.1.1
Copyright (C) 1997-2003, 2007, 2009-2015 Richard P. Curnow and others
chrony comes with ABSOLUTELY NO WARRANTY.  This is free software, and
you are welcome to redistribute it under certain conditions.  See the
GNU General Public License version 2 for details.

chronyc> waitsync
try: 1, refid: 172.24.8.254, correction: 0.000000366, skew: 74.664
chronyc> exit
[root@desktop ~]#

第十三题:创建一个归档

创建一个名为/root/sysconfig.tar.bz2的归档文件,其中包含了/etc/sysconfig目录中的内容。tar归档文件必须使用bzip2进行压缩。

参考答案:

[root@desktop ~]# tar -jcf sysconfig.tar.bz2 /etc/sysconfig

如果报错信息如下,请安装bzip2

tar (child): bzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting n

yum install bzip2

参数解析:
-j 使用bzip2压缩归档文件
-v 显示所有过程
如果要求使用gzip压缩,那么应该使用参数-z,也就是-zcf

第十四题:配置一个用户账号

请创建一个名为jay的用户,并满足以下要求:
  •  用户id为3456
  •  密码为glegunge

参考答案:

[root@desktop ~]# useradd --help
Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]
-u, --uid UID                 user ID of the new account
  
[root@desktop ~]# useradd -u 3456 jay
[root@desktop ~]# echo glegunge | passwd --stdin jay
Changing password for user jay.
passwd: all authentication tokens updated successfully.
[root@desktop ~]# id jay
uid=3456(jay) gid=3456(jay) groups=3456(jay)
[root@desktop ~]#

第十五题:添加一个swap分区

在您的系统中添加一个新的swap分区,并满足以下要求:
  •  swap分区容量为512MiB
  •  当您的系统启动时,swap分区应该可以自动挂载
  •  不要移除或者修改其他已存在你的系统中的swap分区

参考答案:

[root@desktop ~]# fdisk /dev/sda     <---考试使用的是kvm所以是/dev/vda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n     
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e   <---因为后边还有一个题目需要分区,所以先把所有剩余的空间划分为扩展分区
Selected partition 4
First sector (25602048-41943039, default 25602048): 
Using default value 25602048
Last sector, +sectors or +size{K,M,G} (25602048-41943039, default 41943039): 
Using default value 41943039
Partition 4 of type Extended and of size 7.8 GiB is set   <---一路回车下来,可以看到把所有的空间都划分为了扩展分区
Command (m for help): n  <----在刚刚创建的扩展分区上划分新的逻辑分区
All primary partitions are in use
Adding logical partition 5  <----新的分区默认编号是5
First sector (25604096-41943039, default 25604096):   <---默认使用起始柱面
Using default value 25604096
Last sector, +sectors or +size{K,M,G} (25604096-41943039, default 41943039): +512M   <----通过手动输入来确定新的分区大小
Partition 5 of type Linux and of size 512 MiB is set

Command (m for help): t  <----设置分区类型
Partition number (1-5, default 5): 
Hex code (type L to list all codes): 82    <----82为swap类型,如果忘了,可以输入L查看
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): p    <---查看分区结果

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bffad

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    20482047    10240000   83  Linux
/dev/sda2        20482048    24578047     2048000   82  Linux swap / Solaris
/dev/sda3        24578048    25602047      512000   83  Linux
/dev/sda4        25602048    41943039     8170496    5  Extended  <----这是新的扩展分区
/dev/sda5        25604096    26652671      524288   82  Linux swap / Solaris    <----这是新的swap分区

Command (m for help): w    <----保存
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

分区划分完成之后,格式化,配置自动挂载

[root@desktop ~]# partprobe      <----重读分区
[root@desktop ~]# ls -l /dev/sda5    <---- 如果生成设备文件失败,可以使用partx -a /deb/sda再次生成,还是失败就重启系统
brw-rw----. 1 root disk 8, 5 Dec 12 11:58 /dev/sda5
[root@desktop ~]# mkswap /dev/sda5    <----格式这个分区
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=39ae6db2-f221-4f7f-8f91-70bcdf552399   <----复制这个uuid,用于配置自动挂载
[root@desktop ~]# swapon /dev/sda5    <----马上启用该分区
[root@desktop ~]# swapon -s    <----可以卡件新的分区
Filename                Type        Size    Used    Priority
/dev/sda2                                  partition    2047996    0    -1
/dev/sda5                                  partition    524284    0    -2
[root@desktop ~]# 

将刚才的uuid,写入fstab中配置自动挂载

[root@desktop ~]# vim /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Mon Jul 18 19:38:41 2016
#
# 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=3c6e20fa-3e12-42ca-8dba-b12eee74e43e /                       xfs     defaults        1 1
UUID=ff7d2e6d-c2d7-46a0-af09-70c85898ab46 swap                    swap    defaults        0 0
/dev/mapper/vg0-lv0 /home ext3 defaults 0 0
UUID=39ae6db2-f221-4f7f-8f91-70bcdf552399 swap  swap defaults 0 0 

第十六题:查找文件

请把系统上拥有者为jay用户的所有文件找到,并拷贝到/root/findfiles目录中

参考答案:

[root@desktop ~]# mkdir /root/findfiles
[root@desktop ~]# find / -user jay -exec cp -a {} /root/findfiles/ \;
find: ‘/proc/28299/task/28299/fd/6’: No such file or directory
find: ‘/proc/28299/task/28299/fdinfo/6’: No such file or directory
find: ‘/proc/28299/fd/6’: No such file or directory
find: ‘/proc/28299/fdinfo/6’: No such file or directory
cp: cannot overwrite non-directory ‘/root/findfiles/jay’ with directory ‘/home/jay’
[root@desktop ~]# ls -a /root/findfiles/
.  ..  .bash_logout  .bash_profile  .bashrc  extensions  jay  .mozilla  plugins
[root@desktop ~]#

第十七题:查找字符串

把/usr/share/dict/words文件中所有包含seismic字符串的行找到,并将这些行按照原始文件中的顺序存放到/root/wordlist中,/root/wordlist文件不能包含空行

参考答案:

[root@desktop ~]# grep seismic /usr/share/dict/words | grep -v ^$ > /root/wordlist

grep -v ^$ 排除以开头为结尾的行,也就是空行

其他答案

[root@desktop ~]# awk '($0~/seismic/){print $0}' /usr/share/dict/words

第十八题:创建一个逻辑卷

请按照下列要求创建一个新的逻辑卷:
  •  创建一个名为datastore的卷组,卷组的PE尺寸为16MiB
  •  逻辑卷的名字为database,所属卷组为datastore,该逻辑卷由50个PE组成
  •  将新建的逻辑卷格式化为xfs文件系统,要求重新启动系统是,该逻辑卷能被自动挂载到/mnt/database目录

参考答案:

首先创建分区

[root@desktop ~]# fdisk /dev/sda 
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n   <----新建分区
All primary partitions are in use
Adding logical partition 6
First sector (26654720-41943039, default 26654720): 
Using default value 26654720
Last sector, +sectors or +size{K,M,G} (26654720-41943039, default 41943039):      <----使用全部的空间
Using default value 41943039
Partition 6 of type Linux and of size 7.3 GiB is set

Command (m for help): t     <----修改分区类型标记
Partition number (1-6, default 6):    <----直接回车,修改刚刚划分的分区
Hex code (type L to list all codes): 8e   <---8e代表linux LVM 类型
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w    <---保存分区设定
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

创建完成,使用partprobe重新加载分区

[root@desktop ~]# partprobe 

创建物理卷,使用刚刚划分的/dev/sda6

[root@desktop ~]# pvcreate /dev/sda6
  Physical volume "/dev/sda6" successfully created
[root@desktop ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree  
  /dev/sda3  vg0  lvm2 a--  496.00m 204.00m
  /dev/sda6       lvm2 ---    7.29g   7.29g

创建名字为datastore的卷组,并设置PE的尺寸为16M

[root@desktop ~]# vgcreate -s 16M datastore  /dev/sda6 
  Volume group "datastore" successfully created
[root@desktop ~]# vgs
  VG        #PV #LV #SN Attr   VSize   VFree  
  datastore   1   0   0 wz--n-   7.28g   7.28g
  vg0         1   1   0 wz--n- 496.00m 204.00m

创建逻辑卷,默认使用50个PE

[root@desktop ~]# lvcreate -n database -l 50 datastore
  Logical volume "database" created.
[root@desktop ~]# lvs
  LV       VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  database datastore -wi-a----- 800.00m                                                    
  lv0      vg0       -wi-ao---- 292.00m   

格式化刚刚创建的逻辑卷

[root@desktop ~]# mkfs.xfs /dev/datastore/database 
meta-data=/dev/datastore/database isize=256    agcount=4, agsize=51200 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=204800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

挂载

[root@desktop ~]# mkdir /mnt/database
[root@desktop ~]# blkid /dev/datastore/database
/dev/datastore/database: UUID="4a9c4cff-0690-4382-a9f5-c318d8c2143f" TYPE="xfs" 

将UUID写入fstab文件中,确保开机挂载
然后使用mount -a命令,查看是否配置正确

[root@desktop ~]# vim /etc/fstab 


#
# /etc/fstab
# Created by anaconda on Mon Jul 18 19:38:41 2016
#
# 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=3c6e20fa-3e12-42ca-8dba-b12eee74e43e /                       xfs     defaults        1 1
UUID=ff7d2e6d-c2d7-46a0-af09-70c85898ab46 swap                    swap    defaults        0 0
/dev/mapper/vg0-lv0 /home ext3 defaults 0 0
UUID=39ae6db2-f221-4f7f-8f91-70bcdf552399 swap  swap defaults 0 0 
UUID=4a9c4cff-0690-4382-a9f5-c318d8c2143f /mnt/database xfs defaults 0 0
[root@desktop ~]# mount -a 

查看挂载是否成功

[root@desktop ~]# df -hT
Filesystem                     Type      Size  Used Avail Use% Mounted on
/dev/sda1                      xfs       9.8G  3.6G  6.3G  37% /
devtmpfs                       devtmpfs  660M     0  660M   0% /dev
tmpfs                          tmpfs     674M     0  674M   0% /dev/shm
tmpfs                          tmpfs     674M  8.9M  666M   2% /run
tmpfs                          tmpfs     674M     0  674M   0% /sys/fs/cgroup
tmpfs                          tmpfs     135M     0  135M   0% /run/user/0
/dev/mapper/vg0-lv0            ext3      279M  2.1M  264M   1% /home
/dev/mapper/datastore-database xfs       797M   33M  765M   5% /mnt/database

至此,所有题目全部做完,必须重启虚拟机,确保所有操作重启机器后可正常使用

使用grade命令查看是否全部通过

[root@desktop ~]# grade 
Input password: qq5156770 
###### Grading the No.1 question ######
Checking root password...      PASS************* 
Checking your hostname...      PASS************* 

###### Grading the No.2 question ######
Check Set Selinux     PASS************* 

###### Grading the No.3 question ######
Check yum repo config     PASS************* 
Check yum repo enabled     PASS************* 

###### Grading the No.4 question ######
Checking size of lv0 LV...     PASS************* 
Checking size of lv0 filesystem...     PASS************* 

###### Grading the No.5 question ######
Check Group adminuser create     PASS************* 
Check User natasha create     PASS************* 
Check User harry create     PASS************* 
Check User sarah create     PASS************* 
Check natasha's Password     PASS************* 
Check harry's Password     PASS************* 
Check sarah's Password     PASS************* 

###### Grading the No.6 question ######
Check Set file or directory     PASS************* 

###### Grading the No.7 question ######
Check crontab service     PASS************* 
Check Set user crontab     PASS************* 

###### Grading the No.8 question ######
Check Set directory gid     PASS************* 

###### Grading the No.9 question ######
Check Install new Kernel     PASS************* 

###### Grading the No.10 question ######
Check Use LDAP and Kerberos     PASS************* 

###### Grading the No.11 question ######
Check AUTOFS     PASS************* 

###### Grading the No.12 question ######
Check Time sync server set     PASS************* 

###### Grading the No.13 question ######
Check sysconfig tar     PASS************* 

###### Grading the No.14 question ######
Check user jay create     PASS************* 
Check user jay password     PASS************* 

###### Grading the No.15 question ######
Check swap partision     PASS************* 
Check Swap partision id     PASS************* 
Check swap persitent mount in fstab     PASS************* 

###### Grading the No.16 question ######
Check jay file     PASS************* 

###### Grading the No.17 question ######
Check grep result file     PASS************* 

###### Grading the No.18 question ######
Check create LVM VG datastore    PASS************* 
Check create LVM VG size    PASS************* 
Check create LVM VG PE size    PASS************* 
Check create LVM LV database    PASS************* 
Check create LVM LV size    PASS************* 
Check mount file system    PASS*************

猜你喜欢

转载自www.cnblogs.com/despotic/p/10790310.html