网络配置:

您的机器是domain10.example.com域的一个成员.

domain10.example.com域内所有系统在 172.24.10.0/255.255.255.0 子网内,并且所有在这个子网内的系统都属于 domain1.example.com 域

虚拟机system1的网络配置应该如下

主机名: system1.domain10.example.com

地址: 172.24.10.151

子网掩码: 255.255.255.0

网关: 172.24.10.254

名称服务: 172.24.10.250

system1虚拟机的 root 密码 redhat

虚拟机system2的网络配置应该如下

主机名: system2.domain10.example.com

地址: 172.24.10.152

子网掩码: 255.255.255.0

网关:172.24.10.254

名称服务: 172.24.10.250

system2虚拟机的 root 密码需要重置为:glshxwyz


system1配置网络

nmcli con add con-name static ifname eth0 type ethernet ipv4.address 172.24.10.151/24 ipv4.gateway 172.24.10.254 ipv4.dns 172.24.10.250 ipv4.method man

nmcli con add:使用 NetworkManager 命令行工具添加新的网络连接配置。

con-name static:指定新连接的名称为 "static"。

ifname eth0:将此连接与 "eth0" 接口关联。

type ethernet:指定连接类型为以太网。

ipv4.address 172.24.10.151/24:设置连接的 IPv4 地址为 "172.24.10.151",子网掩码为 "/24"。

ipv4.gateway 172.24.10.254:设置连接的 IPv4 网关为 "172.24.10.254"。

ipv4.dns 172.24.10.250:设置连接的 IPv4 DNS 服务器为 "172.24.10.250"。

ipv4.method man:将连接的 IPv4 配置方法设置为手动配置。

nmcli con up static

nmcli con up:使用 NetworkManager 命令行工具启用指定的网络连接。

static:要启用的连接的名称为 "static"。

验证:

ip a 
ip route show
cat /etc/resolv.conf


1.配置默认仓库 - system1

RHCSA9-练习_rhcsa


[root@system1 ~]# cat /etc/yum.repos.d/system1.repo 
[BaseOS]
name=BaseOS
baseurl=http://repo.domain10.example.com/rhce9/rhel9-baseos/BaseOS
gpgcheck=0

[AppStream]
name=AppStream
baseurl=http://repo.domain10.example.com/rhce9/rhel9-baseos/AppStream
gpgcheck=0


验证: 安装yum -y install vim


2.调试SELinux - system1

RHCSA9-练习_rhcsa_02


setenforce 1

setenforce:设置 SELinux 的执行模式。临时修改

1:将 SELinux 设置为强制执行模式。

sed -i "s/SELINUX=permissive/SELINUX=enforcing/" /etc/selinux/config

用于启用 SELinux 并将其设置为强制执行模式。永久生效

yum provides */semanage

//查询senamage命令属于哪个软件包

yum -y install policycoreutils-python-utils 
semanage port -a -t http_port_t -p tcp 82

semanage port:管理 SELinux 端口的命令。

-a:添加新的端口定义。

-t http_port_t:将端口类型设置为 http_port_t,表示这是一个 HTTP 端口。

-p tcp:指定端口协议为 TCP。

82:要添加的端口号。

这个命令用于在 SELinux 中添加一个新的 HTTP 端口(82)定义。

semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"

semanage fcontext:管理 SELinux 文件上下文的命令。

-a:添加新的上下文定义。

-t httpd_sys_content_t:将文件上下文类型设置为 httpd_sys_content_t,表示这是一个 Apache HTTP 服务器内容目录。

"/var/www/html(/.*)?":要添加上下文定义的文件或目录路径。

这个命令用于为 /var/www/html 目录及其子目录添加一个新的 SELinux 文件上下文定义。

restorecon -RvF /var/www/html

restorecon:还原指定文件或目录的 SELinux 上下文。

-R:递归地还原指定目录下的所有文件和子目录。

-v:显示详细的还原操作信息。

-F:强制还原操作。

这个命令用于递归地还原 /var/www/html 目录及其子目录的 SELinux 上下文。

systemctl restart httpd 
systemctl enable httpd 
firewall-cmd --add-port=82/tcp

firewall-cmd:管理防火墙规则的命令。

--add-port=82/tcp:添加一个新的 TCP 端口规则,端口号为 82。

这个命令用于向防火墙添加一个新的允许通过的 TCP 端口规则(82)

firewall-cmd --runtime-to-permanent

--runtime-to-permanent:将当前运行时的防火墙规则永久保存到配置文件中。

这个命令用于将当前运行时的防火墙规则保存到配置文件中,以便下次系统启动时生效。

验证:外部访问http://172.24.10.151:82


3.配置用户账户 - system1

RHCSA9-练习_rhcsa_03


useradd -u 3388 user2 
echo 123 | passwd --stdin user2


检查:

cat /etc/passwd | grep user


4.创建用户账户 - system1

RHCSA9-练习_rhcsa_04


groupadd sysmgrs 
useradd natasha -G sysmgrs 
useradd harry -G sysmgrs 
useradd sarah -s /sbin/nologin 
echo 123 | passwd --stdin natasha 
echo 123 | passwd --stdin harry 
echo 123 | passwd --stdin sarah


验证登录用户


5.配置cron - system1

RHCSA9-练习_rhcsa_05


crontab -u natasha -e 
*/5 * * * * logger "EX200 in progress" 
23 14 * * * /bin/echo "enjia"


检查:

crontab -u natasha -l


6.配置/var/tmp/fatab权限 - system1

RHCSA9-练习_rhcsa_06



cp /etc/fstab /var/tmp/fstab 
setfacl -m u:natasha:rw /var/tmp/fstab 
setfacl -m u:harry:--- /var/tmp/fstab


检查

7.创建协作目录 - system1

RHCSA9-练习_rhcsa_07


mkdir /home/managers 
chgrp sysmgrs /home/managers/ 
chmod g=rwx,o=--- /home/managers/ 
chmod g+s /home/managers/

验证: ll -l /home


8.配置ntp - system1

RHCSA9-练习_rhcsa_08


echo "server host.domain10.example.com iburst" >> /etc/chrony.conf 
systemctl restart chronyd


验证: chronyc >> tracking

9.配置autofs -1

RHCSA9-练习_rhcsa_09


yum -y install nfs-utils autofs 
  echo /rhel /etc/auto.user1 >> /etc/auto.master 
  cat > /etc/auto.user1 <<END 
  user1 -rw nfs.domain10.example.com:/rhel/user1 
  END 
systemctl restart autofs 
systemctl enable autofs


验证:切换用户查看mount


10.查找文件 - system1

RHCSA9-练习_rhcsa_10


mkdir /root/dfiles 
find / -user user3 -exec cp -a {} /root/dfiles \; 
#!/bin/bash 
  find /usr/ -perm /g+s -size +3M -size -5M > /root/myfiles1 
  find /usr/ -perm /u+s -size +30k -size -50k > /root/myfiles2


验证:

ll -lh $(cat /root/myfiles1)
ll -lh $(cat /root/myfiles2)


11.查找字符串 - system1


RHCSA9-练习_rhcsa_11


grep re /usr/share/rhel.xml >/root/files
#cat /usr/share/rhel.xml | grep re > /root/files

验证:

cat /root/files


12.创建存档 - system1

RHCSA9-练习_rhcsa_12



yum -y install tar bzip2  
tar -zcvf books.tar.gz /usr/local/ 
tar -jcvf books.tar.bz2 /usr/local/

验证:

[root@system1 ~]# md5sum books.tar.bz2 
37dc9e9fcb150ceb6761f257fe6d8901 books.tar.bz2
[root@system1 ~]# md5sum books.tar.gz
ee098fbc74db9bf931b0691664c6742e books.tar.gz


13.执行程序 - system1

RHCSA9-练习_rhcsa_13


which rhcsa
[root@system1 ~]# cat /usr/bin/rhcsa 
  #!/bin/bash
  echo 'hello gls'


验证:运行程序

14.系统用户密码的有效期 - system1

RHCSA9-练习_rhcsa_14


vi /etc/login.defs

验证:

[root@system1 ~]# cat /etc/login.defs | grep ^PASS
  PASS_MAX_DAYS 25
  PASS_MIN_DAYS 0
  PASS_WARN_AGE 5


15.设置root密码,并设置网络 - system2

RHCSA9-练习_rhcsa_15


grub启动时定位到rescue选项

RHCSA9-练习_rhcsa_16


linux此行最后追加rd.break然后使用ctrl+x 进入bash

RHCSA9-练习_rhcsa_17


mount -oremount,rw /sysroot
chroot /sysroot
echo glshxwyz | passwd --stdin root
touch /.autorelabel
exit
exit

RHCSA9-练习_rhcsa_18


验证:

使用glshxwyz 密码登录


nmcli con add con-name static ifname eth0 type ethernet ipv4.address 172.24.10.152/24 ipv4.gateway 172.24.10.254 ipv4.dns 172.24.10.250 ipv4.method man
nmcli con up static

验证:

ip a 
ip route show
cat /etc/resolv.conf


16.配置默认软件仓库 - system2

RHCSA9-练习_rhcsa_19


[root@system2 ~]# cat /etc/yum.repos.d/system2.repo 
  [BaseOS]
  name=BaseOS
  baseurl=http://repo.domain10.example.com/rhce9/rhel9-baseos/BaseOS
  gpgcheck=0

  [AppStream]
  name=AppStream
  baseurl=http://repo.domain10.example.com/rhce9/rhel9-baseos/AppStream
  gpgcheck=0


验证:

安装vim 软件

yum -y install vim


17.调整逻辑卷大小 - system2

RHCSA9-练习_rhcsa_20


[root@system2 ~]# lvscan 
 ACTIVE '/dev/vg-exam/vo1' [100.00 MiB] inherit
 ACTIVE '/dev/vg-exam/vo2' [100.00 MiB] inherit
[root@system2 ~]# vgscan 
 Found volume group "vg-exam" using metadata type lvm2
[root@system2 ~]# pvscan 
 PV /dev/vdb1 VG vg-exam lvm2 [<2.00 GiB / 1.80 GiB free]
 Total: 1 [<2.00 GiB] / in use: 1 [<2.00 GiB] / in no VG: 0 [0 ]
[root@system2 ~]# df -hT 
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 784M 8.6M 775M 2% /run
/dev/vda2 xfs 98G 1.7G 97G 2% /
/dev/vda1 xfs 2.0G 167M 1.9G 9% /boot
/dev/mapper/vg--exam-vo1 xfs 95M 6.0M 89M 7% /vo1
/dev/mapper/vg--exam-vo2 ext4 89M 14K 82M 1% /vo2
tmpfs tmpfs 392M 0 392M 0% /run/user/0

lvextend /dev/mapper/vg--exam-vo1 -L 180M
lvextend /dev/mapper/vg--exam-vo2 -L 180M

xfs_growfs /dev/vg-exam/vo1
resize2fs /dev/vg-exam/vo2


验证:

df -hT


18.添加交换分区 - system2

RHCSA9-练习_rhcsa_21


RHCSA9-练习_rhcsa_22


验证vdb2大小:

RHCSA9-练习_rhcsa_23


fdisk /dev/vdb
	n >> p >> +567m >>w
mkswap /dev/vdb2
echo "/dev/vdb2 swap swap defaults 0 0" >> /etc/fstab
swapon -a

验证:

[root@system2 ~]# free -h
 total used free shared buff/cache available
Mem: 3.8Gi 185Mi 3.4Gi 8.0Mi 241Mi 3.4Gi
Swap: 566Mi 0B 566Mi


19.创建逻辑卷 - system2

RHCSA9-练习_rhcsa_24


fdisk/dev/vdb 
	n >> p >> +2G >>w
pvcreate /dev/vdb3 
vgcreate -s 20M npgroup /dev/vdb3 
lvcreate -l 45 -n np npgroup 
mkfs.ext3 /dev/npgroup/np 
mkdir /mnt/np 
echo"/dev/npgroup/np /mnt/np ext3 defaults 0 0" >> /etc/fstab 
mount -a

验证:

[root@system2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 784M 8.6M 775M 2% /run
/dev/vda2 98G 1.7G 97G 2% /
/dev/vda1 2.0G 167M 1.9G 9% /boot
/dev/mapper/vg--exam-vo1 175M 6.8M 168M 4% /vo1
/dev/mapper/vg--exam-vo2 165M 1.6M 154M 1% /vo2
tmpfs 392M 0 392M 0% /run/user/0
/dev/mapper/npgroup-np 869M 44K 824M 1% /mnt/np


20.配置系统调优 - system2


RHCSA9-练习_rhcsa_25


yum -y install tuned
systemctl enable tuned --now
tuned-adm recommend 
tuned-adm profile virtual-guest

验证:

tuned-adm list

RHCSA9-练习_rhcsa_26


21.配置超级用户 - system2

RHCSA9-练习_rhcsa_27


vi /etc/sudoers

RHCSA9-练习_rhcsa_28



22.创建容器以使其自启动 - system1

RHCSA9-练习_rhcsa_29



23.为容器配置持久存储 - system1

RHCSA9-练习_rhcsa_30


yum -y group install "ContainerManagement"

配置镜像仓库

vi /etc/containers/registries.conf
  [registries.search]
  registries = ['registry.domain10.example.com:50000']
  [registries.insecure]
  registries = ['registry.domain10.example.com:50000']

使用elovodo用户登录镜像仓库 密码是redhat

###

podman login registry.domain10.example.com:50000 --username gls --password glshenshuai 

podman pull rlogserver 
mkdir rlogserver 
cd rlogserver/ 
  cat > Dockerfile <<END 
  FROM registry.domain10.example.com:50000/rlogserver:latest 
  RUN echo rhcsa > /rhcsa.txt 
  CMD ["/bin/bash", "-c", "sleep infinity"] 
  END

#事实上,你考试的时候真正需要做的,就这一条,通过给定的Containerfile文件,构建一个自定义镜像

podman build -t rlogserver:rhcsa .


mkdir /tmp/testlog/
podman run --name logserver -d -v /home/elovodo/container_rlogserver/:/var/log/journal:Z -v /tmp/testlog/:/var/log/testlog:Z rlogserver:rhcsa

podman run:使用 Podman 运行容器。

--name logserver:为容器指定名称为 logserver。

-d:将容器放入后台运行。

-v /home/elovodo/container_rlogserver/:/var/log/journal:Z:将本地 /home/elovodo/container_rlogserver/ 目录挂载到容器内的 /var/log/journal 目录,并使用 SELinux 标签 Z。

-v /tmp/testlog/:/var/log/testlog:Z:将本地 /tmp/testlog/ 目录挂载到容器内的 /var/log/testlog 目录,并使用 SELinux 标签 Z。

rlogserver:rhcsa:要运行的容器镜像。

mkdir ~/.config/systemd/user -p 
cd ~/.config/systemd/user 
podman generate systemd --new --files --name logserver 
podman stop logserver 
podman rm logserver 
loginctl enable-linger 
systemctl --user daemon-reload 
systemctl --user enable container-logserver --now 
logger -p local5.info "This is an RHCSA exam"

###

#root来做

chmod +r /tmp/testlog/test.log


验证: root 用户查看文件

cat /tmp/testlog/test.log