=========================================
RHCSA考试大致要求(自整理)
========================================
1-1. 重启系统,在已开机的desktop虚拟机上,同时按下Ctrl+Alt+Del
三键
1-2. 在Grub Boot Loader
倒计时读秒技术前,按下任意键
1-3. 选中默认的的第一个启动条目,并按下键盘字母e
键,以便编辑
1-4. 进入启动条目编辑界面后,通过键盘方向键(↓)
,找到第一个以linux16
开头的行,并通过按下Ctrl+e
快速把光标定位到该行的行末,输入<空格键> rd.break
1-5. 确定没错之后,按下Ctrl+x
,以修改后的配置引导系统,系统将启动到临时内核shell界面,输入以下指令即可修改密码
switch_root :/# mount -o remount,rw / /sysroot
sh-4.2# chroot /sysroot
sh-4.2# echo rrhh9708 | passwd --stdin root
sh-4.2#
sh-4.2# touch /.autorelabel
sh-4.2#
sh-4.2# exit
sh-4.2# exit
注意: 修改密码后,首次重启的时间将会比较长,因为系统将对所有文件进行Selinux 打标,请耐心等待,整个过程并非死机,请勿在打标过程中手动强制再次重启,否则系统将会永久性损坏导致无法开机
1-6. 成功启动系统后,输入账号root
,密码为题目要求修改的密码
后,完成网络配置
nmcli
命令管理网络[root@localhost ~]# nmcli device //查看本机网卡设备
[root@localhost ~]# nmcli connection //查看本机连接
[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 ~]# nmcli connection reload //重新加载连接配置信息
[root@localhost ~]# nmcli connection down eth0 //关闭网卡
[root@localhost ~]# nmcli connection up eth0 //重启网卡
[root@localhost ~]# ping -c5 server //测试网络连通性
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.260 ms
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=2 ttl=64 time=0.588 ms
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=3 ttl=64 time=1.18 ms
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=4 ttl=64 time=0.631 ms
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=5 ttl=64 time=0.562 ms
--- server.group8.example.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 0.260/0.644/1.180/0.298 ms
redhat系统中,网卡配置文件位于/etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none //将dhcp修改为none或者static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=4dc8c88c-69b0-4203-a0a6-3671ceb0cd7e
ONBOOT=yes //将no改为yes确保重启可用
DEVICE=eth0
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPADDR=172.24.8.10 //添加ipaddress信息
PREFIX=24 //添加子网掩码信息,PREFIX或者NETMASK均可
GATEWAY=172.24.8.254 //添加网关信息
DNS1=172.24.8.254 //添加DNS信息
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.24.8.254 server.group8.example.com //修改hosts确保dns服务器域名可达
[root@localhost ~]# systemctl restart network //重启网卡使网络生效
[root@localhost ~]# ping -c5 server //测试网络连通性
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.260 ms
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=2 ttl=64 time=0.588 ms
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=3 ttl=64 time=1.18 ms
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=4 ttl=64 time=0.631 ms
64 bytes from server.group8.example.com (172.24.8.254): icmp_seq=5 ttl=64 time=0.562 ms
--- server.group8.example.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 0.260/0.644/1.180/0.298 ms
1-7. 设定主机名
[root@localhost ~]# hostnamectl set-hostname desktop.group8.example.com
[root@localhost ~]# bash //可以执行bash命令,让终端马上看到修改后的主机名
[root@desktop ~]#
[root@desktop ~]# getenforce
Permissive
[root@desktop ~]# setenforce 1 //临时设置为enforcing模式
[root@desktop ~]# getenforce
Enforcing
[root@desktop ~]# vim /etc/sysconfig/selinux //永久设置为enforcing模式
# 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-config-manager
命令管理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,再次执行上述添加指令
[root@desktop ~]# cat /etc/yum.repos.d/server.group8.example.com_yum.repo
[server.group8.example.com_yum]
name=added from: http://server.group8.example.com/yum
baseurl=http://server.group8.example.com/yum
enabled=1
[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
[root@desktop ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release <--- 为了避免安装软件包因外部源未经校验导致安装中断,可以通过导入校验秘钥方式防止中断
[root@desktop ~]#
配置文件位于/etc/yum.repos.d
[root@desktop ~]# cat /etc/yum.repos.d/777.repo
[7]
name=777
baseurl=http://server.group8.example.com/yum <--- 地址严格按照要求填写
enabled=1
gpgcheck=0
[root@desktop ~]# yum repolist
Loaded plugins: aliases, changelog, fastestmirror, langpacks, tmprepo, verify, versionlock
Loading mirror speeds from cached hostfile
repo id repo name status
!7 777 119
repolist: 119
[root@desktop ~]# df -Th
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
/dev/mapper/vg0-lv0 ext3 190M 1.6M 179M 1% /home <--- 当前容量少于290MiB,需要扩容
tmpfs tmpfs 135M 0 135M 0% /run/user/0
[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 200.00 MiB (50 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-ao---- 292.00m <--- 扩容成功,容量一般都会有少量误差,属于正常现象
[root@desktop ~]# resize2fs /dev/vg0/lv0 <--- 刷新文件系统的容量信息
resize2fs 1.42.9 (28-Dec-2013) <--- 注意:如果文件系统是xfs,应该使用xfs_growfs /dev/vg0/lv0
Filesystem at /dev/vg0/lv0 is mounted on /home; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/vg0/lv0 is now 299008 blocks long.
[root@desktop ~]# df -Th
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
/dev/mapper/vg0-lv0 ext3 279M 2.1M 263M 1% /home <--- 调整成功
tmpfs tmpfs 135M 0 135M 0% /run/user/0
如果当前容量比题目要求调整的目标容量要大,那么就需要给逻辑卷裁剪容量
xfs文件系统不支持缩小
[root@desktop ~]# df -Th
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
/dev/mapper/vg0-lv0 ext3 279M 2.1M 263M 1% /home <--- 确认容量为279M,现调整为150M
tmpfs tmpfs 135M 0 135M 0% /run/user/0
[root@desktop ~]# umount /dev/vg0/lv0 <--- 缩小容量前必须先卸载文件系统
[root@desktop ~]# e2fsck /dev/vg0/lv0 <--- 缩小前必须检测文件系统,以免把文件系统的错误扩大
e2fsck 1.42.9 (28-Dec-2013)
/dev/vg0/lv0: clean, 11/75776 files, 15740/299008 blocks
[root@desktop ~]# resize2fs /dev/vg0/lv0 150m <--- 必须先刷新文件系统的容量信息,这是与扩容相反的,顺序错了就会损坏
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vg0/lv0' first. <--- 如果已经检测过,但执行多次还是这个提示,再次执行的时候添加参数-f
[root@desktop ~]# resize2fs -f /dev/vg0/lv0 150m <--- 添加参数 -f 强制调整
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.
[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 <--- 需要输入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 -Th
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 142M 1.6M 133M 2% /home <--- 缩小容量成功
[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
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@desktop ~]# echo redhat | passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@desktop ~]# echo redhat | passwd --stdin sarah
Changing password for user sarah.
passwd: all authentication tokens updated successfully.
/var/tmp/fstab
的权限[root@desktop ~]# cp /etc/fstab /var/tmp/ <--- 注意cp和mv的区别
[root@desktop ~]# chown root:root /var/tmp/fstab <--- 更改文件所有者和所有组
[root@desktop ~]# chmod a-x /var/tmp/fstab <--- 所有人不能执行该文件
[root@desktop ~]# setfacl -m u:natasha:rw,u:harry:--- /var/tmp/fstab <--- 对两个用户分别设置不同的权限
[root@desktop ~]# 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@desktop ~]# crontab -e -u natasha
23 14 * * * /bin/echo "rhcsa"
解析:每一列对应的含义
分钟 | 小时 | 每天 | 每月 | 每星期 |
---|---|---|---|---|
23 | 14 | * | * | * |
[root@desktop ~]# mkdir /home/admins
[root@desktop ~]# chgrp adminuser /home/admins/ <--- 更改所属组
[root@desktop ~]# chmod g=rw,o=--- /home/admins/ <--- 修改权限
[root@desktop ~]# chmod g+s /home/admins/ <--- 设定特权位,实现第三个要求
[root@desktop ~]# ls -ld /home/admins/
drwxrwS---. 2 root adminuser 1024 Mar 31 18:08 /home/admins/ <--- 查看最终属性
http://server.group8. example.com/pub/
下找到需要升级的内核 ,同时满足下列要求:[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...></a></td><td align="right">2016-12-30 16:48 </td><td align="right"> 33M</td><td> </td></tr>
[root@desktop ~]# yum install -y http://server.group8.example.com/pub/kernel-3.10.0-327.4.5.el7.x86_64.rpm <--- 使用yum命令安装内核
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:01
Examining /var/tmp/yum-root-Un01d_/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-Un01d_/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-Un01d_/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
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
Verifying : kernel-3.10.0-327.4.5.el7.x86_64 1/1
Installed:
kernel.x86_64 0:3.10.0-327.4.5.el7
Complete!
[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验证服务
,您的系统需要按照以下要求绑定到这个服务上:http://server.group8.example.com/pub/cacert.pem
当正确完成配置后,用户thales可以登录系统,登录密码是redhat
[root@desktop ~]# yum install -y sssd authconfig-gtk.x86_64 <--- 安装ldap验证所需的服务(sssd必须要有)
mkdir /etc/openldap/cacerts/ <--- 首次使用,必须先自己建立保存证书的目录(或者运行authconfig-tui自动生成)
[root@desktop ~]# wget -O /etc/openldap/cacerts/ca.pem http://server.group8.example.com/pub/cacert.pem <--- 下载证书,保存的证书后缀名必须是.pem
--2020-03-31 18:43:51-- 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
2020-03-31 18:43:51 (213 MB/s) - ‘/etc/openldap/cacerts/ca.pem’ saved [1350/1350]
[root@desktop ~]# authconfig-tui
[root@desktop ~]# getent passwd thales
thales:*:2001:2001:thales:/home/ldap/thales:/bin/bash
报错: 如果无法获得thales用户的信息,或者在执行authconfig-tui命令之后报错
排错: 在确保上面填写的信息与题目提供的信息一致正确的前提下,一般sssd服务无法正确启动导致的,而导致该服务启动失败一般是时间没有和服务器同步
解决: 先完成后面ntp时间同步的题目,然后重新启动sssd服务
[root@desktop ~]# systemctl restart sssd
server.group8.examp1e.com
通过NFS
输出了/rhome
目录到您的系统,这个文件系统包含了用户thales的主目录,并且己经预先配置好了。server.group8.example.com:/rhome/thales
本地的/home/ldap/thales
[root@desktop ~]# yum install -y 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 <--- 当系统访问以/home/ldap路径开头的资源时,读取/etc/*.ldap配置文件进行自动挂载
[root@desktop ~]# vim /etc/auto.ldap
* -rw,sync,soft server.group8.eample.com:/rhome/& <--- 注意-rw前面的“-”符号,还有最后“/&”
配置含义:当访问/home/ldap/* (*代表任意路径)的资源时,自动挂载到
server.group8.example.com:/rhome/对应路径的资源
[root@desktop ldap]# ssh thales@localhost <--- 登录验证
thales@localhost's password:
Last login: Tue Mar 31 19:37:33 2020 from localhost
[thales@desktop ~]$ ls
file1 file2 file3
[thales@desktop ~]$ pwd
/home/ldap/thales
[thales@desktop ~]$ logout
server.group8.example.com
同步,要求系统重启后依然生效提示: redhat 7.0 以后的版本,时间同步采用chrony服务来替代原有的ntp服务,该服务默认已安装
[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 <--- 把这里原来的4行注释掉,考试试环境根本无法与这四台服务器通信
server 1.rhel.pool.ntp.org iburst <--- 把它们留着这里只会影响同步的效率
server server.group8.example.com iburst <--- 把题目要求添加的时间服务器地址添加到这里
[root@desktop ~]# systemctl enable chronyd
[root@desktop ~]# systemctl restart chronyd
[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.000000053, skew: 160.854 <--- 看到类似的返回,说明已经成功同步了
chronyc> exit
/root/sysconfig.tar.bz2
的归档文件,其中包含/etc/sysconfig目录
中的内容,tar归档文件必须使用bzip2
进行压缩[root@desktop ~]# tar -jcf /root/sysconfig.tar.bz2 /etc/sysconfig/
参数解析:
-c
使用bzip2压缩归档
文件
如果考试的时候,要求使用gzip压缩
,那么参数应该是-z
, 也就是-zcf
如果记不住,可以#man tar
jay
的用户, 并满足以下要求:[root@desktop ~]# useradd -u 3456 jay
[root@desktop ~]# echo glegunge | passwd --stdin jay
Changing password for user jay.
passwd: all authentication tokens updated successfully.
swap
分区,并满足以下要求:512MiB
自动挂载
不要移除
或者修改其他已经存在于您的系统中的swap分区[root@desktop ~]# lsblk <--- 查看磁盘
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 9.8G 0 part /
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 500M 0 part
└─vg0-lv0 253:0 0 152M 0 lvm /home
[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): <--- 直接回车,修改刚创建的编号为5的分区,如果不是,可以自行填写分区编号
Hex code (type L to list all codes): 82 <--- 82代表swap类型
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 ~]#
[root@desktop ~]# partprobe <--- 同步磁盘信息
[root@desktop ~]# ls -l /dev/sda5 <--- 如果生成设备文件失败可以使用#partx -a /dev/sda再次生成,如果还失败就重启系统
brw-rw----. 1 root disk 8, 5 Mar 31 20:18 /dev/sda5
[root@desktop ~]# mkswap /dev/sda5 <--- 将该分区格式化为swap格式
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=88a10116-1fd6-43b9-88c4-75a0869c58d0 <--- 复制这个UUID,如果想再次查看uuid可以使用# blkid /dev/sda5查看
[root@desktop ~]# swapon /dev/sda5 <--- 启用该分区
[root@desktop ~]# swapon -s <--- 查看swap分区
Filename Type Size Used Priority
/dev/sda2 partition 2047996 0 -1
/dev/sda5 partition 524284 0 -2
[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=88a10116-1fd6-43b9-88c4-75a0869c58d0 swap swap defaults 0 0 <--- 增加新的swap分区的挂载设定
提示: 您当然也可以把UUID替换成/dev/sda5 (考试的时候是/dev/vda5或其他),但是实际工作中,强烈建议使用UUID挂载
jay
用户的所有文件,并将其拷贝到/root/findfiles
目录中[root@desktop ~]# mkdir /root/findfiles
[root@desktop ~]# find / -user jay -exec cp -a {} /root/findfiles/ \;
/usr/share/dict/words
文件中所有包含seismic字符串
的行找到,并将这些行按照原始文件中的顺序存放到/root/wordlist
中,/root/wordlist文件不能包含空行[root@desktop ~]# grep seismic /usr/share/dict/words | grep -v ^$ > /root/wordlist <--- "grep -V ^$" 是为了保证文件中不能包含空行
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.
[root@desktop ~]# partprobe
[root@desktop ~]# ls -l /dev/sda6
brw-rw----. 1 root disk 8, 6 Mar 31 20:40 /dev/sda6
[root@desktop ~]# pvcreate /dev/sda6 <--- 创建物理卷
Physical volume "/dev/sda6" successfully created
[root@desktop ~]# vgcreate -s 16m datastore /dev/sda6 <--- 按照题目要求将PE设置为16M
Volume group "datastore" successfully created
[root@desktop ~]# vgdisplay datastore
--- Volume group ---
VG Name datastore
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 7.28 GiB
PE Size 16.00 MiB <--- 确定PE与题目要求一致
Total PE 466
Alloc PE / Size 0 / 0
Free PE / Size 466 / 7.28 GiB
VG UUID YKZKQd-sTEi-PXhE-tw3d-5kzW-0htx-0f7gcm
[root@desktop ~]# lvcreate -n database -l 50 datastore<--- 参数小写字母-l,50代表使用50个PE的容量
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 <--- 50x16M=800M
lv0 vg0 -wi-ao---- 152.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="2a5530be-00c6-465d-a884-9b232ac01991" TYPE="xfs"
[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=88a10116-1fd6-43b9-88c4-75a0869c58d0 swap swap defaults 0 0
UUID=2a5530be-00c6-465d-a884-9b232ac01991 /mnt/database xfs defaults 0 0 <--- 增加挂载设定
[root@desktop ~]# mount -a
[root@desktop ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 xfs 9.8G 3.6G 6.3G 36% /
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 142M 1.6M 133M 2% /home
/dev/mapper/datastore-database xfs 797M 33M 765M 5% /mnt/database <--- 检查符合题目要求
重启虚拟机
,以便检测所有考试操作是否在系统重启后仍然生效。[root@desktop ~]# grade
Input password:
###### 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*************
lv0 LV is too small
Checking size of lv0 filesystem... PASS*************
lv0 filesystem is too small
###### 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*************