RHCSA試題+答案(2017-10-28)

RHCSA_pdf下載: 下載地址
考試環境:考試過程中所有的操作是在kvm虛擬機中進行,虛擬機root密碼需要破解,重設爲題目指定的密碼。

上午:時間2.5H
把root密碼設置爲要求的:
grub啓動菜單選e編輯,找見默認kernel(linux16,在行末添加rd.break,b引導。(虛擬機需要刪到ro,ro保留。 虛擬機中小鍵盤不能用的可能性比較大,特別是用passwd指定root密碼的時候不易察覺,易導致root破解失敗,所以虛擬機下不用小鍵盤。)

mount -o rw,remount /sysroot
chroot  /sysroot 
passwd root  (或者 echo 123456 |passwd --stdin root)
touch /.autorelabel   (注意/之後.  最後是bel)
reboot

重啓之後虛擬機可能默認命令行界面,如果需要切換到圖形界面,root登錄,執行以下命令:

[root@server ~]# systemctl isolate graphical.target   (暫時圖形化界面,重啓之後還是命令行)

(不建議*)如果嫌每次重啓切換麻煩,可以改變默認界面,執行以下命令:

[root@server ~]# systemctl get-default 
multi-user.target
[root@server ~]# systemctl set-default graphical.target

但是切記*最後要改回命令行界面,即:

[root@server ~]# systemctl set-default multi-user.target 

按要求配置虛擬機:(注意在虛擬機中配置)

  • Hostname: serverX.example.com
  • IP address: 172.25.X.11 (static)
  • Netmask: 255.255.255.0
  • Gateway: 172.25.X.254
  • Name server: 172.25.X.254

命令:
配置主機名:

[root@server ~]# hostnamectl set-hostname serverX.example.com

或者

[root@server ~]# vim /etc/hostname (默認沒有此文件,手動編寫)

配置網絡:

[root@server ~]# nmcli con show --active
[root@server ~]# nmcli con mod "System eth0" ipv4.method manual ipv4.addresses "172.25.X.11/24 172.25.X.254" ipv4.dns 172.25.X.254

檢驗

[root@server ~]# cat /etc/hostname
[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

重啓服務,重啓虛擬機檢驗

[root@server ~]# systemctl restart NetworkManager
[root@server ~]# reboot

檢驗網絡沒問題之後開始正式答題,推薦從實機ssh -X到server虛擬機,方便複製粘貼

正式答題

1.selinux開啓爲enforcing

[root@server16 ~]# setenforce 1
[root@server16 ~]# vim /etc/selinux/config
SELINUX=enforcing

2. YUM 的軟件庫源爲 http://172.25.254.254/content/rhel7.0/x86_64/dvd. 將此配置爲您的系統的默認軟件倉庫。

[root@server16 ~]# cd /etc/yum.repos.d/
[root@server16 yum.repos.d]# vim server.repo
              [base]
              name=server
              baseurl=http://172.25.254.254/content/rhel7.0/x86_64/dvd
              enabled=1
              gpgcheck=0
[root@server16 ~]# yum clean all
[root@server16 yum.repos.d]# yum makecache 
或者 [root@server16 yum.repos.d]# yum repolist

3. 將邏輯卷vol和其文件系統大小調整到 380 MiB。要確保文件系統中的內容保持完整。請注意:分區大小很少能夠完全符合要求的大小,所以大小在 350 MiB 和 410 MiB 之間都是可以接受的。
準備分區:(順便準備14,18題所需分區)

[root@server16 ~]# fdisk /dev/vdb
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    20971519    10484736    5  Extended
/dev/vdb5            4096     1028095      512000   83  Linux
/dev/vdb6         1030144     2578431      774144   83  Linux
/dev/vdb7         2580480     3645439      532480   83  Linux
三個邏輯分區大小分別爲500M,765M,520M,fdisk完成之後記得w保存退出。
[root@server16 ~]# partprobe /dev/vdb 
[root@server16 ~]# pvcreate /dev/vdb5
  Physical volume "/dev/vdb5" successfully created
[root@server16 ~]# vgcreate vg0 /dev/vdb5
  Volume group "vg0" successfully created
[root@server16 ~]# lvcreate -L 200M -n vol vg0 
  Logical volume "vol" created


[root@server ~]# lvdisplay   (查看vol路徑path)
[root@server ~]# lvresize -r -L 380M /dev/vg0/vol   (切記-r,文件系統)

邏輯卷ext4在線放大,離線縮小,xfs只能放大,不能縮小。

4. 按照以下要求創建用戶,組,及用戶與組的關係
新建一個名爲sharegrp的組
新建一個名爲natasha的用戶,並將sharegrp作爲其附屬組
新建一個名爲harry的用戶,也將sharegrp作爲其附屬組
新建一個名爲sarah的用戶,其不屬於sharegrp組,並將其shell設置爲不可登錄shell
natasha、harry、sarah用戶的密碼均設置爲emesgravy

[root@server16 ~]# groupadd sharegrp 
[root@server16 ~]# useradd -G sharegrp natasha
[root@server16 ~]# useradd -G sharegrp harry
[root@server16 ~]# useradd -s /sbin/nologin sarah
[root@server16 ~]# echo emesgravy |passwd --stdin sarah
[root@server16 ~]# echo emesgravy |passwd --stdin harry
[root@server16 ~]# echo emesgravy |passwd --stdin natasha
測試:
[root@server16 ~]# id natasha
[root@server16 ~]# id harry
[root@server16 ~]# id sarah
[root@server16 ~]# grep sarah /etc/passwd

5.複製文件/etc/fstab 到 /var/tmp目錄中,並按以下要求配置/var/tmp/fstab文件的權限:
文件/var/tmp/fstab的所屬人爲root
文件/var/tmp/fstab的所屬組爲root
文件/var/tmp/fstab對任何人均沒有執行權限
用戶natasha對文件/var/tmp/fstab有讀和寫的權限
用戶harry對文件/var/tmp/fstab既不能讀也不能寫
所有其他用戶(包換當前用戶及未來創建的用戶)對文件/var/tmp/fstab都有讀的權限

[root@server16 ~]# cd /var/tmp/
[root@server16 tmp]# cp /etc/fstab .
[root@server16 tmp]# ll fstab
[root@server16 tmp]# setfacl -m u:natasha:rw fstab 
[root@server16 tmp]# setfacl -m u:harry:- fstab
檢查:
[root@server16 tmp]# ll fstab
[root@server16 tmp]# getfacl fstab

PS: ① acl權限(rwx)給錯怎麼辦?再次setfacl -m 覆蓋即可。例如:

[root@server16 tmp]# setfacl -m u:natasha:rwx fstab
[root@server16 tmp]# setfacl -m u:natasha:rw fstab

②acl權限用戶指定錯誤怎麼辦?先刪除,再添加。例如:

[root@server16 tmp]# setfacl -m u:sarah:rw fstab 
[root@server16 tmp]# setfacl -x u:sarah fstab
[root@server tmp]# setfacl -m u:natasha:rw fstab

記不得-x怎麼辦?:) 刪掉fstab文件再來一次,簡單粗暴。

6.對natasha用戶配置計劃任務,要求在本地時間的每天14:23分執行以下命令:/bin/echo hiya

[root@server ~]# crontab -e -u natasha
23 14 * * * /bin/echo hiya

(分 時 日 月 星期)    星期日 = 0 or 7 
檢查:
[root@server ~]# crontab -l -u natasha

PS:由於bug,編輯保存退出時有可能自動複製出好多23 14 * * * /bin/echo hiya,所以一定要-l確保沒問題。

7.創建一個目錄/nfsshare:
* 其擁有者root,擁有組爲sharegrp,組擁有所有權限,其他人無任何權限。
* 用戶sarah對其擁有所有權限。
* 用戶在該目錄下創建的新文件的擁有組爲sharegrp。

[root@server16 ~]# mkdir /nfsshare
[root@server16 ~]# chgrp sharegrp /nfsshare
[root@server16 ~]# chmod g=rwx,o=- /nfsshare/     (*)
[root@server16 ~]# chmod g+s /nfsshare/          (*)
[root@server16 ~]# setfacl -m u:sarah:rwx /nfsshare
檢查:
[root@server16 ~]# ll -d /nfsshare
[root@server16 ~]# getfacl /nfsshare

PS:(*)標註的兩條不能用原答案上給的chmod g=rws,o=- /nfsshare 一條代替,因爲ll可以發現這樣做組權限爲rwS,即並沒有x執行權限,而用上面(*)標註的兩句執行完ll組權限必然是rws,即有x執行權限,符合題意要求。

8.按以下要求更新系統的內核,新內核的RPM包位於http://classroom.example.com/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm.
重新重啓時,會默認以新內核啓動系統。原始的內核將繼續可用。

[root@server16 ~]# wget http://172.25.254.254/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm
[root@server16 ~]# ls
[root@server16 ~]# rpm -ivh kernel-3.10.0-123.1.2.el7.x86_64.rpm
[root@server16 ~]# reboot
[root@server16 ~]# uname -r
3.10.0-123.1.2.el7.x86_64

9.在classroom.example.com 上已部署了一臺LDAP認證服務器,按以下要求配置你的系統以加入到該LDAP服務中:
該認證服務的Base DN爲: dc=example,dc=com
該LDAP 服務既提供的帳戶信息也同時提供認證信息
認證的會話連接需要被加密,證書的下載地址爲http://classroom.example.com/pub/EXAMPLE-CA-CERT.
當配置完成後,你可以使用ldapuserX登錄,但在你完成autofs配置之前,是無法獲取到家目錄的。
ldapuserX 的密碼爲password

[root@server16 ~]# yum -y install authconfig-gtk sssd krb5-workstation
[root@server16 ~]# authconfig-gtk 

rhcsa1.png
rhcsa2.png

[root@server16 ~]# su - ldapuser16
su: warning: cannot change directory to /home/guests/ldapuser16: No such file or directory
mkdir: cannot create directory '/home/guests': Permission denied
-bash-4.2$

10.配置你的系統以使其時間與服務器classroom.example.com 同步.

[root@server16 ~]# vim /etc/chrony.conf 
server classroom.example.com iburst
[root@server16 ~]# systemctl restart chronyd.service 
[root@server16 ~]# timedatectl 
      Local time: Sat 2017-10-28 10:27:35 CST
  Universal time: Sat 2017-10-28 02:27:35 UTC
        RTC time: Sat 2017-10-28 02:27:34
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@server16 ~]# timedatectl set-ntp true 
[root@server16 ~]# systemctl restart chronyd.service 
[root@server16 ~]# timedatectl 
      Local time: Sat 2017-10-28 10:30:18 CST
  Universal time: Sat 2017-10-28 02:30:18 UTC
        RTC time: Sat 2017-10-28 02:30:17
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
[root@server16 ~]# chronyc sources -v

11.配置autofs以當你使用ldapuserX登錄時自動掛載家目錄: /home/guests/ldapuserX(X爲你的座位號)
classroom.example.com (172.25.254.254) 已使用NFS-exports共享了/home/guests目錄。該共享目錄裏包括ldapuserX的家目錄。
ldapuserX的家目錄在classroom.example.com:/home/guests/ldapuserX
ldapuserX的家目錄將會在你訪問/home/guests/ldapuserX時被自動掛載本地的/home/guests/ldapuserX
ldapuserX要對其家目錄有完整權限。
ldapuserX 的密碼爲password

[root@server16 ~]# showmount -e classroom.example.com
Export list for classroom.example.com:
/home/guests 172.25.0.0/255.255.0.0
[root@server16 ~]# yum -y install autofs
[root@server16 ~]# vim /etc/auto.master
/home/guests    /etc/auto.ldap
[root@server16 ~]# vim /etc/auto.ldap
*  -intr,soft,rw,v3 172.25.254.254:/home/guests/&
[root@server16 ~]# systemctl restart autofs
[root@server16 ~]# systemctl enable autofs
[root@server16 ~]# su - ldapuser16
Last login: Sat Oct 28 10:38:45 CST 2017 on pts/0
[ldapuser16@server16 ~]

12.搭建一個Web Server,站點爲http://serverX.example.com , 然後按以下步驟配置:
下載http://172.25.254.254/content/rhce/web/station.html到你的web server的DocumentRoot 重命名爲index.html
不要修改index.html文件的內容

[root@server16 ~]# yum -y install httpd
[root@server16 ~]# cd /var/www/html/
[root@server16 html]# wget -O index.html http://172.25.254.254/content/rhce/web/station.html
[root@server16 html]# systemctl start httpd
[root@server16 html]# systemctl enable httpd.service
檢查:
[root@server16 html]# firefox http://server16.example.com

13.創建一個名爲alex的用戶,設置其用戶ID爲3456,密碼爲glegunge

[root@server16 ~]# useradd -u 3456 alex
[root@server16 ~]# echo glengunge |passwd --stdin alex
Changing password for user alex.
passwd: all authentication tokens updated successfully.
[root@server16 ~]# id alex
uid=3456(alex) gid=3456(alex) groups=3456(alex)

14.爲你的系統增加一個756MiB的SWAP分區,新的SWAP分區將會在重新啓動系統後自動被激活。不要刪除或修改已存在的SWAP分區。

[root@server16 ~]# mkswap /dev/vdb6
Setting up swapspace version 1, size = 774140 KiB
no label, UUID=975a0fa9-2147-48e4-bc9b-1dfd0a7833e8
[root@server16 ~]# blkid /dev/vdb6 
/dev/vdb6: UUID="975a0fa9-2147-48e4-bc9b-1dfd0a7833e8" TYPE="swap" 
[root@server16 ~]# blkid /dev/vdb6 >> /etc/fstab
[root@server16 ~]# vim /etc/fstab
UUID="975a0fa9-2147-48e4-bc9b-1dfd0a7833e8" swap   swap   defaults   0 0
[root@server16 ~]# swapon -a
[root@server16 ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/vdb6                               partition   774140  0   -1
[root@server16 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1841       1574        266         16          4       1044
-/+ buffers/cache:        525       1315
Swap:          755          0        755

15.找出用戶natasha擁有的所有的文件,並把它們複製到/root/findfiles/目錄中。

[root@server16 ~]# mkdir findfiles
[root@server16 ~]# find / -user natasha -exec cp -rp {} findfiles/ \;
find: ‘/proc/32344/task/32344/fd/6’: No such file or directory
find: ‘/proc/32344/task/32344/fdinfo/6’: No such file or directory
find: ‘/proc/32344/fd/6’: No such file or directory
find: ‘/proc/32344/fdinfo/6’: No such file or directory
cp: cannot overwrite non-directory ‘findfiles/natasha’ with directory ‘/home/natasha’
[root@server16 ~]# cd findfiles/
[root@server16 findfiles]# ll
total 8
drwxr-xr-x. 2 natasha natasha    6 Jan 27  2014 extensions
-rw-r--r--. 1 natasha natasha    4 Jul 11  2014 gnome-initial-setup-done
-rw-r--r--. 1 natasha natasha 1443 Jul 11  2014 monitors.xml
-rw-rw----. 1 natasha mail       0 Oct 28 11:20 natasha
drwxr-xr-x. 2 natasha natasha    6 Jan 27  2014 plugins

16.查找出/usr/share/dict/words文件當中所有包含seismic字符串的行,並將這些行仍然按照原始文件中的順序.
存放入/root/wordlist中,/root/wordlist文件不能包含空行。

[root@server16 ~]#  grep seismic /usr/share/dict/words  > wordlist
檢查:
[root@server16 ~]#  less wordlist

17.創建/root/backup.tar.bz2的歸檔文件,其中包括/usr/local的內容,必須使用bzip的壓縮。

[root@server16 ~]# tar -cjvf backup.tar.bz2 /usr/local/*
檢查:
[root@server16 ~]# tar -tjvf backup.tar.bz2

PS: man tar
-c, –create
-v, –verbose
-f, –file ( 選項最後一個)
-j, –bzip2
-J, –xz
-z, –gzip

18.按照以下要求創建一個新的邏輯卷:
邏輯卷的名字爲database,其屬於datastore卷組,該邏輯卷由30個PE組成。
卷組datastore的單個PE大小爲16MiB。
將新創建的邏輯卷格式化爲xfs文件系統,在系統啓動邏輯卷會被自動掛載到/mnt/database目錄下。

[root@server16 ~]# pvcreate /dev/vdb7
  Physical volume "/dev/vdb7" successfully created
[root@server16 ~]# vgcreate -s 16M datastore /dev/vdb7
  Volume group "datastore" successfully created
[root@server16 ~]# lvcreate -l 30 -n database datastore
  Logical volume "database" created
[root@server16 ~]# mkfs.xfs /dev/datastore/database 
[root@server16 ~]# blkid /dev/datastore/database
/dev/datastore/database: UUID="5e3db0a4-f9cc-4976-a8f8-26fd091bc811" TYPE="xfs" 
[root@server16 ~]# blkid /dev/datastore/database >> /etc/fstab
[root@server16 ~]# vim /etc/fstab
UUID="5e3db0a4-f9cc-4976-a8f8-26fd091bc811" /mnt/database  xfs defaults 0 0
[root@server16 ~]# mkdir /mnt/database
[root@server16 ~]# mount -a
[root@server16 ~]# df -h
/dev/mapper/datastore-database  477M   25M  453M   6% /mnt/database

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