RHCSA8.0模拟题

systemip AddressRole
servera.lab.example.com172.25.250.10需要配置的虚拟机
serverb.lab.example.com172.25.250.11需要配置的虚拟机
bastion.lab.example.com172.25.250.254开机状态即可

账户信息

  • f0主机的root密码为Asimov,f0上其他用户的密码均为redhat,fo里面所有虚拟系统的root密码是redhat,请勿更改root密码。
  • serverb的root密码未知,需要进行密码重置,要求请查看后面的题目。
  • 所有系统上已预装了SSH密钥,允许在不输入密码的前提下通过SSH进行root访问。
  • 请勿对系统上的root SSH配置文件进行任何修改。
开启虚拟机
[root@foundatione ~]# rht-vmctl start bastion
[root@foundatione ~]# rht-vmctl start servera
[root@foundation0 ~]# rht-vmctl start serverb

#保证classroom虚拟机处于开启状态
[root@foundation0 ~]# rht-vmctl start classroom
#打开虚拟机列表图形化界面
[root@foundatione ~]# virt-manager
重置虚拟机
在平时练习过程中,若遇到不可逆的操作导致虚拟机崩溃,可以使用此命令将虚拟机全部重置。
当练习结束后,需要将虚拟机重置再开始下一次的练习。

[root@foundation0~]#rht-vmctlresetall

说明:考试需要通过图形界面对虚拟机进行开机(start)、关机(poweroff)、重启(reboot)和重置(rebuilt)操作
重置虚拟机后,虚拟机所有的配置将会清空

虚拟机servera

1、配置网络地址
虚拟机servera的root密码为redhat,请为此虚拟机配置以下网络参数: hostname: servera.lab.example.comIPAddress: 172.25.250.10/24
Gateway : 172.25.250.254
Domain Name Server: 172.25.250.254

# 打开servera虚拟机图形化界面,登录进入系统#设置servera主机名
[root@localhost ~]# hostnamectl set-hostname servera.lab.example.com[root@localhost ~]# bash

#配置网络,先查看网卡配置文件,若有配置文件则修改,若没有配置文件则添加一个,一般来说网卡 会有一个默认
的配置文件
[root@localhost ~]# nmcli con show
[root@localhost~]# nmcli con modify配置文件名称 ipv4.addresses 172.25.250.10/24 ipv4.gateway172.25.250.254 ipv4.dns 172.25.250.254 ipv4.method manual autoconnect yes
[root@localhost ~]# systemctl restart NetworkManager
[root@localhost ~]# nmcli con up配置文件名
[root@localhost ~]# ip a
2、配置软件仓库
请配置你虚拟机的yum仓库,地址如下
http://content.example.com/rhel8.2/x86_64/dvd/ Baseos
http://content.example.com/rhel8.2/x86_64/dvd/AppStream

# 配置yum仓库
[root@servera ~]# vim /etc/yum.repos.d/hhr.repo
[Baseos]
name=Baseos
baseurl=http: //content.example.com/rhel8.2/x86_64/dvd/BaseoS/
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=http://content.example.com/rhel8.2/x86_64/dvd/AppStream/
enabled=1
gpgcheck=0
[root@servera ~]# yum clean all
[root@servera ~]# yum list all
3、调试SELinux配置httpd在82端口上提供web服务,满足以下要求:
1.在/var/www/ htm1/下添加index.html文件
2.此web服务器在系统启动时自动启动
3.确保SELinux保护机制运行在Enforcing模式

# 准备工作,安装httpd服务,修改监听的端口号为80
[root@servera ~]# dnf -y install httpd
[root@servera ~]# systemctl enable --now httpd
[root@servera ~]# echo "hello world" > /var/www /htm1/index.html

#修改监听的端口号
[root@servera ~]# vim /etc/httpd/conf/httpd.conf
Listen 82

#准备工作结束,以上httpd服务环境考试已经配置完成,考生只需要将82端口成功设置为服务端口即可
-----------------------------------------

#确保selinux的状态为enforcing
[root@servera ~]# vim /etc/selinux/config SELINUX=enforcing
[root@servera ~]# reboot

#重启httpd服务,服务将会重启失败,因为selinux中没有为httpd服务添加82端口[root@servera ~]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code.See "systemctl status httpd.service" and "journalctl -xe" for details.

#将对应的端口号(82端口)设置为httpd的标准端口
[root@servera ~]# semanage port -a -t http_port_t -p tcp 82

#调试防火墙
[root@servera ~]# firewall-cmd --add-port=82/tcp --permanent

#重新加载防火墙配置
[root@servera ~]# firewall-cmd --reload

#重启httpd服务,此时重启成功
[root@servera ~]# systemctl restart httpd

#查看端口号82已经监听
[root@servera ~]# ss -anitup | grep httpd

#访问测试
[root@servera ~]# curl http://172.25.250.10:82
4、创建用户账户根据下列要求创建用户及组账号:
1.名为admins的组
2.用户harry,其附属组为admins
3.用户natasha,其附属组还属于admins
4.用户alice,没有可交互的登录Shell,且不属于admins组
5. harry、natasha、alice的密码都应该是redhat

[root@servera ~]# groupadd admins
[root@servera ~]# useradd -G admins harry
[root@servera ~]# useradd -G admins natasha
[root@servera ~]# useradd -s /sbin/nologin alice
[root@servera ~]# echo "redhat” l passwd --stdin harry
[root@servera ~]# echo "redhat" l passwd --stdin natasha
[root@servera ~]# echo "redhat" l passwd --stdin alice
5、配置cron计划任务配置计划任务,以用户harry的身份每5分钟执行一次命令echo "hello world"
注意:考试时计划任务会随机指定某个时间
[root@servera ~]# which echo
/usr/bin/echo
[root@servera ~]# crontab -u harry -e */5* * * * /usr/bin/echo "hello world"
[root@servera ~]# crontab -u harry -1 */5* * * * /usr/bin/echo "hello world"
6、创建共享目录创建具有以下特点的共用目录:
1. /home/tools的所有组是admins
2.此目录能被admins组的成员读取、写入和访问,除root外其他用户没有这些权限
3.在此目录下创建的文件,其组的所有权自动设置为admins组
[root@servera ~]# mkdir /home/tools
[root@servera ~]# chown .admins /home/tools
[root@servera ~]# chmod 770 /home/tools
[root@servera ~]# chmod g+s /home/tools
[root@servera ~]# ll -d / home/tools
drwxrws---. 2 root admins 6 Jun 20 14:37 / home/tools
7、配置NTP时间客户端配置你的系统,使其成为classroom. example.com的NTP客户端
[root@servera ~]# yum -y install chrony
[root@servera ~]# vim /etc/chrony.conf
server classroom.example.com iburst
[root@servera~]# systemctl restart chronyd
[root@servera ~]# systemctl enable chronyd
[root@servera~]# chronyc sources
210 Number of sources = 1
MS Name/IP address		Stratum Poll Reach LastRx Last sample
================================================================================
^*	classroom.example.com 8		10		1 	245 	+8574ns[+21us] +/- 627us

虚拟机serverb

8、配置autofs
准备工作:在serverb主机准备NFS服务端环境,过程如下

#打开serverb虚拟机,配置nfs共享
[root@serverb ~]# mkdir -p /rhome/ldapuser00
[root@serverb ~]# vim /etc/exports
/ rhome/ldapuser0*(rw)
[root@serverb ~]# systemctl restart nfs-server
[root@serverb ~]# systemctl enable nfs-server
[root@serverb ~]# firewall-cmd --permanent --add-service=rpc-bind
[root@serverb ~]# firewall-cmd --permanent --add-service=nfs
[root@serverb ~]# firewall-cmd --permanent --add-service=mountd
[root@serverb ~]# firewall-cmd --reload

考试题目:按照以下要求,在servera上配置autofs自动挂载:
1. serverb通过NFS共享目录/rhome到你的系统,此文件系统中包含为用户ldapuser0预配置的家目录
2.预设用户ldapuser0的家目录是serverb.lab.example.com:/rhome/ldapuser0
3.预设用户ldapuser0的家目录应自动挂载到本地的/rhome/ldapuser0目录
4.挂载后的家目录必须可读写;ldapuser0用户的密码是"xxxx'

[root@servera ~]# showmount -e serverb.lab.example.com
Export list for 172.25.250.11:
/ rhome/ldapuser0*
[root@servera ~]# dnf -y install autofs
[root@servera ~]# systemctl enable autofs
[root@servera ~]# vim /etc/auto.master
/rhome /etc/auto.nfs
[root@servera ~]# vim /etc/auto.nfs
ldapusere -rw serverb.lab.example.com:/rhome /ldapusere
[root@servera ~]# systemctl restart autofs

#当前练习环境触发挂载
[root@servera ~]# cd /rhome/ 
[root@servera rhome]# cd ldapusere

#考试时触发挂载
[root@servera ~]# ssh ldapusere0@127.0.0.1输入登录密码
[root@servera ~]# df -h //查看到有题目共享的挂载测试完成后exit退回到root用户
9、配置文件权限
将文件/etc/fstab复制到/var/tmp/,并按要求配置/var/tmp/fstab的权限:
1.文件/var/tmp/fstab属于root用户
2.文件/var/tmp/fstab属于root组
3.任何用户对/var/tmp/fstab都没有可执行权限
4.用户harry能够读取和写入/var/tmp/fstab文件
5.用户natasha无法读取或写入/var/tmp/fstab文件
6.所有其他用户(包括未来创建的用户)能够读取/var/tmp/fstab文件

[root@servera ~]# cp /etc/fstab /var/tmp/
[root@servera ~]# ll /var/tmp/fstab
-rw-r--r--. 1 root root 427 Jun 20 14:47 /var/tmp/fstab
[root@servera ~]# setfacl -m u:harry:rw- /var/tmp/fstab
[root@servera ~]# setfacl -m u:natasha:--- /var/tmp/fstab
[root@servera ~]# getfacl /var/tmp/fstab
getfacl: Removing leading ' /' from absolute path names
# file: var/tmp/fstab
# owner: root
# group: root
user: : rw
user:harry : rw
user:natasha: ---
group : :r--
mask : : rw
other: : r--
10、配置用户账户创建用户hhr,其用户ID为2020,此用户的密码应当是redhat,该用户密码30天后到期
[root@servera ~]# useradd -u 2020 hhr
[root@servera ~]# echo redhat / passwd --stdin hhr
[root@servera ~]# passwd -x 30 hhr
11、查找文件
1.找出/etc/目录下大小超过5MB的文件,并将其复制到/root/findfiles目录下[root@servera~]#mkdir /root/findfiles
[root@servera~]#find /etc -size +5M -exec cp -a {} /root/findfiles/ \;

2.查找归hhr所有的文件,将副本放入/root/findfiles目录下
[root@servera~]#mkdir /root/findfiles
[root@servera~]#find /-user hhr -exec cp -a {} /root/findfiles/ \;

3.使hhr用户在系统中创建的文件默认权限:-r--r----。同一用户所有新建目录具有默认权限:dr-Xr-Xr-X。
#将-r--r--r--权限转换为8进制结果为:444
#将dr-xr-xr-x权限转换为8进制结果为:555

#文件的默认最高权限为666,用666减去当前要设置的权限444,得出要遮住的权限为222
 666
-444
 222

#目录的默认最高权限为777,用777减去当前要设置的权限555,得出要遮住的权限为222
 777
-555
 222

[root@servera ~]# su - hhr #切换到该用户
[hhr@servera ~]# vim .bashrc
umask 222 #在最后一行添加该配置
#最后exit退出该用户即可

4.建一个名为hhrfind的脚本,脚本存在于/usr/local/bin,把/usr目录下的小于10N,具有SETUID(或SETGID)权限的文件找出来。
执行结果放到/tmp/hhrfindfiles目录下(同时查找含有SETUID(4000)和SETGID(2800)权限的文件把对应的-4000换成/6000即可)
[root@servera ~]# cd /usr/local/bin
[root@servera bin]# mkdir -p /tmp/hhrfindfiles
[root@servera bin]# vim hhrfind
#!/bin/bash
find /usr/ -size -10M -perm -4000 -exec cp -a {} /tmp/hhrfindfiles \;
#将命令写入脚本时,最好将命令在命令行执行一遍确保命令无报错

[root@servera bin]# chmod +x hhrfind
[root@servera bin]# hhrfind		#执行脚本,进行测试
[root@servera bin]# ls /tmp/hhrfindfiles/		#查看有无结果
[root@servera bin]# rm -rf /tmp/hhrfindfiles/*		#题目没有要求我们运行脚本,所以清空执行脚本后产生文件

5.使得xxx用户(或组)能够获得管理员权限,并且不需要输入密码。
[root@servera ~]# visudo #visudo命令打开配置文件,选择以下内容添加至配置文件最后一行
Xxx ALL= (root) NOPASSMD:ALL #使xxx用户在任何机器上能够借助root用户所有权限,并且不需要密码当题目要求是用户是,写上面一条,当题目要求是组时,写下面一条
%xxx ALL=(root) NOPASSMD:ALL #使xxx组中所有人在任何机器上能够借助root用户所有权限,并且不需要密码

:wq! 保存退出即可
12、查找字符串
找出文件/etc/man_db.conf中包含字符串sbin的所有行,将其按原始顺序导入到文件/root/out.txt中,文件/root/out.txt中不得包含空行。
[root@servera~]#grep "sbin" /etc/man_db.conf |grep -v "^$" >/root/out.txt
13、创建归档
创建一个名为/root/backup.tar .bz2的tar归档,其应该包含/usr/local/的内容。此归档文件必须使用bzip2进行压缩
[root@servera ~]# tar -jcf /root/backup.tar.bz2 /usr/local/ #验证
[root@servera ~]# file backup.tar.bz2
backup.tar.bz2: bzip2 compressed data,block size = 900k

虚拟机serverb

14、设置root密码
将serverb的root密码设置为123456
1.重启serverb
2.将光标移动到要启动的内核
3.按e键编译当前条目
4.在linux开头的尾行添加 rd.break
5.按ctrl+x继续启动
6.重启以读写方式挂载 /sysroot
switch_root: /# mount -o remount,rw /sysroot
7.切换至真正操作系统的根 /sysroot
switch_root:/# chroot /sysroot
8.重置密码
sh-4.4# echo 123456 | passwd --stdin root
9.打标签
sh-4.4# touch /.autorelabel
10.输入两次exit退出重启
15、配置软件仓库
请配置你虚拟机的yum仓库,地址如下
http://content.example.com/rhel8.2/x86_64/dvd/Baseos
http://content.example.com/rhel8.2/x86_64/dvd/AppStream

# 配置yum仓库
[root@serverb ~]# vim /etc/yum.repos.d/hzz.repo
[BaesOS]
name=BaesOS
baseurl=http://content.example.com/rhel8.2/x86_64/dvd/Baseos/
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=http://content.example.com/rhel8.2/x86_64/dvd/AppStream/
enabled=1
gpgcheck=0
[root@serverb ~]# dnf clean all
[root@serverb ~]# dnf list all
16、调整逻辑卷大小
1.预先创建2GiB的分区/dev/vdb1,并用于创建卷组testvg
2.创建大小为200NiB的逻辑卷/dev/testvg/vo,格式化为xfs(或者ext4)文件系统,并挂载在/mnt/vo上
3.将逻辑卷/dev/testvg/vo及其文件系统大小调整到3eeMiB,确保文件系统内容保持不变

# 准备工作
[root@serverb ~]# fdisk /dev/vdb
welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only,until you decide to write them.Be caneful before using the wnite command.Device does not contain a recognized partition table.
Created a new Dos disklabel with disk identifier Oxae75bf0a.
Command (m for help): n
Partition type
p primary (e primary , 0 extended4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4default 1):
First sector (2048-10485759,default 2048):
Last sector,+sectors or +size{K,M,G,T,P}(2048-10485759,default 10485759):+2G
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
syncing disks.
[root@serverb ~]# partprobe /dev/vdb
[root@serverb ~]#pvcreate /dev/vdb1 	#创建物理卷
[root@serverb ~]# vgcreate testvg /dev/vdb1	#创建卷组并将vdb1加入到卷组
[root@serverb ~]# lvcreate -n vo -L 20OM testvg #在卷组中分出逻辑卷
[root@serverb ~]# mkfs.xfs /dev/testvg/vo	#格式化为xfs
[root@serverb ~]# blkid /dev/testvg/vo	#查看uuid
/dev/testvg/vo: UUID="fe323058-93db-428d-883c-2c0210cd1ec6" TYPE="xfs"
[root@serverb ~]# mkdir /mnt/vo
[root@serverb ~]# vim /etc/fstab
UUID="fe323058-93db-428d-883c-2c0210cd10c6"/mnt/vo xfs defaults 0 0
[root@serverb ~]# mount -a

#准备工作结束	-------------------------------------

#实际操作
[root@serverb ~]# df -hT /dev/testvg/vo #查看文件系统的类型和大小
Filesystem Type size Used Avail Use% Mounted on
/dev/mapper/testvg-vo xfs 195M 12M183M 6% /mnt/vo
[root@serverb ~]# lvextend -L 30eM /dev/testvg/vo
[root@serverb ~]# lvs
#扩展文件系统,ext类型的文件系统用resize2fs /dev/testvg/vo,后面接的是逻辑卷的路径。
[root@serverb ~]# xfs_growfs /mnt/vo 	#后面接的是挂载点的路径
[root@serverb ~]# df -hT /dev/testvg/vo
Filesystem Type size Used Avail Use% Mounted on
/dev/mapper/testvg-vo xfs 295M 13M 283M 5% /mnt/vo
17、添加交换分区
在系统上添加一个512NiB的交换分区,设置交换分区应在系统启动时自动挂载,不要删除或修改系统上已存在的交换分区
[root@serverb ~]# fdisk /dev/vdb
welcome to fdisk (util-linux 2.32.1).
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 extended3 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4default 2):
First sector ( 4196352-10485759,default 4196352):
Last sector,+sectors or +size{K,M,G,T,P}(4196352-10485759,default10485759): +512M
Created a new partition 2 of type 'Linux' and of size 512 MiB.
Command (m for help) : t
Partition number ( 1,2,default 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.
Syncing disks.
[root@serverb ~]# partprobe /dev/vdb
[root@serverb ~]# mkswap /dev/vdb2
[root@serverb ~]# blkid /dev/vdb2
/dev/vdb2: UUID="f626f11c-4363-4caf-aba6-5a418ea04079"TYPE="swap” PARTUUID="ae75bf0a-02"[root@serverb ~]# vim /etc/fstab
UUID=f626f11c-4363-4caf-aba6-5a418ea04079 swap swap defaults 0 0
[root@serverb ~]# swapon -a
[root@serverb ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb2 partition 524284 0 -2
18、创建逻辑卷
根据以下要求,创建新的逻辑卷:
1.逻辑卷的名字为my1v,属于myvg卷组,大小为50个pe
2.卷组myvg中的逻辑卷的pe大小应当为16MiB
3.使用vfat文件系统将逻辑卷mylv格式化
4.此逻辑卷应当在系统启动时自动挂载到/mnt/mydata目录下

[root@serverb ~]# fdisk /dev/vdb
welcome to fdisk (util-linux 2.32.1).
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 (2 primary, e extended,2 free)
e extended (container for logical partitions)
**Select** (default p):
Using default response p.
Partition number (3,4,default 3):
First sector (5244928-10485759default 5244928):
Last sector,+sectors or +size{K,M,G,T,P} (5244928-10485759,default10485759): +816M
Created a new partition 3 of type 'Linux' and of size 816 MiB.
Command (m for help) : t
Partition number ( i-3,default 3):
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.
syncing disks.
[root@serverb ~]# partprobe /dev/vdb
[root@serverb ~]# pvcreate /dev/vdb3
[root@serverb ~]# vgcreate -s 16M myvg /dev/vdb3
[root@serverb ~]# lvcreate -1 50 -n mylv myvg
[root@serverb ~]# mkfs.vfat /dev/myvg/my1v
[root@serverb ~]# mkdir /mnt/mydata
[root@serverb ~]# blkid /dev/myvg/mylv
UUID=""*****"
[root@serverb ~]# vim /etc/fstab
UUID="*****"/mnt/ mydata vfat defaults 0 0
[root@serverb ~]# mount -a
[root@serverb ~]# df -h /mnt/mydata/
Filesystem size Used Avail Use% Mounted on
/dev/myvg/mylv 799M 4.BK 799M 1% /mnt/mydata
19、创建VDO卷
根据如下要求,创建新的VDO卷:
1.使用未分区的磁盘(/dev/vdc)
2.此VDO卷的名称为myvdo
3.此VDo卷的逻辑大小为50G
4.此VDO卷使用xfs文件系统格式化
5.此VDo卷在系统启动时自动挂载到/vblock目录下

[root@serverb ~]# yum -y install vdo

#命令man vdo找examples
[root@serverb ~]# vdo create --name=myvdo --device=/dev/vdc --vdoLogicalsize=50G
Creating vDo myvdo
Starting vDo myvdo
Starting compression on vDo myvdo
vDo instance 0 volume is ready at /dev/mapper/myvdo
[root@serverb ~]# mkfs.xfs /dev/ mapper/myvdo
[root@serverb ~]# mkdir /vblock
[root@serverb ~]# blkid /dev/mapper/myvdo
UUID="*****”
[root@serverb ~]# vim /etc/fstab
UUID=""*****"/vblock xfs defaults,x-systemd.requires=vdo.service 0 0
[root@serverb ~]# mount -a
[root@serverb ~]# df -h /vblock
Filesystem size Used Avail Use% Mounted on
/dev/mapper/myvdo 5eG 390M 50G1% /vblock
注意:/etc/fstab中的挂载参数可以在man帮助中搜索到,使用man vdo命令查看vdo的帮助文档,搜索fstab可以找到挂载参数

如果说创建vdo卷时发现大小不对时,不知如何删除请按照以下方法进行删除
[root@serverb ~]# vdo remove --name myvdo(这里为你创建的vdo卷的名字)
Removing vDo myvdo
stopping vDo myvdo
[root@serverb ~]#lsblk #查看是否删除成功,可以看到磁盘变回没有创建时的状态(随后即可正常继续操作)
20、配置系统调优为您的系统选择建议的tuned配置集并将它设为默认设置。
注意:考试默认的tuned模式为thronghput-performance
[root@serverb ~]# tuned-adm list #列出系统中所有调优方案Available profiles:
- balanced - General non-specialized tuned profile
- desktop - optimize for the desktop use-case
- latency-performance - 0ptimize for deterministic performance at thecost ofincreased power consumption
- network-latency - Optimize for deterministic performance at thecost ofincreased power consumption,focused on low latency network performance- network-throughput - Optimize for streaming network throughput,generallyonly necessary on older CPUs or 40G+ networks
- powersave - Optimize for low power consumption
- throughput-performance - Broadly applicable tuning that providesexcellentperformance across a variety of common server workloads
- virtual-guest - optimize for running inside a virtual guest
- virtual-host - Optimize for running KVM guestsCurrent active profile:virtual-guest
- 
[root@serverb ~]# tuned-adm recommend #查看系统推荐方案
virtual-guest
[root@serverb ~]# tuned-adm profile virtual-guest #将系统调优方案调整为推荐方案[root@serverb ~]# tuned-adm active #查看系统调优方案是否调整为推荐方案
current active profile: virtual-guest

容器podman

containers用户的密码为redhat。在registry.lab . example.com上使用admin账户和redhat321密码访问容器镜
像注册表。
您可以从serverb上的/home/containers/rhcsa-compreview4/variables文件复制并粘贴web容器参数。

准备工作
#开启workstation和utility虚拟机
[root@foundation0 ~]# rht-vmctl start workstation 
[root@foundation0 ~]# rht-vmctl start utility

#使用student用户登录workstation
[root@foundatione ~]# ssh -x workstation

#运行脚本部署,考试不需要操作
[student@workstation ~]$ lab rhcsa-compreview4 start

在serverb上,创建/srv/web/目录,然后在该目录中提取/home/containers/rhcsa-compreview4/web-content.tgz存档。配置该目录,使rootless容器可以将其用于持久存储。
#远程登录到serverb
[root@foundatione~]#ssh root@serverb

#创建/srv/web/目录
[root@serverb~]#mkdir /srv/web

#在/srv/web/目录中提取/home/containers/rhcsa-compreview4/web-content.tgz存档
[root@serverb~]#cd /srv/web/
[root@serverbweb]#tar -xf /home/containers/rhcsa-compreview4/web-content.tgz
#Rootless容器需要拥有对/srv/web/目录及其内容的读取访问权限。
此外,以containers用户身份运行的podman命令必须能够重新标记SELinux的目录。将目录所有者设置为containers,然后确认每个人都有权访问该内容
[root@serverbweb]#chown -R containers /srv/web

在serverb上,安装容器工具。
#安装container-tools模块
[root@serverb web]# dnf -y module install container-tools

#从root账户注销
[root@serverb web]# exit

在serverb上,以containers⽤户身份,创建名为web的Apache HTTP Server分离容器,使用registry.lab.example.com注册表中标签为1-105的rhel8/httpd-24镜像。将容器中的端⼝8080映射到主机上的端⼝8888。将主机上的/srv/web⽬录作为/var/www挂载到容器中。使⽤event声明环境变量HTTPD_MPM。

#在registory.lab.example.com上使⽤admin账户和redhat321密码登录容器镜像注册表。
#在workstation虚拟机中用student使用containers连接到serverb
[root@foundatione ~]# ssh containers@serverb
[containers@serverb ~]$ cat rhcsa-compreview4/variables [containers@serverb ~]$ podman login registry.lab.example.com
Username: admin
Password: redhat321
Login Succeeded!

#拉取镜像到本地
[containers@serverb ~]$ podman pull rhel8/httpd-24:1-105

#使用podman run命令创建容器。
[containers@serverb ~]$ podman run -d --name web -p 8888:8080 -v /srv/web:/var/www:Z -e  HTTPD_MPM=eventregistry.lab.example.com/rhel8/httpd-24:1-105

#使用curl命令确认Apache HTTP Server正在运行
[containers@serverb ~]$ curl http://localhost:8888/

在serverb上,以containers用户身份配置systemd,以便web容器在服务器启动时自动启动。
#创建~/ .config/systemd/user/目录
[containers@serverb -]$ mkdir -p ~/.config/systemd/user/

#使用podman generate systemd命令,从正在运行的容器中创建systemd单元文件
[containers@serverb ~]$ cd ~/.config/systemd/user/
[containers@serverb user]$ podman generate systemd --files --name web --new/home/containers/.config/systemd/user/container-web.service

#停止然后册除web容器
[containers@serverb user]$ podman stop web
[containers@serverb user]$ podman rm web

#指示systemd重新加载其配置,然后启用并启动container-web服务
[containers@serverb user]$ systemctl--user daemon-reload
[containers@serverb user]$ systemctl --user enable --now container-web.service

#确定容器正在运行
[containers@serverb user]$cur1 http: //loca1host:8888/
Comprehensive Review web Content Test
Lorem ipsum dolor sit amet,consectetur adipiscing elit.
sed sit amet lacus vestibulum,varius magna sit amet , tempus neque. ...output omitted. . .

#运行loginctl enable-linger命令,使用户服务在服务器启动时自动启动
[containers@serverb-]$ loginctl enable-linger containers

#从serverb退出
[containers@serverb~]$ exit---------------------------------------------
#以下命令考试不需要做
#容器题目做完后在workstation计算机上以student用户身份,使用命令为工作评级
[root@foundation0~]# ssh student@workstation
[student@workstation ~]$ lab rhcsa-compreview4 grade	#工作评级
[student@workstation ~]$ lab rhcsa-compreview4 finish	#结束容器实验
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值