Linux7認證(RHCSA)試題及參考解答方法

一、設置環境:

請初始化您的考試虛擬機 server0.example.com,將系統的 root 賬號密碼設置為 123456 。配置您的虛擬機系統使用下述靜態網絡配置:

* Hostname:server0.example.com * IP address:172.25.0.11 * Netmask:255.255.255.0 * Gateway:172.25.0.254 * Name server:172.25.254.254

解題:

1.1.修改密碼

Linux7認證(RHCSA)試題及參考解答方法

<code>按“e”進入編輯模式
在utf-8後面添加空格 rd.break
Ctrl + x執行/<code>
<code>

<code>

Linux7認證(RHCSA)試題及參考解答方法

<code>以讀寫權限重新掛載硬盤上的真實系統根目錄:
mount -o remount,rw / /sysroot
切換至真實系統根目錄:
chroot /sysroot
按要求修改root密碼:
echo 123456 | passwd --stdin root
重新打標:
touch /.autorelabel
退出真實系統:
exit
退出系統重新引導:
exit
以新密碼登錄系統/<code>

Linux7認證(RHCSA)試題及參考解答方法

Linux7認證(RHCSA)試題及參考解答方法

1.2.設置主機名

<code>[root@server0 ~]# hostnamectl set-hostname server0.example.com  
[root@server0 ~]# bash
[root@server0 ~]# hostname
server0.example.com
[root@server0 ~]# /<code>

1.3.設置網絡

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# nmcli connection modify eth0 ipv4.addresses "172.25.0.11/24 172.25.0.254"  ipv4.dns "172.25.254.254" connection.autoconnect yes ipv4.method manual
[root@server0 ~]# nmcli connection reload
[root@server0 ~]# service network restart
Restarting network (via systemctl): [ OK ]
[root@server0 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
IPV6INIT=no
NAME=eth0
PERSISTENT_DHCLIENT=1
IPADDR0=172.25.0.11
PREFIX0=24
GATEWAY0=172.25.0.254
DNS1=172.25.254.254
DOMAIN=server0.example.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

二、設置SELinux

請保證系統 SELinux 運行在 Enforcing 狀態,要求系統重啟仍然生效

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# setenforce 1
[root@server0 ~]# getenforce
Enforcing
[root@server0 ~]#
[root@server0 ~]# vim /etc/selinux/config /<code>
Linux7認證(RHCSA)試題及參考解答方法

[root@server0 ~]# reboot

Linux7認證(RHCSA)試題及參考解答方法

三、配置yum源

配置你的本地默認 YUM 倉庫指向 http://classroom.example.com/content/rhel7.0/x86_64/dvd

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# yum-config-manager --help | grep add
--downloaddir=DLDIR
--add-repo=ADDREPO add (and enable) the repo from the specified file or
[root@server0 ~]# yum-config-manager --add-repo="http://classroom.example.com/content/rhel7.0/x86_64/dvd/"
Loaded plugins: langpacks
adding repo from: http://classroom.example.com/content/rhel7.0/x86_64/dvd/

[classroom.example.com_content_rhel7.0_x86_64_dvd_]
name=added from: http://classroom.example.com/content/rhel7.0/x86_64/dvd/
baseurl=http://classroom.example.com/content/rhel7.0/x86_64/dvd/
enabled=1


[root@server0 ~]# echo "gpgcheck=0">>/etc/yum.repos.d/classroom.example.com_content_rhel7.0_x86_64_dvd_.repo
[root@server0 ~]# yum clean all
Loaded plugins: langpacks
Cleaning repos: classroom.example.com_content_rhel7.0_x86_64_dvd_ rhel_dvd
Cleaning up everything
[root@server0 ~]# yum makecache
Loaded plugins: langpacks
classroom.example.com_content_rhel7.0_x86_64_dvd_ | 4.1 kB 00:00:00
rhel_dvd | 4.1 kB 00:00:00
(1/9): classroom.example.com_content_rhel7.0_x86_64_dvd_/group_gz | 134 kB 00:00:00
(2/9): classroom.example.com_content_rhel7.0_x86_64_dvd_/primary_db | 3.4 MB 00:00:00
(3/9): classroom.example.com_content_rhel7.0_x86_64_dvd_/other_db | 1.3 MB 00:00:00
(4/9): classroom.example.com_content_rhel7.0_x86_64_dvd_/productid | 1.6 kB 00:00:00
(5/9): classroom.example.com_content_rhel7.0_x86_64_dvd_/filelists_db | 3.0 MB 00:00:00
(6/9): rhel_dvd/group_gz | 134 kB 00:00:00
(7/9): rhel_dvd/primary_db | 3.4 MB 00:00:00
(8/9): rhel_dvd/other_db | 1.3 MB 00:00:00
(9/9): rhel_dvd/filelists_db | 3.0 MB 00:00:00
Metadata Cache Created
[root@server0 ~]# yum repolist
Loaded plugins: langpacks
repo id repo name status
classroom.example.com_content_rhel7.0_x86_64_dvd_ added from: http://classroom.example.com/content/ 4,305
rhel_dvd Remote classroom copy of dvd 4,305
repolist: 8,610
[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

四、調整邏輯卷

1. 新建一個邏輯卷,名字為lv0 ,其屬於 vg0 卷組,該邏輯卷由 16 個 LE 組成。卷組 vg0 的單個 PE 大小為 16 MiB。將新創建的邏輯卷格式化為 xfs 文件系統,在系統啟動時,該邏輯卷會被自動掛載到 /mnt/lvm 目錄下。

2. 將邏輯卷 lv0 和其文件系統大小調整到 384 MiB。要確保文件系統中的內容保持完整。請注意:分區大小很少能夠完全符合要求的大小,所以大小在 352 MiB 和 416 MiB 之間都是可以接受的。

解題:

4.1.劃分1G的LVM

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# fdisk /dev/vdb 
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 0x095042ab.

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x095042ab

Device Boot Start End Blocks Id System

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

Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-2099199, default 4096):
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-2099199, default 2099199):
Using default value 2099199
Partition 5 of type Linux and of size 1023 MiB is set

Command (m for help): t
Partition number (1,5, default 5): 5
Hex code (type L to list all codes): 8e
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.
Syncing disks.
[root@server0 ~]# partprobe
[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

4.2.按要求添加邏輯卷

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# pvcreate /dev/vdb5
Physical volume "/dev/vdb5" successfully created
[root@server0 ~]# vgcreate --help | grep size
[-s|--physicalextentsize PhysicalExtentSize[bBsSkKmMgGtTpPeE]]
[root@server0 ~]# vgcreate vg0 -s 16M /dev/vdb5
Volume group "vg0" successfully created
[root@server0 ~]# vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 1008.00 MiB
PE Size 16.00 MiB
Total PE 63
Alloc PE / Size 0 / 0
Free PE / Size 63 / 1008.00 MiB
VG UUID jvZd9h-nV9v-ankV-skjP-btgB-vF8R-W67IRT

[root@server0 ~]# lvcreate -n lv0 -l 16 vg0
Logical volume "lv0" created
[root@server0 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/lv0
LV Name lv0
VG Name vg0
LV UUID n8oBJF-9caQ-COg8-2peS-pWTz-mQDj-rXHUKL
LV Write Access read/write
LV Creation host, time server0.example.com, 2019-12-03 21:47:56 +0800
LV Status available
# open 0
LV Size 256.00 MiB
Current LE 16
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0

[root@server0 ~]# mkfs.xfs /dev/vg0/lv0
meta-data=/dev/vg0/lv0 isize=256 agcount=4, agsize=16384 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=65536, 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@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

4.3.設置自動掛載

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# mkdir -p /mnt/lvm
[root@server0 ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb5: UUID="KydhrK-3Nar-ktHy-b6Gq-skNj-sIQu-MgWCmm" TYPE="LVM2_member"
/dev/mapper/vg0-lv0: UUID="11ddc813-2a94-46f7-a7de-e735eb8bfe8c" TYPE="xfs"
[root@server0 ~]# echo "UUID="11ddc813-2a94-46f7-a7de-e735eb8bfe8c" /mnt/lvm xfs defaults 0 0">>/etc/fstab
[root@server0 ~]# mount -av
/ : ignored
mount: /mnt/lvm does not contain SELinux labels.
You just mounted an file system that supports labels which does not
contain labels, onto an SELinux box. It is likely that confined
applications will generate AVC messages and not be allowed access to
this file system. For more details see restorecon(8) and mount(8).
/mnt/lvm : successfully mounted
[root@server0 ~]# df -lh | grep lv0
/dev/mapper/vg0-lv0 253M 13M 240M 6% /mnt/lvm
[root@server0 ~]#/<code>
Linux7認證(RHCSA)試題及參考解答方法

4.4.擴容

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# lvextend -L 384M /dev/vg0/lv0 
Extending logical volume lv0 to 384.00 MiB
Logical volume lv0 successfully resized
[root@server0 ~]# xfs_growfs /dev/vg0/lv0
meta-data=/dev/mapper/vg0-lv0 isize=256 agcount=4, agsize=16384 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=65536, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 65536 to 98304
[root@server0 ~]# df -lh | grep lv0
/dev/mapper/vg0-lv0 381M 14M 368M 4% /mnt/lvm
[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

五、按照以下要求創建用戶、組

• 新建一個名為adminuser的組,id為40000• 新建一個natasha的用戶,並將adminuser作為其附屬組• 新建一個harry用戶,並將adminuser作為其附屬組• 新建一個sarah的用戶,其不屬於adminuser組,在系統送沒有任何可交互的shell• natasha、harry、和sarah三個用戶的密碼均設為rehat

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# groupadd --help | grep id
-g, --gid GID use GID for the new group
-K, --key KEY=VALUE override /etc/login.defs defaults
[root@server0 ~]# groupadd -g 40000 adminuser
[root@server0 ~]# cat /etc/group | grep 4000
adminuser:x:40000:
[root@server0 ~]# useradd --help | grep group
-g, --gid GROUP name or ID of the primary group of the new
-G, --groups GROUPS list of supplementary groups of the new
-N, --no-user-group do not create a group with the same name as
-U, --user-group create a group with the same name as the user
[root@server0 ~]# useradd -G adminuser natasha
[root@server0 ~]# useradd -G adminuser harry
[root@server0 ~]# useradd --help | grep shell
-s, --shell SHELL login shell of the new account
[root@server0 ~]# useradd -s /sbin/nologin sarah
[root@server0 ~]# cat /etc/passwd | grep sarah
sarah:x:1003:1003::/home/sarah:/sbin/nologin
[root@server0 ~]# echo rehat | passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@server0 ~]# echo rehat | passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@server0 ~]# echo rehat | passwd --stdin sarah
Changing password for user sarah.
passwd: all authentication tokens updated successfully.
[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

六、配置文件權限

• 該文件的所屬組為root• 該文件的所屬人為root• 該文件對任何人均沒有執行權限• 用戶natasha對該文件有讀和寫權限• 用戶harry對該文件既不能讀也不能寫• 所有用戶(包括當前用戶和未來創建的用戶)對該文件都有讀的權限

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# cp -a  /etc/fstab /var/tmp/
[root@server0 ~]# chown root:root /var/tmp/fstab

[root@server0 ~]# chmod a-x /var/tmp/fstab
[root@server0 ~]# setfacl -Rm u:natasha:rw,u:harry:-- /var/tmp/fstab
[root@server0 ~]# chmod a+r /var/tmp/fstab
[root@server0 ~]# 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--

[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

七、建立計劃任務

• 對natasha用戶建立計劃任務,要求在本地時間的每天14:23執行 /bin/echo "rhcsa" 命令

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# crontab -e -u natasha
[root@server0 ~]# crontab -l -u natasha
# mim hour day month week command
23 14 * * * /bin/echo "rhcsa"

[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

八、創建共享目錄

• /home/admins目錄的所屬組為adminuser• 該目錄對adminuser組的成員可讀可寫可執行,但是對其它用戶沒有任何權限,但是root不受限制• 在/home/admins目錄下創建的文件所屬組自動被設置為adminuser

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# mkdir /home/admins
[root@server0 ~]# chgrp adminuser /home/admins/
[root@server0 ~]# chmod g=rwx,o=-- /home/admins/
[root@server0 ~]# chmod g+s /home/admins/
[root@server0 ~]# ls -ld /home/admins/

drwxrws---. 2 root adminuser 6 Dec 3 22:17 /home/admins/
[root@server0 ~]# getfacl /home/admins/
getfacl: Removing leading '/' from absolute path names
# file: home/admins/
# owner: root
# group: adminuser
# flags: -s-
user::rwx
group::rwx
other::---
[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

九、升級系統內核

• 當系統重新啟動之後,升級的內核要作為默認的內核• 原來的內核要被保留,並且仍然可以正常啟動• A 新內核的 RPM 包在http://classroom.example.com/content/rhel7.0/x86_64/errata/Packages注意事項:使用連接的時候一定要在連接尾部添加“/”

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# curl -s http://classroom.example.com/content/rhel7.0/x86_64/errata/Packages/  | grep kernel                     
[   ]
2014-06-11 04:34 29M
[   ]2014-06-11 04:35 12M
[root@server0 ~]# wget http://classroom.example.com/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm
--2019-12-03 23:52:28-- http://classroom.example.com/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm
Resolving classroom.example.com (classroom.example.com)... 172.25.254.254

Connecting to classroom.example.com (classroom.example.com)|172.25.254.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 30266784 (29M) [application/x-rpm]
Saving to: ‘kernel-3.10.0-123.1.2.el7.x86_64.rpm’

100%[=================================================>] 30,266,784 82.1MB/s in 0.4s

2019-12-03 23:52:29 (82.1 MB/s) - ‘kernel-3.10.0-123.1.2.el7.x86_64.rpm’ saved [30266784/30266784]

[root@server0 ~]# ls
anaconda-ks.cfg Documents kernel-3.10.0-123.1.2.el7.x86_64.rpm Pictures Templates
Desktop Downloads Music Public Videos
[root@server0 ~]# chmod 755 kernel-3.10.0-123.1.2.el7.x86_64.rpm
[root@server0 ~]# rpm -ivh kernel-3.10.0-123.1.2.el7.x86_64.rpm
warning: kernel-3.10.0-123.1.2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:kernel-3.10.0-123.1.2.el7 ################################# [100%]
[root@server0 ~]# grub2-editenv list
saved_entry=Red Hat Enterprise Linux Server (3.10.0-123.1.2.el7.x86_64) 7.0 (Maipo)
[root@server0 ~]# reboot/<code>
Linux7認證(RHCSA)試題及參考解答方法

十、綁定外部驗證

• 在 classroom.example.com 上已部署了一臺 LDAP 認證服務器,按以下要求配置你的系統

• 加入到該 LDAP 服務中,並使用 Kerberos 認證用戶密碼

• 該 LDAP 認證服務的Base DN為:dc=example,dc=com .

• 該 LDAP 認證服務的LADP Server為 :classroom.example.com

• 該認證服務的 Kerbros Realm 為:EXAMPLE.COM

• 該認證服務的 Kerbros KDC為:classroom.example.com

• 該認證服務的 Kerbros Admin Server為:classroom.example.com

• 認證的會話連接需要被加密,證書的下載地址為 http://classroom.example.com/pub/example-ca.crt

解題:

10.1.安裝必備軟件

<code>[root@server0 ~]# yum install authconfig-gtk sssd krb5-workstation -y
[root@server0 ~]# authconfig-gtk/<code>

10.2.配置LDAP

Linux7認證(RHCSA)試題及參考解答方法

<code>
<code>上面配置完成再進行(沒有配置的話sssd服務無法啟動):
[root@server0~]# systemctl enable sssd
[root@server0~]# systemctl restart sssd
[root@server0~]# systemctl status sssd
[root@server0~]# su ldapuser0
bash-4.2$
驗證用戶:ldapuser0/<code>

[root@server0 ~]# systemctl restart sssd[root@server0 ~]# su ldapuser0bash-4.2$ exitexit[root@server0 ~]# getent passwd ldapuser0ldapuser0:*:1700:1700:LDAP Test User 0:/home/guests/ldapuser0:/bin/bash[root@server0 ~]#

<code> /<code>
Linux7認證(RHCSA)試題及參考解答方法

十一、配置autofs

  • classroom.example.com 使用 NFS 共享了/home/guests 給你的系統。這個文件系統包含了預先設置好的用戶 ldapuser0 的家目錄;
  • ldapuser0 的家目錄是 classroom.example.com:/home/guests/ldapuser0 ;
  • ldapuser0 的家目錄應該自動掛載到本地的 /home/guests/ldapuser0 家目錄必須對用戶具有可寫權限;
  • ldapuser0 的密碼是 'kerberos’

解題:

11.1.安裝軟件

<code>[root@server0 ~]# yum install autofs -y
[root@server0 ~]# systemctl enable autofs.service/<code>

11.2.設置掛載

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# cp -a /etc/auto.misc /etc/auto.aa
[root@server0 ~]# echo "/home/guests /etc/auto.aa" >>/etc/auto.master
[root@server0 ~]# echo "* -type=nfs,rw classroom.example.com:/home/guests/&">>/etc/auto.aa
[root@server0 ~]# systemctl restart autofs.service
[root@server0 ~]# ssh ldapuser0@localhost
ldapuser0@localhost's password: (kerberos)
Last login: Wed Dec 4 00:50:57 2019 from localhost
[ldapuser0@server0 ~]$ cd /home/guests/
[ldapuser0@server0 guests]$ ls
ldapuser0
[ldapuser0@server0 guests]$ /<code>
Linux7認證(RHCSA)試題及參考解答方法

十二、配置NTP

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

解題:

12.1.如圖

Linux7認證(RHCSA)試題及參考解答方法

12.2.設置開機啟動

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# systemctl enable chronyd
[root@server0 ~]# systemctl restart chronyd.service
[root@server0 ~]# chronyc sources -v
210 Number of sources = 1

.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| / xxxx = adjusted offset,
|| Log2(Polling interval) -. | yyyy = measured offset,
|| \\ | zzzz = estimated error.
|| | |
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* classroom.example.com 8 6 17 17 +796ns[ -21us] +/- 1176us
[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

十三、創建歸檔

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

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# man tar | grep zip2   
-j, --bzip2
filter the archive through bzip2
-j, --bzip2
filter the archive through bzip2
[root@server0 ~]# tar -jcf /root/sysconfg.tar.bz2 /etc/sysconfig/ /<code>
Linux7認證(RHCSA)試題及參考解答方法

十四、創建一個用戶

  • 用戶id=3456 用戶名:jay
  • 密碼為:glegunle

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# useradd -u 3456 jay
[root@server0 ~]# echo "glegunge"|passwd --stdin jay
Changing password for user jay.
passwd: all authentication tokens updated successfully.
[root@server0 ~]# id jay
uid=3456(jay) gid=3456(jay) groups=3456(jay)

[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

十五、添加swap分區

• swap分區的容量為512M• 當您的系統啟動時,swap分區可以自動掛載• 不要移動或是修改其它已經存在於您的系統中的swap分區

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# fdisk /dev/vdb 
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 (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-20971519, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519): +512M
Partition 2 of type Linux and of size 512 MiB is set

Command (m for help): t
Partition number (1,2,5, default 5): 2
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

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@server0 ~]# partprobe
[root@server0 ~]# mkswap /dev/vdb2
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=b9a7e4a8-66f9-4de0-8d3e-f09a7844fa69
[root@server0 ~]# swapon -av /dev/vdb2
swapon /dev/vdb2
swapon: /dev/vdb2: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/vdb2: pagesize=4096, swapsize=536870912, devsize=536870912
[root@server0 ~]# echo "UUID=b9a7e4a8-66f9-4de0-8d3e-f09a7844fa69 swap swap defults 0 0">>/etc/fstab
[root@server0 ~]# mount -av
/ : ignored
/mnt/lvm : already mounted
swap : ignored/<code>

[root@server0 ~]# free -lh | grep Swap Swap: 511M 0B 511M [root@server0 ~]#

<code>
Linux7認證(RHCSA)試題及參考解答方法

十六、查找文件

  • 請把系統上擁有者為jay用戶的所有文件,拷貝到/root/findfiles目錄中

解題:

Linux7認證(RHCSA)試題及參考解答方法

<code>[root@server0 ~]# mkdir /root/findfiles -p
[root@server0 ~]# find / -user jay -exec cp -a {} /root/findfiles/ \\;
find: ‘/proc/18294/task/18294/fd/6’: No such file or directory
find: ‘/proc/18294/task/18294/fdinfo/6’: No such file or directory
find: ‘/proc/18294/fd/6’: No such file or directory
find: ‘/proc/18294/fdinfo/6’: No such file or directory
find: ‘/home/guests/ldapuser0’: Permission denied
cp: cannot overwrite non-directory ‘/root/findfiles/jay’ with directory ‘/home/jay’
[root@server0 ~]# ls -l /root/findfiles/
total 8
drwxr-xr-x. 2 jay jay 6 Jan 27 2014 extensions
-rw-r--r--. 1 jay jay 4 Jul 11 2014 gnome-initial-setup-done
-rw-rw----. 1 jay mail 0 Dec 4 01:07 jay
-rw-r--r--. 1 jay jay 1443 Jul 11 2014 monitors.xml
drwxr-xr-x. 2 jay jay 6 Jan 27 2014 plugins
[root@server0 ~]# /<code>
Linux7認證(RHCSA)試題及參考解答方法

十七、查找一個字符串

• 把/usr/share/dict/words文件中包含seismic字符串的行找到,並將這些行按照原始文件中的順序存放到/root/wordlist中。• /root/wordlist文件不能包含空行。

解題:

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


分享到:


相關文章: