二、RHCSA試題解析


一、設置YUM倉庫

YUM的軟件庫源地址為:http://content.example.com/rhel7.0/x86_64/dvd,將此配置為操作系統的默認軟件倉庫。

方法一(修改配置文件):

vim /etc/yum.repos.d/yum.repo

[base]
name=RHCSA
baseurl=http://content.example.com/rhel7.0/x86_64/dvd
enable=1
gpgcheck=0

  創建yum源需要主機配置文件必須存放在/etc/yum.repos.d下,並且以.repo結尾。

name:定義源名稱
baseurl:定義源地址
enable:定義是否啟用
gpgcheck:定義是否檢查軟件簽名,如果設置為1,需要設置:gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
baseurl:支持使用本地路徑、FTP、http三種資源格式:

baseurl=file:///
baseurl=ftp://
baseurl=http://

  本地路徑位置中第三個/表示本地根目錄,與上述gpgkey本地路徑格式一致。

方法二(使用命令行進行添加):

yum-config-manager -add http://content.example.com/rhel7.0/x86_64/dvd
  如果當前系統沒有yum-config-manager命令需要安裝yum-utils軟件包。

二、調整邏輯卷大小

將邏輯卷/dev/VolGroup/lv_home和其文件系統大小調整到15G,要確保文件系統中的內容保持完整。

查看當前邏輯卷大小

[root@serverX ~]# lvscan
  ACTIVE            '/dev/VolGroup/lv_swap' [<1.97 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_root' [50.00 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_home' [11.48 GiB] inherit //lv_home大小為11.48G

  使用lvscan命令可以查看出當前LV/dev/VolGroup/lv_home大小為11.48G。

查看組卷大小

[root@serverX ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <63.51 GiB
  PE Size               4.00 MiB
  Total PE              16258
  Alloc PE / Size       16243 / <63.45 GiB
  Free  PE / Size       15 / 60.00 MiB //硬盤可供指派給邏輯卷的單位
  VG UUID               dcN4dI-xFex-69UJ-6L1d-b4b4-9BEZ-YdPD6f

  查看當前硬盤可供指派給邏輯卷的最小單位已經不足以使用,所以需要對當前VG進行擴展,在此我們做一個分區用於擴展VG。

添加所需分區

parted /dev/sdb
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext4
Start? 1
End? 5GiB
(parted) print
Model: ATA CentOS Linux-1 (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  5369MB  5368MB  primary

將新添加的分區加入邏輯卷中

[root@serverX ~]# vgextend VolGroup /dev/sdb1 //將sdb1分區加入卷組
  Physical volume "/dev/sdb1" successfully created.
  Volume group "VolGroup" successfully extended
[root@serverX ~]# lvextend -L 15GiB /dev/VolGroup/lv_home //擴展邏輯卷至15GiB
  Size of logical volume VolGroup/lv_home changed from 11.48 GiB (2939 extents) to 15.00 GiB (3840 extents).
  Logical volume VolGroup/lv_home successfully resized.
[root@serverX ~]# resize2fs /dev/VolGroup/lv_home //更新邏輯卷
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/VolGroup/lv_home is mounted on /home; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/VolGroup/lv_home is now 3932160 blocks long.

[root@serverX ~]# lvscan //重新掃描確認結果
  ACTIVE            '/dev/VolGroup/lv_swap' [<1.97 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_root' [50.00 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_home' [15.00 GiB] inherit

三、創建用戶組

創建下列用戶、組以及和組的成員關系:

  • 一個名為adminuser的組;
  • 一個名為natasha的用戶,其屬於adminuser,這個組是該用戶的從屬組;
  • 一個名為harry的用戶,屬於adminuser,這個組是該用戶的從屬組;
  • 一個名為sarah的用戶,其在系統中沒有可交互的shell,並且不是adminuser組的成員;
  • natasha、harry、sarah的密碼都要設置為flectrag。
[root@serverX ~]# groupadd adminuser
[root@serverX ~]# useradd -G adminuser natasha //-G指定用戶所屬的從屬組
[root@serverX ~]# useradd -G adminuser harry
[root@serverX ~]# useradd -s /sbin/nologin sarah //-s 指定登錄shell,/sbin/nologin表示不能登錄系統
[root@serverX ~]# echo flectrag|passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@serverX ~]# echo flectrag|passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@serverX ~]# echo flectrag|passwd --stdin sarah
Changing password for user sarah.
passwd: all authentication tokens updated successfully.

四、使用訪問控制列表配置文件權限

拷貝文件/etc/fstab到/var/tmp/fstab,配置文件/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@serverX ~]# cp /etc/fstab /var/tmp/
[root@serverX ~]# setfacl -m u:natasha:rw /var/tmp/fstab
[root@serverX ~]# setfacl -m u:harry:- /var/tmp/fstab

五、配置一個crontab任務

為用戶natasha配置一個定時任務,每天在本地時間14:23時執行以下命令:
bin/echo hiya

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

  計划任務時間格式為分時日月周,后面直接加要執行的命令即可。
crontab -e -u user:為指定用戶編輯計划任務
crontab -l:查看當前用戶所有的計划任務
crontab -r:清除計划任務

特殊字符 代表意義
* 代表任何時刻,例如分鍾為*,代表每分鍾都執行
, 代表分割時段,例如小時為3,5表示3時和5時執行此計划任務
- 代表一個時間段范圍,例如日配置為1-10,表示相應月的1-10號執行此計划任務
/n n表示數字,如果分鍾為*/5,表示每五分鍾執行一次計划任務

六、創建一個多用戶使用目錄

創建一個多用戶共同使用的目錄/home/admins,特性如下:

  • /home/admins目錄的組所有權是adminuser;
  • adminuser組的成員對目錄有讀寫和執行的權限。除此之外的其他所有用戶沒有任何權限(root除外);
  • 在/home/admins目錄中創建的文件,其組所有權會自動設置為屬於adminuser組。
[root@serverX ~]# mkdir /home/admins
[root@serverX ~]# chown :adminuser /home/admins/ //設置目錄所屬組為adminuser
[root@serverX ~]# chmod 2770 /home/admins //2770特殊權限為2表示為SGID,使用者在此目錄下的群組將會變成該目錄的群組,770表示文件的屬主屬組擁有讀寫執行權限。
[root@serverX ~]# ll /home/
total 0
drwxrws---. 2 root     adminuser  6 Jan  3 17:28 admins

七、升級操作系統內核

新版本內核文件可以從http://rhgls.domainX.example.com/pub/updates/獲取。升級操作系統內核,同事需要滿足下列要求:

  • 當系統重新啟動之后升級的內核要作為默認的內核;
  • 原來的內核要被保留,並且仍然可以正常啟動。
[root@serverX ~]# uname -r
3.10.0-693.el7.x86_64
[root@serverX ~]# wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm
--2019-01-03 18:08:33--  https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm
Resolving elrepo.org (elrepo.org)... 69.195.83.87
Connecting to elrepo.org (elrepo.org)|69.195.83.87|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 47850944 (46M) [application/x-rpm]
Saving to: ‘kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm’

100%[===================================================================================================================>] 47,850,944   603KB/s   in 79s

2019-01-03 18:09:53 (589 KB/s) - ‘kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm’ saved [47850944/47850944]
[root@serverX ~]# rpm -ivh kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm
warning: kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:kernel-ml-4.19.12-1.el7.elrepo   ################################# [100%]
[root@serverX ~]# cat /boot/grub2/grub.cfg |grep menuentry //過濾啟動項,查看grub配置文件中是否存在安裝后的內核啟動參數。
if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
  menuentry_id_option=""
export menuentry_id_option
menuentry 'CentOS Linux (4.19.12-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-da5515d9-ffb3-4589-99c5-699b3fcb547f' {
menuentry 'CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-da5515d9-ffb3-4589-99c5-699b3fcb547f' {
menuentry 'CentOS Linux (0-rescue-529c8dcd6c464addae7654f5958443c6) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-529c8dcd6c464addae7654f5958443c6-advanced-da5515d9-ffb3-4589-99c5-699b3fcb547f' {
[root@serverX ~]#grub2-set-default 'CentOS Linux (4.19.12-1.el7.elrepo.x86_64) 7 (Core)' //將默認啟動內核設置為新安裝內核
[root@serverX ~]#grub2-editenv list //確認是否設置成功
saved_entry=CentOS Linux (4.19.12-1.el7.elrepo.x86_64) 7 (Core)
[root@serverX ~]#reboot 
[root@serverX ~]#uname -r
4.19.12-1.el7.elrepo.x86_64

八、使用LDAP進行用戶集中認證

系統host.domainX.example.com提供了一個LDAP驗證服務。將系統按照以下要求綁定到這個服務上:

  • 驗證服務器的基本 DN 是:dc=domainX,dc=example,dc=com;
  • 帳戶信息和驗證信息都是由 LDAP 提供的;
  • 連接要使用證書進行加密,證書可以在下面的鏈接中下載 :ftp://host.domainX.example.com/pub/domainX.crt;
  • 當正確完成配置后,用戶 ldapuserX 應該能夠登錄到您的系統中,但是沒有主目錄。 當您完成 autofs 的題目之后,才能生成主目錄;
  • 用戶 ldapuserX 的密碼是 password。
[root@serverX ~]# yum -y install sssd
[root@serverX ~]# authconfig-tui


[root@serverX ~]# cd /etc/openldap/certs/
[root@serverX certs]# wget ftp://host.domainx.example.com/pub/domainX.crt
[root@serverX certs]# systemctl restart sssd
[root@serverX certs]# id ldapuserX
uid=17X(ldapuserX) gid=17X(ldapuserX) groups=17X(ldapuserX)

九、autofs配置

按照以下要求配置autofs用來自動掛載LDAP用戶的家目錄:

  • host.domainX.example.com(172.24.10.250)通過 NFS v3 版本輸出 /rhome 目錄到您的系統,這個文件系統包含了用戶 ldapuserX 的主目錄,並且已經預先配置好;
  • ldapuserX 用戶的家目錄是 host.domainX.example.com:/rhome/ldapuserX;
  • ldapuserX 的家目錄應該掛載到本地的/rhome/ldapuserX 目錄下;
  • 用戶對其家目錄是可寫的;
  • ldapuserX 用戶的密碼是 password。
[root@serverX ~]# yum -y install autofs
[root@serverX ~]# mkdir /rhome/ldapuserX -p
[root@serverX ~]# vim /etc/auto.master //指定監控點
/rhome/ldapuserX /etc/guests.rule
[root@serverX ~]# vim /etc/guests.rule
ldapuserX -rw,v3 host.domainX.example.com:/rhome/ldapuserX //通過NFS V3版本以可讀寫方式進行掛載
[root@serverX ~]# systemctl start autofs
[root@serverX ~]# systemctl enable autofs
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.
[root@serverX ~]# su - ldapuserX -c 'pwd'
/rhome/ldapuserX

十、配置NTP客戶端

配置操作系統,讓其作為ntp1.aliyun.com的NTP客戶端。

[root@serverX ~]# yum -y install chrony
[root@serverX ~]# vim /etc/chrony.conf
server ntp1.aliyun.com iburst //注釋原有默認NTP地址
[root@serverX ~]# systemctl restart chronyd
[root@serverX ~]# timedatectl
      Local time: Fri 2019-01-04 14:39:02 CST
  Universal time: Fri 2019-01-04 06:39:02 UTC
        RTC time: Fri 2019-01-04 06:39:02
       Time zone: America/New_York (CST, +0800)
     NTP enabled: yes //查看NTP是否啟用
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

十一、配置一個用戶賬戶

創建一個名為alex的用戶,用戶ID為3456。密碼是flectrag

[root@serverX ~]# useradd -u 3456 alex
[root@serverX ~]# echo flectrag | passwd --stdin alex
Changing password for user alex.
passwd: all authentication tokens updated successfully.

十二、添加一個swap分區

在操作系統中添加一個大小為512MiB的swap分區,詳細信息如下:

  • 當操作系統啟動時,swap分區可以自動掛載;
  • 不要移除或修改當前系統中其他的swap分區。
[root@serverX ~]# fdisk /dev/sdb
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x001379c8.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +512M
Partition 1 of type Linux and of size 512 MiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@serverX ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=05291f58-7136-436b-b5ed-28df93547bbc
[root@serverX ~]# vim /etc/fstab
/dev/sdb1 swap swap defaults 0 0
[root@serverX ~]# swapon -a
[root@serverX ~]# swapon -s //查看當前交換分區啟動情況
Filename				Type		Size	Used	Priority
/dev/dm-1                              	partition	2097148	0	-2
/dev/sdb1                              	partition	524284	0	-3

十三、查找文件

找出所有用戶student擁有的文件,並且把它們拷貝到/root/findfiles目錄中。

mkdir /root/findfiles ; find / -user student -type f |xargs -i cp {} /root/findfiles/

十四、查找一個字符串

在文件/usr/share/dict/words 中查找到所有包含字符串 seismic 的行:

  • 將找出的行按照原文的先后順序拷貝到/root/wordlist 文件中;
  • /root/wordlist 文件不要包含空行,並且其中的所有行的內容都必須是/usr/share/dict/words 文件中原始行的准確副本。
[root@serverX ~]# grep 'seismic' /usr/share/dict/words > /root/wordlist

十五、創建一個邏輯卷

根據下面的要求創建一個新的邏輯卷:

  • 邏輯卷命名為 database,屬於 datastore 卷組,並且邏輯卷的大小為 50 個物理擴展單元 (physical extent);
  • 在 datastore 卷組中的邏輯卷,物理擴展單元 (physical extent) 大小應為 16 MiB;
  • 使用 ext3 文件系統對新的邏輯卷進行格式化,此邏輯卷應該在系統啟動的時候自動掛載在 /mnt/database 目錄下。
[root@serverX ~]# fdisk /dev/sdb
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 (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2):
First sector (1050624-209715199, default 1050624):
Using default value 1050624
Last sector, +sectors or +size{K,M,G} (1050624-209715199, default 209715199): +1G //因為題目要求PE大小為16MiB,邏輯卷大小為50PE,所以用於做此邏輯卷的分區必須大於50x16,free PE數小於50會導致創建失敗。
Partition 2 of type Linux and of size 50 MiB is set

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@serverX ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x001379c8

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     1050623      524288   83  Linux
/dev/sdb2         1050624     1153023       51200   83  Linux
[root@serverX ~]# partprobe /dev/sdb ;sync
[root@serverX ~]# vgcreate -s 16MiB datastore /dev/sdb2
  Physical volume "/dev/sdb2" successfully created.
  Volume group "datastore" successfully created
[root@serverX ~]# lvcreate -l 50 -n database datastore
  Logical volume "database" created.
[root@serverX ~]# mkfs.ext3 /dev/datastore/database
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
51296 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7328 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

[root@serverX ~]# mkdir /mnt/database
[root@serverX ~]# vim /etc/fstab
/dev/datastore/database /mnt/database ext3 defaults 0 0
[root@serverX ~]# mount -a 

十六、創建一個歸檔文件

創建一個名為 /root/backup.tar.bz2 的歸檔文件,其中包含 /usr/local 目錄中的內容,tar 歸檔必須使用 bzip2 進行壓縮。

tar jcf /root/backup.tar.bz2 /usr/local/


免責聲明!

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



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