关键点:如何进入恢复模式(正常的系统根默认挂载到 /sysroot)
1)重启虚拟机,出现 GRUB 启动菜单时按 2次e 键进入编辑状态
2)找到 linux16 所在行,末尾添加 rd.break console=tty0,按 Ctrl+x 键进恢复模式
3)以可写方式挂载硬盘中的根目录,并重设 root 密码:
switch_root:/#
switch_root:/# mount -o remount,rw /sysroot
switch_root:/# chroot /sysroot/
sh-4.2# echo 密码 | passwd --stdin root
sh-4.2# touch /.autorelabel //重新设置selinux标签
或者
sh-4.2# vim /etc/selinux/config
SELINUX=disabled
sh-4.2# exit
switch_root:/# reboot
网卡名(内核识别的设备名):eth0
连接名(管理员指定的配置名):eth0 (System eth0)
系统服务:NetworkManager
nmcli
Network Manager Command Line Interface
如果原来已经有现成的连接:
1)修改连接配置
nmcli con mod “连接名” ipv4.method manual ipv4.addresses “IPv4地址/掩码位数 默认网关地址” ipv4.dns DNS服务器地址 connection.autoconnect yes
2)激活新配置
nmcli con up “连接名”
关于RHEL7.2以上系统,默认网关配置:
nmcli con mod … … ipv4.gateway 默认网关地址
如果原来没有任何现成的连接:
1)先添加连接
nmcli con add con-name 连接名 ifname 网卡名 type ethernet
2)再修改连接配置
3)激活新配置
YUM的软件库源为 http://content.example.com/rhel7.0/x86_64/dvd,将此配置为您的系统的默认软件仓库。
[root@server0 ~]# yum-config-manager --add http://content.example.com/rhel7.0/x86_64/dvd
//添加指定软件源
[root@server0 ~]# vim /etc/yum.conf
gpgcheck=0 //找到此行,把原来的 1 改为 0,不检查软件签名
[root@server0 ~]# yum repolist
创建一个名为alex的用户,用户ID是 3456,密码是flectrag
[root@server0 ~]# useradd -u 3456 alex
创建下列用户、组以及和组的成员关系:
[root@server0 ~]# groupadd adminuser
[root@server0 ~]# useradd -G adminuser natasha
[root@server0 ~]# useradd -G adminuser harry
[root@server0 ~]# useradd -s /sbin/nologin sarah
[root@server0 ~]# echo flectrag | passwd --stdin sarah
[root@server0 ~]# echo flectrag | passwd --stdin harry
[root@server0 ~]# echo flectrag | passwd --stdin natasha
拷贝文件/etc/fstab到/var/tmp/fstab,配置文件/var/tmp/fstab的权限:
[root@server0 ~]# cp /etc/fstab /var/tmp/fstab
[root@server0 ~]# ls /var/tmp/fstab
/var/tmp/fstab
[root@server0 ~]# ls -l /var/tmp/fstab
-rw-r--r--. 1 root root 313 Apr 9 14:18 /var/tmp/fstab
[root@server0 ~]# setfa
setfacl setfattr
[root@server0 ~]# setfacl -m user:natasha:rw /var/tmp/fstab
[root@server0 ~]# ls -l /var/tmp/fstab
-rw-rw-r--+ 1 root root 313 Apr 9 14:18 /var/tmp/fstab
[root@server0 ~]# setfacl -m user:harry:--- /var/tmp/fstab
[root@server0 ~]# ls -l /var/tmp/fstab
-rw-rw-r--+ 1 root root 313 Apr 9 14:18 /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--
创建一个共享目录/home/admins ,特性如下:
/home/admins目录的组所有权是adminuser
adminuser组的成员对目录有读写和执行的权限。除此之外的其他所有用户没有任何权限(root用户能够访问系统中的所有文件和目录)
在/home/admins目录中创建的文件,其组所有权会自动设置为属于adminuser组
[注]此处所谓的共享目录并不是指网络共享,只是某个组成员共用
[root@server0 ~]# mkdir /home/admins
[root@server0 ~]# ls -ld /home/admins
drwxr-xr-x. 2 root root 6 Apr 9 14:24 /home/admins
[root@server0 ~]# chown :adminuser /home/admins
[root@server0 ~]# ls -ld /home/admins
drwxr-xr-x. 2 root adminuser 6 Apr 9 14:24 /home/admins
[root@server0 ~]# chmod 770 /home/admins
[root@server0 ~]# ls -ld /home/admins
drwxrwx---. 2 root adminuser 6 Apr 9 14:24 /home/admins
[root@server0 ~]# chmod g+s /home/admins
[root@server0 ~]# ls -ld /home/admins
drwxrws---. 2 root adminuser 6 Apr 9 14:24 /home/admins
[root@server0 ~]# touch /home/admins/a.txt
[root@server0 ~]# ls -l /home/admins/a.txt
-rw-r--r--. 1 root adminuser 0 Apr 9 14:27 /home/admins/a.txt
或
为用户natasha配置一个定时任务,每天在本地时间14:23时执行命令 /bin/echo hiya
[root@server0 ~]# crontab -e -u natasha
no crontab for natasha - using an empty one
crontab: installing new crontab
23 14 * * * /bin/echo hiya
从指定的地址 http://classroom.example.com/content/rhel7.0/x86_64/errata/Pa ckages/ 找到新版kernel的rpm安装文件,下载并用来升级内核,同时要满足下列要求:
[root@server0 ~]# ls /boot/vmlinuz-*
[root@server0 ~]# yum -y install http://classroom.example.com/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm
[root@server0 ~]# ls /boot/vmlinuz-*
[root@server0 ~]# uname -r
[root@server0 ~]# reboot
[root@server0 ~]# uname -r
配置您的系统,让其作为 NTP 服务器 classroom.example.com 的客户端
[root@server0 ~]# vim /etc/chrony.conf
server classroom.example.com iburst
#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
[root@server0 ~]# systemctl restart chronyd.service
[root@server0 ~]# systemctl enable 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 37 14 -1483ns[-3093us] +/- 166us
系统 classroom.example.com 提供了一个 LDAP 验证服务。您的系统需要按照以下要求绑定到这个服务上:
[root@server0 ~]# yum -y install sssd
[root@server0 ~]# authconfig-tui
[root@server0 ~]# cd /etc/openldap/cacerts
[root@server0 cacerts]# ls
[root@server0 cacerts]# wget http://classroom.example.com/pub/example-ca.crt
[root@server0 cacerts]# ls
example-ca.crt
[root@server0 ~]# systemctl restart sssd
[root@server0 ~]# id ldapuser0
uid=1700(ldapuser0) gid=1700(ldapuser0) groups=1700(ldapuser0)
[root@server0 ~]# ssh ldapuser0@server0
The authenticity of host 'server0 (172.25.0.11)' can't be established.
ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server0,172.25.0.11' (ECDSA) to the list of known hosts.
ldapuser0@server0's password:
Could not chdir to home directory /home/guests/ldapuser0: No such file or directory
mkdir: cannot create directory ‘/home/guests’: Permission denied
-bash-4.2$
-bash-4.2$
-bash-4.2$ exit
logout
Connection to server0 closed.
[root@server0 ~]# su - ldapuser0 //没有家目录
Last login: Thu Apr 9 15:33:59 CST 2020 from server0.example.com on pts/2
su: warning: cannot change directory to /home/guests/ldapuser0: No such file or directory
mkdir: cannot create directory '/home/guests': Permission denied
按照下述要求配置 autofs 用来自动挂载 LDAP 用户的主目录:
[root@server0 ~]# yum -y install autofs
[root@server0 ~]# vim /etc/auto.master
/home/guests /etc/guests.rule
[root@server0 ~]# vim /etc/guests.rule
ldapuser0 -rw classroom.example.com:/home/guests/ldapuser0
[root@server0 ~]# systemctl start autofs
[root@server0 ~]# systemctl enable autofs
[root@server0 ~]# ls -ld /home/guests/ldapuser0/
drwx------. 5 ldapuser0 ldapuser0 4096 Apr 9 16:12 /home/guests/ldapuser0/
[root@server0 ~]# su - ldapuser0
Last login: Thu Apr 9 16:12:26 CST 2020 on pts/0
[ldapuser0@server0 ~]$ pwd
/home/guests/ldapuser0
找出所有用户student拥有的文件,并且把它们拷贝到/root/findfiles 目录中
[root@server0 ~]# find / -user student -type f -exec cp -p {} /root/findfiles/ \;
[root@server0 ~]# ls -al /root/findfiles
在文件/usr/share/dict/words中查找到所有包含字符串seismic的行:
[root@server0 ~]# grep seismic /usr/share/dict/words > /root/wordlist
创建一个名为/root/backup.tar.bz2的归档文件,其中包含/usr/local目录中的内容,tar归档必须使用bzip2进行压缩
[root@server0 ~]# tar -jPcf /root/backup.tar.bz2 /usr/local
[root@server0 ~]# ls
[root@server0 ~]# file backup.tar.bz2
backup.tar.bz2: bzip2 compressed data, block size = 900k
注(1):考试环境直接操作磁盘/dev/vda(包含 Linux 系统),使用剩余空间完成考题要求
注(2):练习环境需要自行处理/dev/vdb,模拟成“已使用部分空间+剩余空间”的磁盘练习环境
[root@server0 ~]# fdisk /dev/vdb
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): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +200M
Partition 1 of type Linux and of size 200 MiB is set
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): 2
First sector (411648-20971519, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +2000M
Partition 2 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (4507648-20971519, default 4507648):
Using default value 4507648
Last sector, +sectors or +size{K,M,G} (4507648-20971519, default 20971519): +1000M
Partition 3 of type Linux and of size 1000 MiB is set
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: 0x4405d8b2
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 83 Linux
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
Command (m for help): w
[root@server0 ~]# partprobe /dev/vdb
[root@server0 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 10G 0 disk
└─vda1 252:1 0 10G 0 part /
vdb 252:16 0 10G 0 disk
├─vdb1 252:17 0 200M 0 part
├─vdb2 252:18 0 2G 0 part
└─vdb3 252:19 0 1000M 0 part
[root@server0 ~]# vgcreate systemvg /dev/vdb1
Physical volume "/dev/vdb1" successfully created
Volume group "systemvg" successfully created
[root@server0 ~]# lvcreate -n vo -L 180M systemvg
Logical volume "vo" created
[root@server0 ~]# lvscan
ACTIVE '/dev/systemvg/vo' [180.00 MiB] inherit
[root@server0 ~]# mkfs.ext3 /dev/systemvg/vo
[root@server0 ~]# fdisk /dev/vdb
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 (6555648-20971519, default 6555648):
Using default value 6555648
Last sector, +sectors or +size{K,M,G} (6555648-20971519, default 20971519):
Using default value 20971519
Partition 4 of type Extended and of size 6.9 GiB is set
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (6557696-20971519, default 6557696):
Using default value 6557696
Last sector, +sectors or +size{K,M,G} (6557696-20971519, default 20971519): +500M
Partition 5 of type Linux and of size 500 MiB is set
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (7583744-20971519, default 7583744):
Using default value 7583744
Last sector, +sectors or +size{K,M,G} (7583744-20971519, default 20971519): +2000M
Partition 6 of type Linux and of size 2 GiB is set
Command (m for help): n
All primary partitions are in use
Adding logical partition 7
First sector (11681792-20971519, default 11681792):
Using default value 11681792
Last sector, +sectors or +size{K,M,G} (11681792-20971519, default 20971519): +512M
Partition 7 of type Linux and of size 512 MiB is set
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: 0x4405d8b2
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 83 Linux
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
/dev/vdb4 6555648 20971519 7207936 5 Extended
/dev/vdb5 6557696 7581695 512000 83 Linux
/dev/vdb6 7583744 11679743 2048000 83 Linux
/dev/vdb7 11681792 12730367 524288 83 Linux
Command (m for help): w
[root@server0 ~]# partprobe /dev/vdb
[root@server0 ~]# reboot //重启一次确保所有新分区表生效
[root@server0 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 10G 0 disk
└─vda1 252:1 0 10G 0 part /
vdb 252:16 0 10G 0 disk
├─vdb1 252:17 0 200M 0 part
│ └─systemvg-vo 253:0 0 180M 0 lvm
├─vdb2 252:18 0 2G 0 part
├─vdb3 252:19 0 1000M 0 part
├─vdb4 252:20 0 1K 0 part
├─vdb5 252:21 0 500M 0 part
├─vdb6 252:22 0 2G 0 part
└─vdb7 252:23 0 512M 0 part
根据下面的要求创建一个新的逻辑卷:
逻辑卷命名为database,属于datastore卷组,并且逻辑卷的大小为50个物理扩展单元 (physical extent)
在datastore卷组中的逻辑卷,物理扩展单元 (physical extent) 大小应为 16 MiB
使用ext3文件系统对新的逻辑卷进行格式化,此逻辑卷应该在系统启动的时候自动挂载在 /mnt/database 目录下
[root@server0 ~]# vgcreate -s 16MiB datastore /dev/vdb6
Physical volume "/dev/vdb6" successfully created
Volume group "datastore" successfully created
[root@server0 ~]# lvcreate -l 50 -n database datastore
Logical volume "database" created
[root@server0 ~]# mkfs.ext3 /dev/datastore/database
[root@server0 ~]# mkdir /mnt/database
[root@server0 ~]# vim /etc/fstab
/dev/datastore/database /mnt/database ext3 defaults 0 0
[root@server0 ~]# mount -a
[root@server0 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 xfs 10G 3.3G 6.8G 33% /
devtmpfs devtmpfs 478M 0 478M 0% /dev
tmpfs tmpfs 498M 80K 497M 1% /dev/shm
tmpfs tmpfs 498M 14M 484M 3% /run
tmpfs tmpfs 498M 0 498M 0% /sys/fs/cgroup
/dev/mapper/datastore-database ext3 772M 828K 715M 1% /mnt/database
自行建立一个200MiB的逻辑卷 /dev/systemvg/vo,格式化为ext3文件系统并挂载到 /vo 。然后将逻辑卷vo和其文件系统大小调整到 300 MiB。要确保文件系统中的内容保持完整。请注意:分区大小很少能够完全符合要求的大小,所以大小在 270 MiB 和 330 MiB 之间都是可以接受的。
[root@server0 ~]# lvscan
ACTIVE '/dev/systemvg/vo' [180.00 MiB] inherit
ACTIVE '/dev/datastore/database' [800.00 MiB] inherit
[root@server0 ~]# vgextend systemvg /dev/vdb5
[root@server0 ~]# lvextend -L 300MiB /dev/systemvg/vo
[root@server0 ~]# resize2fs /dev/systemvg/vo
[root@server0 ~]# lvscan
ACTIVE '/dev/systemvg/vo' [300.00 MiB] inherit
ACTIVE '/dev/datastore/database' [800.00 MiB] inherit
在您的系统中添加一个大小为 512 MiB 的swap分区:
当您的系统启动时,swap 分区应该可以自动挂载
不要移除或者修改其他已经存在于您的系统中的 swap 分区
[root@server0 ~]# vim /etc/fstab
/dev/vdb7 swap swap defaults 0 0
[root@server0 ~]# swapon -a
[root@server0 ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb7 partition 524284 0 -1