Linux EX200-RHCSA考题『上篇』
文章目录
- 在 node1.domain250.example.com 上执行以下任务(RH124)
- 1. 配置网络设置 : c12
- 2. 配置您的系统以使用默认存储库 : c14
- 3. 调试 SELinux : RH134-c5-c11
- 4. 创建用户帐户 : c6
- 5.A 配置 cron 作业 : RH134-c2
- 5.B 配置 cron 作业 : RH134-c2
- 6. 创建协作目录 : c7
- 7. 配置 NTP : c11
- 8. 配置 autofs : RH134-C9
- 9. 配置 /var/tmp/fstab 权限 : c7,RH134-c4
- 10. 配置用户帐户 : c6
- 11. 查找文件 : c15
- 12. 查找字符串 : c2,RH134-c1
- 13. 创建存档 : c13
- 14. 配置容器使其自动启动(A卷): RH134-c13
- 15. 为容器配置持久存储(A卷): c11,RH134-c13
- 16. 配置容器使其自动启动(B卷): RH134-c13
- 17. 容器nginx(附加题): RH134-c13
- 18. 添加sudo免密操作(附加题)- c10
- 19. 配置创建新用户的密码策略(附加题): c6
- 20. 创建脚本(附加题)(A卷): RH134-c1
- 21. 创建脚本(附加题)(B卷): RH134-c1
- 22. 设置默认权限(附加题)
- 23. 配置一个应用(附加题): RH134-c1
重要配置信息
在练习期间,除了您就坐位置的台式机之外,还将使用多个虚拟系统。您不具有台式机系统的根访问权,但具有对虚拟系统的完全根访问权。
系统信息
系统 | IP 地址 |
---|---|
node1.domain250.example.com | 172.25.250.100 |
node2.domain250.example.com | 172.25.250.200 |
您使用的系统属于 DNS 域 domain250.example.com
。该域中的所有系统都位于 172.25.250.0/255.255.255.0
子网中,该子网中的所有系统都位于 domain250.example.com
中。
针对这些系统列出的 IP 地址是应该分配给系统的地址。您可能需要为一个或两个系统配置网络,以便能够通过上述地址访问您的地址。
帐户信息
node1 的 root 密码已经设置为 flectrag
。
除非另有指定,否则这将是用于访问其他系统和服务的密码。此外,除非另有指定,否则应将该密码用于您创建的什么问题帐户或者需要设置密码的任意服务。
其他信息
您可以通过 SSH 或控制台访问练习系统(参见下文所述)。请注意,SSH 访问权可能取决于您解答其他练习项目的情况。
如果您需要在系统上安装其他软件,可以使用位于以下地址的存储库:
-
http://foundation0.ilt.example.com/dvd/BaseOS
-
http://foundation0.ilt.example.com/dvd/AppStream
注册服务器信息
注册服务器地址registry.domain250.example.com
使用 admin
作为用户名,使用 redhat321
作为映像注册表的凭据
重要评测信息
您的系统会在重新引导后进行评测,因此务必确保您实施的的所有配置和服务在重新引导后仍然保留。服务必须在没有人工干预的情况下启动。
同样,本次练习使用的所有虚拟实例都必须 能够重新引导至适当的多用户目标,而无需任何人工辅助。在无法引导或无法进行无人干预引导的系统上完成的所有操作都将为零分。
练习要求
在您的系统上执行以下所有步骤。
文章目录
- 在 node1.domain250.example.com 上执行以下任务(RH124)
- 1. 配置网络设置 : c12
- 2. 配置您的系统以使用默认存储库 : c14
- 3. 调试 SELinux : RH134-c5-c11
- 4. 创建用户帐户 : c6
- 5.A 配置 cron 作业 : RH134-c2
- 5.B 配置 cron 作业 : RH134-c2
- 6. 创建协作目录 : c7
- 7. 配置 NTP : c11
- 8. 配置 autofs : RH134-C9
- 9. 配置 /var/tmp/fstab 权限 : c7,RH134-c4
- 10. 配置用户帐户 : c6
- 11. 查找文件 : c15
- 12. 查找字符串 : c2,RH134-c1
- 13. 创建存档 : c13
- 14. 配置容器使其自动启动(A卷): RH134-c13
- 15. 为容器配置持久存储(A卷): c11,RH134-c13
- 16. 配置容器使其自动启动(B卷): RH134-c13
- 17. 容器nginx(附加题): RH134-c13
- 18. 添加sudo免密操作(附加题)- c10
- 19. 配置创建新用户的密码策略(附加题): c6
- 20. 创建脚本(附加题)(A卷): RH134-c1
- 21. 创建脚本(附加题)(B卷): RH134-c1
- 22. 设置默认权限(附加题)
- 23. 配置一个应用(附加题): RH134-c1
在 node1.domain250.example.com 上执行以下任务(RH124)
1. 配置网络设置 : c12
将 node1 配置为具有以下网络配置:
- 主机名:
node1.domain250.example.com
- IP 地址:
172.25.250.100
- 子网掩码:
255.255.255.0
- 网关:
172.25.250.254
- DNS服务器:
172.25.250.254
Hint - 提示
- 默认有生效的动态IP地址。配置完后,需要 nmcli up 生效
- search domains 保持默认,不需修改
VM Control / `node1` / OK / `Console_node1_VM` / OK
clear login: root
Password: flectrag
[node1]
方法一
# nmtui
`Edit a connection` / `Wired connection 1` /
IPv4 CONFIGURATION `<Manual>` `<Show>`
Addresses `172.25.250.100/24`
Gateway `172.25.250.254`
DNS servers `172.25.250.254`
<OK> / <Back> / `<Quit>`
# nmcli con up 'Wired connection 1'
确认IP、掩码
# ip a s
...输出省略...
inet `172.25.250.100/24` brd 172.25.250.255 scope global noprefixroute eth0
方法二
# nmcli con show
# man nmcli | grep -A 1 nmcli.*mod
-方法1,便于阅读
# nmcli con mod 'Wired connection 1' \
ipv4.method manual \
ipv4.addresses 172.25.250.100/24 \
ipv4.gateway 172.25.250.254 \
ipv4.dns 172.25.250.254
-方法2,实际操作
# nmcli con mod 'Wired connection 1' ipv4.method manual ipv4.addresses 172.25.250.100/24 ipv4.gateway 172.25.250.254 ipv4.dns 172.25.250.254
# nmcli con up 'Wired connection 1'
# ip a s
inet 172.25.250.100/24 brd 172.25.250.255 scope global noprefixroute eth0
[foundation]
$ ssh root@node1
root@node1\'s password: `flectrag`
[node1]
# hostnamectl set-hostname node1.domain250.example.com
确认主机名
# hostname
`node1.domain250.example.com`
# cat /etc/hostname
node1.domain250.example.com
确认网关
# ip route
default via `172.25.250.254` dev eth0 proto static metric 100
172.25.250.0/24 dev eth0 proto kernel scope link src 172.25.250.100 metric 100
确认DNS
# cat /etc/resolv.conf
# Generated by NetworkManager
search domain250.example.com
nameserver `172.25.250.254`
2. 配置您的系统以使用默认存储库 : c14
配置您 的系统以使用默认存储库
- YUM 存储库已可以从
http://foundation0.ilt.example.com/dvd/BaseOS
和http://foundation0.ilt.example.com/dvd/AppStream
使用配置您的系统,以将这些位置用作默认存储库
Hint - 提示
- foundation 浏览器中查找 yum-utils 包, dnf是yum的一个分支
- add-repo 添多了,删除 /etc/yum.repos.d 目录下相关文件
**[foundation]**
$ yum provides yum-config-manager
...
`dnf-utils`-4.0.2.2-3.el8.noarch : Yum-utils CLI compatibility layer
...
浏览器中`http://foundation0.ilt.example.com/dvd/BaseOS`,
`Packages`中
<Ctrl-F>搜索`dnf-utils`找不到
<Ctrl-F>搜索`yum-utils`找得到
鼠标右键`Copy link location`
[node1]
-安装yum-config-manager安装包
# yum -y install http://foundation0.ilt.example.com/dvd/BaseOS/Packages/yum-utils-4.0.12-3.el8.noarch.rpm
# yum-config-manager -h | grep repo
-添加仓库1/BaseOS
*# yum-config-manager --add-repo http://foundation0.ilt.example.com/dvd/BaseOS
Adding repo from: http://foundation0.ilt.example.com/dvd/BaseOS
-添加仓库1/AppStream
*# yum-config-manager --add-repo http://foundation0.ilt.example.com/dvd/AppStream
Adding repo from: http://foundation0.ilt.example.com/dvd/AppStream
# find / -name *KEY*
/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta
/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
/usr/share/doc/gnupg2/KEYSERVER
-导入公钥
*# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
# yum -y remove yum-utils
# yum -y install yum-utils
# yum -y install ftp
3. 调试 SELinux : RH134-c5-c11
调试 SELinux 非标准端口
82
上运行的 Web 服务器在提供内容时遇到问题。根据需要调试并解决问题,使其满足以下条件:
- 系统上的 Web 服务器能够提供
/var/www/html
中所有现有的 HTML 文件(注:不要删除或以其他方式改动现有的文件内容) - Web 服务器在端口
82
上提供此内容 - Web 服务器在系统启动时
自动启动
Hint - 提示
- 服务无法启动,查日志改端口
- file1 无法访问;类型查看 /var/www/html
**[node1]**
Port/方法一、
# systemctl list-uint-files | grep http
# systemctl status httpd
...(13)Permission denied: H00072: make_sock: could not bind to address [::]:`82`
# systemctl restart httpd
# sleep 2
# grep -n 82 /var/log/messages
...
***** Plugin bind_ports (99.5 confidence) suggests ************************
If you want to allow httpd to bind to network port 82
Then you need to modify the port type.
`semanage port -a -t PORT_TYPE -p tcp 82`
where PORT_TYPE is one of the following: `http_cache_port_t`, `http_port_t`, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t.
# man semanage port
`/-a` add, `/-l` list
/-t type
/-p protocol
# grep -w ^http /etc/services
http `80`/tcp www www-http # WorldWideWeb HTTP
...
# semanage port -l | grep -w 80
`http_port_t` tcp 82, 80, 81, 443, 488, 8008, 8009, 8443, 9000
# semanage port -a -t http_port_t -p tcp 82
# systemctl restart httpd
# systemctl status httpd
# systemctl enable httpd
port/方法二、
# man semanage port | grep \#
# grep -w http /etc/services
# semanage port -l | grep -w 80
# semanage port -a -t http_port_t -p tcp 82
# semanage port -l | grep -w 82
# systemctl enable --now httpd
fcontext
# ll /var/www/html/ -Z
-rw-r--r--. 1 root root system_u:object_r:etc_t:s0 14 Mar 24 08:12 file1
-rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 14 Mar 24 08:12 file2
-rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 14 Mar 24 08:12 file3
# man semanage fcontext | grep \#
# semanage fcontext -a -t httpd_sys_content_t "/var/www/html/file1"
ValueError: File context for /var/www/html/file1 already defined
# semanage fcontext -l | grep file1
/var/www/html/file1 all files system_u:object_r:etc_t:s0
方法1,修改
# semanage fcontext -m -t httpd_sys_content_t "/var/www/html/file1"
方法2,删除
# semanage fcontext -d -t default_t /var/www/html/file1
# restorecon -v /var/www/html/file1
Relabeled /var/www/html/file1 from system_u:object_r:etc_t:s0 to system_u:object_r:httpd_sys_content_t:s0
# for i in {1..3}; do
curl http://localhost:82/file$i
done
4. 创建用户帐户 : c6
创建用户帐户 创建下列用户、组和组成员资格:
- 名为
sysmgrs
的组 - 用户
natasha
,作为次要组从属于sysmgrs
- 用户
harry
,作为次要组还从属于sysmgrs
- 用户
sarah
,无权访问系统上的交互式 shell
且不是sysmgrs
的成员 -
natasha
、harry
和sarah
的密码应当都是flectrag
Hint - 提示
- 非交互式的 shell 可以是 /bin/false 或 /sbin/nologin
[node1]
# groupadd sysmgrs
# useradd -G sysmgrs natasha
# useradd -G sysmgrs harry
# cat /etc/passwd
# useradd -s /sbin/nologin sarah
# for i in natasha harry sarah; do
echo flectrag | passwd --stdin $i
done
# ssh natasha@localhost id
# ssh harry@localhost id
# ssh sarah@localhost id
# grep sarah /etc/passwd
5.A 配置 cron 作业 : RH134-c2
配置 cron 作业 配置
cron
作业,该作业每隔 2 分钟
运行并执行以下命令:
-
logger "EX200 in progress"
,以用户natasha
身份运行
Hint - 提示
- crontab 命令,或 /etc/crontab 文件两种方法皆可
- 强烈建议使用命令这种做法
**[node1]**
- 判断服务启动,并且是开机自启
# systemctl status crond
- 查看帮助
# man -k crontab
# man 5 crontab
- 配置作业
*# crontab -e -u natasha
*/2 * * * * logger "EX200 in progress"
- 确认
# crontab -l -u natasha
*/2 * * * * logger "EX200 in progress"
# sleep 4m
# grep EX200 /var/log/messages
Mar 24 09:32:01 node1 natasha[25113]: EX200 in progress
Mar 24 09:34:01 node1 natasha[25113]: EX200 in progress
5.B 配置 cron 作业 : RH134-c2
配置 cron 作业 配置
cron
作业,以用户harry
身份每天14:23
分执行/usr/bin/echo hello
Hint - 提示
- crontab 命令,或 /etc/crontab 文件两种方法皆可
- 强烈建议使用命令这种做法
**[node1]**
- 判断服务启动,并且是开机自启
# systemctl status crond
- 查看帮助
# man -k crontab
# man 5 crontab
- 配置作业
*# crontab -e -u harry
23 14 * * * /usr/bin/echo hello
- 确认
# crontab -l -u harry
23 14 * * * /usr/bin/echo hello
一般情况 RHCSA 上午考试,等不到下午14:23
# grep hello /var/log/messages
6. 创建协作目录 : c7
创建具有以下特征的协作目录
/home/managers
:
-
/home/managers
的组用权是sysmgrs
- 目录应当可被
sysmgrs
的成员读取、写入和访问,但任何其他用户不具这些权限。(当然,root 用户有权访问系统上的所有文件和目录) -
/home/managers
中创建的文件自动将组所有权设置到sysmgrs
组
Hint - 提示
- 字符法或数值法都可以
- suid=4, sgid=2, stick=1
[node1]
# mkdir /home/managers
# chown :sysmgrs /home/managers
# chmod g+rw,o=- /home/managers
# chmod g+s /home/managers/
# ls -ld /home/managers/
# touch /home/managers/file
# ll /home/managers/file
7. 配置 NTP : c11
配置 NTP 配置您的系统,使其成为
materials.example.com
的 NTP 客户端。(注:materials.example.com
是classroom.example.com
的 DNS 别名)
Hint - 提示
- chronyc sources -v 命令验证时,显示的DNS名称可能不同。ping一下DNS名称,是同一台机器
**[node1]**
- 确认服务名称
# systemctl list-units | grep NTP
`chronyd`.service loaded active running NTP client/server
- 确认服务的状态,确认配置文件
# systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; `enabled`; vendor p>
Active: `active (running)` since Sun 2021-11-07 08:24:28 GMT; 2h 36min ago
Docs: man:chronyd(8)
man:`chrony.conf`(5)
...输出省略...
- 查看配置文件的手册,确认配置文件的位置
# man chrony.conf
- * 编辑配置文件(永久生效)
# vim /etc/chrony.conf
...此处省略...
# server 时间服务器
# materils.example.com 具体的地址
# iburst ping,在时钟同步前先测试连通性
server materials.example.com iburst
...此处省略...
- * 重启服务(立即生效)
# systemctl restart chronyd
- * 确认结果
# 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
|| Reachability register (octal) -. | 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 -590us[ -844us] +/- 2547us
# timedatectl
...
System clock synchronized: `yes`
NTP service: `active`
8. 配置 autofs : RH134-C9
配置 autofs 配置
autofs
,以按照如下所述自动挂载远程用户的主目录:
-
materials.example.com
(172.25.254.254
) NFS 导出/rhome
到您的系统。此文件系统包含为用户remoteuser1
预配置的主目录 -
remoteuser1
的主目录是materials.example.com:/rhome/remoteuser1
-
remoteuser1
的主目录应自动挂载到本地/rhome
下的/rhome/remoteuser1
- 主目录必须可供其用户
写入
-
remoteuser1
的密码是flectrag
Hint - 提示
- /etc/auto.rhome 需创建,拷贝的目的是为了参考格式
**[node1]**
# showmount -e materials.example.com
Export list for `materials.example.com:`
`/rhome/remoteuser1` *
# grep remoteuser1 /etc/passwd
remoteuser1:x:1002:1002::`/rhome/remoteuser1`:/bin/bash
# rpm -qc autofs
主地图文件,写绝对路径。启动服务时,自动创建
# vim /etc/auto.master
...输出省略...
/rhome /etc/auto.rhome
# cp /etc/auto.misc /etc/auto.rhome
子地图文件,写相对路径。当访问该目录时,自动创建,自动挂载
# vim /etc/auto.rhome
remoteuser1 -rw materials.example.com:/rhome/remoteuser1
# systemctl enable --now autofs
# ls -ld /rhome
# ssh remoteuser1@localhost
remoteuser1@localhost\'s password: `flectrag`
$ pwd
/rhome/remoteuser1
$ touch my.file
$ mount | grep rhome
...
aterials.example.com:/rhome/remoteuser1 on /rhome/remoteuser1 type nfs4 (`rw`,relatime,vers=4.2,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=172.25.250.100,local_lock=none,addr=172.25.254.254)
$ <Ctrl+D>
9. 配置 /var/tmp/fstab 权限 : c7,RH134-c4
配置 /var/tmp/fstab 权限 将文件
/etc/fstab
复制到/var/tmp/fstab
。配置 /var/tmp/fstab 的权限以满足如下条件:
- 文件
/var/tmp/fstab
自root
用户所有 - 文件
/var/tmp/fstab
属于组root
- 文件
/var/tmp/fstab
应不能被任何人执行 - 用户
natasha
能够读取和写入/var/tmp/fstab
- 用户
harry
无法写入或读取/var/tmp/fstab
- 所有其他用户(当前或未来)能够读取
/var/tmp/fstab
[node1]
# cp /etc/fstab /var/tmp/fstab
# man setfacl | grep \\-m
# setfacl -m u:natasha:rw /var/tmp/fstab
# setfacl -m u:harry:- /var/tmp/fstab
# ll /var/tmp/fstab
# getfacl /var/tmp/fstab
10. 配置用户帐户 : c6
配置用户帐号 配置用户
manalo
,其用户 ID 为3533
。此用户的密码应当为flectrag
。
[node1]
# id manalo
# useradd -u 3533 manalo
# echo flectrag | passwd --stdin manalo
# ssh manalo@localhost id
11. 查找文件 : c15
查找文件 查找归
jacques
所有的所有文件并将其副本放入/root/findfiles
目录
Hint - 提示
- 创建文件夹 是隐藏题
[node1]
# mkdir /root/findfiles
# man find | grep find.*exec
# find --help
# find / -user jacques -exec cp -a {} /root/findfiles \;
# ll /root/findfiles/
total 0
-rw-r--r--. 1 jacques root 0 Mar 24 08:12 gamelan
-rw-r--r--. 1 jacques jacques 0 Mar 24 08:12 jacques
-rw-r--r--. 1 jacques root 0 Mar 24 08:12 libWedgeit.so.1.2.3
12. 查找字符串 : c2,RH134-c1
查找字符串 查找文件
/usr/share/xml/iso-codes/iso_639_3.xml
中包含字符串ng
的所有行。将所有这些行的副本按原始顺序放在文件/root/list
中。/root/list
不得包含空行,且所有行必须是/usr/share/xml/iso-codes/iso_639_3.xml
中原始行的确切副本。
[node1]
- 查看
# grep ng /usr/share/xml/iso-codes/iso_639_3.xml
- 生成
*# grep ng /usr/share/xml/iso-codes/iso_639_3.xml > /root/list
- 验证
# cat /root/list
13. 创建存档 : c13
创建存档 创建一个名为
/root/backup.tar.gz
的 tar 存档,其应包含/usr/local
的 tar 存档,其应包含/usr/local
的内容。该 tar 存档必须使用gzip
进行压缩。
Hint - 提示
- tar: Removing leading '/' from member names 这是提示,不是报错
- -z, --gzip # tar -czf ...
- -j, --bzip2 # tar -cjf ...
- -J, --xz # tar -cJf ...
**[node1]**
# man tar | grep gzip
-z, --gzip, --gunzip, --ungzip
...
# MANWIDTH=120 man tar | grep tar.*-c
tar -cvf a.tar /etc
...
# tar -czf /root/backup.tar.gz /usr/local
tar: Removing leading '/' from member names
# echo $?
lisT,查看包文件内容
# tar -tf /root/backup.tar.gz
# file /root/backup.tar.gz
/root/backup.tar.gz: `gzip` compressed data, ...
14. 配置容器使其自动启动(A卷): RH134-c13
配置容器使其自动启动(A卷) 利用注册服务器上的
rsyslog
镜像,创建一个名为logserver
的容器
- 面向
wallah
用户,配置一个 systemd 服务 - 该服务命名为
container-logserver
,并在系统重启时自动启动,无需干预
15. 为容器配置持久存储(A卷): c11,RH134-c13
为容器配置持久存储(A卷) 通过以下方式扩展上一个任务的服务
- 配置主机系统的 journald 日志以在系统重启后保留数据,并重新启动日志记录服务
- 将主机
/var/log/journal
目录下任何以*.journal
的文件复制到/home/wallah/container_logfile
中 - 将服务配置为在启动时自动将
/home/wallah/container_logfile
挂载到容器中的/var/log/journal
下
Hint - 提示
- 建议 A卷两题一起做
Important - 重要
- podman 默认已经安装 1.9 版本
- 注意路径,登陆下网页确认
- 一定要 ssh
**[node1]**
# systemctl list-unit-files | grep journal
# systemctl status systemd-journald
# man journald.conf
# vim /etc/systemd/journald.conf
#`Storage`=`auto`
# man journald.conf
/Storage
Storage=
Controls where to store journal data. One of "volatile",
"persistent", "auto" and "none". If "volatile", journal log data
will be stored only in memory, i.e. below the `/run/log/journal`
...
and if the disk is not writable. "auto" is similar to "persistent"
but the directory `/var/log/journal` is not created if needed, so
# ll -d /run/log/journal
drwxr-sr-x. 3 root systemd-journal 60 Mar 24 17:56 /run/log/journal
# mkdir /var/log/journal
# chown root:systemd-journal /var/log/journal
# chmod g+s /var/log/journal
# systemctl restart systemd-journald
# ls /var/log/journal
f874df04639f474cb0a9881041f4f7d4
# ls /run/log/journal
ls: cannot access '/run/log/journal': No such file or directory
# cp /var/log/journal/*/*.journal /home/wallah/container_logfile/
# chown -R wallah ~wallah
# ll -Z /home/wallah/container_logfile/
[node1]
# ssh wallah@localhost
$ podman login registry.domain250.example.com
Username: `admin`
Password: `redhat321`
login Succeeded!
$ podman search registry.domain250.example.com/
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
example.com registry.domain250.example.com/rhel8/rsyslog 0
...
$ podman run -d --name logserver \
-v /home/wallah/container_logfile:/var/log/journal:Z \
registry.domain250.example.com/rhel8/rsyslog
$ podman stop logserver
$ loginctl enable-linger
$ loginctl show-user wallah
$ MANWIDTH=160; man systemd.unit | grep config.*user
...
`│$HOME/.config/systemd/user` │...
$ mkdir -p ~/.config/systemd/user/
$ cd ~/.config/systemd/user/
$ podman generate systemd -n logserver -f
$ systemctl --user enable --now container-logserver
$ systemctl --user status container-logserver
$ podman exec logserver ls /var/log/journal
system.journal
user-1004.journal
$ <Ctrl-D>
# reboot
# ps aux | grep -n podman
16. 配置容器使其自动启动(B卷): RH134-c13
配置容器使其自动启动(B卷) 利用注册服务器上的
rsyslog
镜像,创建一个名为logger
的容器
- 面向
wallah
用户,配置一个 systemd 服务 - 该服务命名为
container-logger
,并在系统重启时自动启动,无需干预 - 将服务配置为在启动时自动将
/home/wallah/var_log
挂载到容器中的/var/log
下 - 在容器中执行命令
podman exec logger logger -p authpriv.info SUIBIAN
[node1]
# ssh wallah@localhost
$ podman login -u admin -p redhat321
WARNING! ...
login Succeeded!
$ podman search registry.domain250.example.com/
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
example.com registry.domain250.example.com/rhel8/rsyslog 0
...
$ podman run -d --name logger \
-v /home/wallah/var_log:/var/log:Z \
registry.domain250.example.com/rhel8/rsyslog
$ podman stop logger
$ loginctl enable-linger
$ loginctl show-user wallah
$ MANWIDTH=160; man systemd.unit | grep -A 20 \\--user
...
│$HOME/.config/systemd/user │...
$ mkdir -p ~/.config/systemd/user/
$ cd ~/.config/systemd/user/
$ podman generate systemd -n logger -f
$ systemctl --user enable --now container-logger
$ systemctl --user status container-logger
$ podman exec logger logger -p authpriv.info SUIBIAN
$ grep ^authpriv /etc/rsyslog.conf
authpriv.* /var/log/`secure`
$ grep SUIBIAN /home/wallah/var_log/secure
2021-08-13T11:45:37.824980+00:00 574761d4236a root: SUIBIAN
$ <Ctrl-D>
# reboot
# ps -aux | grep podman
17. 容器nginx(附加题): RH134-c13
容器nginx 利用注册服务器上的
nginx
镜像,创建一个名为nginx
的容器
- 面向
wallah
用户,配置一个 systemd 服务 - 该服务命名为
container-nginx
,并在系统重启时自动启动,无需干预 - 在
/home/wallah/www
下创建文件index.html
,内容为hello nginx
- 将服务配置为在启动时自动将
/home/wallah/www
挂载到容器中的/usr/share/nginx/html
下 - 将容器主机上的端口
8080
映射到容器上的端口80
[root@node1]
# man -k registries
`containers-registries.conf` (5) - Syntax of System Registry Configuration File
...输入省略...
# man containers-registries.conf
# ls /etc/containers/registries.conf ~wallah/.config/containers/registries.conf
# ssh wallah@localhost
$ cp /etc/containers/registries.conf ~wallah/.config/containers/registries.conf
$ vim ~wallah/.config/containers/registries.conf
# The first version
[registries.search]
registries = ['registry.domain250.example.com']
[registries.insecure]
registries = ['registry.domain250.example.com']
[registries.block]
registries = []
# The second version
unqualified-search-registries = ["registry.domain250.example.com"]
[[registry]]
location = "registry.domain250.example.com"
insecure = true
$ podman info
...输出省略...
registries:
registry.domain250.example.com:
Blocked: false
Insecure: true
Location: registry.domain250.example.com
MirrorByDigestOnly: false
Mirrors: null
Prefix: registry.domain250.example.com
search:
- registry.domain250.example.com
...输出省略...
$ podman login registry.domain250.example.com
Username: `admin`
Password: `redhat321`
login Succeeded!
$ podman search registry.domain250.example.com/
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
example.com registry.domain250.example.com/library/nginx 0
...
$ mkdir /home/wallah/www
$ echo hello nginx > /home/wallah/www/index.html
$ podman run \
-d \
--name nginx \
-v /home/wallah/www:/usr/share/nginx/html:Z \
-p 8080:80 \
registry.domain250.example.com/library/nginx
启用『逗留功能』
$ loginctl enable-linger
确认『逗留功能』
$ loginctl show-user wallah
$ MANWIDTH=160; man systemd.unit | grep config.*user
~/.config/systemd/user.control/*
`~/.config/systemd/user/*`
│~/.config/systemd/user.control |...
│$HOME/.config/systemd/user │...
$ mkdir -p ~/.config/systemd/user/
$ cd ~/.config/systemd/user/
生成用户的单元文件
$ podman generate systemd -n nginx -f
$ podman stop nginx
$ systemctl --user enable --now container-nginx
$ systemctl --user status container-nginx
$ curl localhost:8080
hello nginx
$ <Ctrl-D>
# reboot
验证方式A
# curl localhost:8080
验证方式B
# ss -antup | grep 8080
验证方式C
# ps -aux | grep podman
18. 添加sudo免密操作(附加题)- c10
添加sudo免密操作
- 允许
sysmgrs
组成员sudo时不需要密码
[node1]
# visudo
...
# %wheel ALL=(ALL) NOPASSWD: ALL
%sysmgrs ALL=(ALL) NOPASSWD: ALL
/NOPEnter, yy, p, dw, w, cw, Ctrl-Shfit-v, Esc, ZZ
# su - natasha
$ sudo tail /var/log/messages
19. 配置创建新用户的密码策略(附加题): c6
配置创建新用户的密码策略
- 创建新用户时,默认密码策略为
20
天后,密码会过期
[node1]
# man useradd
<G>
# vim /etc/login.defs
...
PASS_MAX_DAYS 20
# useradd dog
# chage -l dog
Last password change : Apr 29, 2021
Password expires : May 19, 2021
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : `20`
Number of days of warning before password expires : 7
20. 创建脚本(附加题)(A卷): RH134-c1
创建脚本
- 创建一个名为
myresearch
的脚本 - 该脚本放置在
/usr/bin
下 - 该脚本用来查找
/usr
下所有小于10m
且具有修改组ID
权限的文件,将这些文件放置于/root/myfiles
下
Important - 重要 此题做完后,一定要 df -h / 看一下根分区的容量
**[node1]**
# vim /etc/bashrc
/if 查找if
# man test | grep \\-d
# vim /usr/bin/myresearch
#!/bin/bash
mkdir /root/myfiles
find /usr -size -10M -perm /g=s -exec cp -a {} /root/myfiles \;
# chmod +x /usr/bin/myresearch
# /usr/bin/myresearch
# ll -h /root/myfiles
-rwx--`s`--x. 1 root slocate `47K` Aug 12 2018 locate
-r-xr-`s`r-x. 1 root ssh_keys `464K` Nov 26 2018 ssh-keysign
-rwx--`s`--x. 1 root utmp `13K` Aug 12 2018 utempter
-rwxr-`s`r-x. 1 root tty `23K` Dec 11 2018 write
# df -h /
21. 创建脚本(附加题)(B卷): RH134-c1
创建脚本
- 创建一个名为
newsearch
的脚本 - 该脚本放置在
/usr/bin
下 - 该脚本用来查找
/usr
下所有大于30k
,但是小于50k
且具有SUID
权限的文件,将这些文件名字放置于/root/newfiles
文件中
[node1]
# vim /usr/bin/newsearch
#!/bin/bash
find /usr -size +30k -size -50k -perm /u=s > /root/newfiles
# chmod +x /usr/bin/newsearch
# /usr/bin/newsearch
# cat /root/newfiles
22. 设置默认权限(附加题)
设置默认权限
- 用户
manalo
在 node1 上,所有新创建的文件都应具有-r--r--r--
的默认权限 - 此用户的所有新创建目录应具有
dr-xr-xr-x
的默认权限
Hint - 提示 file = 666 - umask = 666 - 444 = 222 folder = 777 - umask
**[node1]**
# su - manalo
$ ls -a
. .. .bash_logout `.bash_profile` `.bashrc`
$ vim ~/.bashrc
...内容省略...
umask 222
-m1 立即生效
$ source ~/.bashrc
-m2 注销,重新登陆
$ <Ctrl-D>
$
$ umask
$ touch file; mkdir folder
$ ll -d f*
23. 配置一个应用(附加题): RH134-c1
配置一个应用
- 配置一个应用
rhcsa
- 这个应用以
natasha
身份运行时,会显示一个字符串This is a rhcsa
[node1]
# su - natasha
考试时,请按照手册的方法配置
*$ man rhcsa
$ vim ~/.bashrc
...输出省略...
alias rhcsa='echo This is a rhcsa'
$ source ~/.bashrc
$ rhcsa
This is a rhcsa
相关文章
- Linux常用命令(更新)
- Linux – nmap – nc(ncat) 命令 – 扫描端口
- Linux fdisk命令详解[主分区/逻辑分区创建]程序员
- Linux操作系统考题:提升技能之路(linux操作系统考题)
- Linux系统下自动挂载配置指南(linux自动mount)
- Linux筛选文件:一种简单的技巧(linux筛选文件)
- 检查Linux系统启动:文件系统检查(linux启动文件系统)
- Linux分区格式:轻松安装(安装linux的分区格式)
- Linux 考题指南(linux考题)
- 启动 如何在Linux上通过U盘启动系统(linux如何u盘)
- 编码Linux下如何设置GBK编码(linux设置gbk)
- Mac安装Linux系统指南(mac怎么安装linux)
- Linux之分岔发展史(linux的分支)
- Linux分支:探索开源的新世界(linux的分支)
- Linux基础测试:突破考题,助你轻松过关!(linux基础考题)
- 开启 Linux 上的 wdt 之旅(wdtlinux)
- 开启Linux之旅:学习LINUX系统登录(linux系统登录)
- 如何删除 Linux 上的软连接?How to delete soft links in Linux(删除软连接linux)
- “奇迹般的Linux:运行bin的方式”(linux 运行 bin)
- 深入Linux:学习Linux语言(查看 linux 语言)