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*************


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM