红帽认证RHCSA(一)

RHCSA认证

`

在 mars.lab.example.com 上执行以下任务

一、配置网络地址

**题目:**
将mars 配置为具有以下网络配置:
主机名: mars.lab.example.com
IP 地址: 192.168.122.101
子网掩码: 255.255.255.0
网关: 打开VMware-编辑-虚拟网络编辑器-NAT模式-NAT设置找到网关地址
名称服务器: 223.5.5.5

**答题:**
# 修改IP地址-命令
nmcli con mod ens160 ipv4.method manual ipv4.addr "192.168.122.101/24" ipv4.gateway "192.168.122.2" ipv4.dns "223.5.5.5" connection.autoconnect yes
# 修改主机名 
[root@localhost ~]# hostnamectl set-hostname servera.lab.example.com 

# 修改网卡信息,我的VMware里的网关是 192.168.122.2 

# 重启网卡之前一定要重新载入一下配置文件,不然不能立即生效
[root@servera ~]# nmcli c reload
#重启网卡:
[root@servera ~]# nmcli connection up enp1s0

#考试时一定要确认要修改哪张网卡的IP地址,通过以下命令确认。
[root@servera ~]# nmcli c show 
[root@servera ~]# nmcli d show

#检查:
#查看IP地址和DNS。
[root@servera ~]# ip addr
[root@servera ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search lab.example.com
nameserver 223.5.5.5
#

二、配置您的系统以使用默认存储库

**题目:**
yum 存储库已可以从 http://mirrors.aliyun.com/centos- vault/8.5.2111/BaseOS/$basearch/os/ 
和
http://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/ 使用。配置您的系统, 以将这些位置用作默认存储库

#答题:
# 准备工作,清空yum仓库,考试不需要做
[root@servera ~]# rm -rf /etc/yum.repos.d/* 

**#实际操作** 
[root@servera ~]# cd /etc/yum.repos.d/

[root@servera yum.repos.d]# vim rehl_dvd.repo
[root@servcea yum.repos.d]# cat rhel_dvd.repo
[BaseOS]
name = BaseOS
baseurl = http://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck = 0
enable = 1

[AppStream]
name=AppStream
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=0
enable=1

#检查:
#要求清除缓存再生成缓存无报错。 
[root@servera ~]# yum clean all 
12 files removed 
[root@servera ~]# yum makecache


[root@servera ~]# yum repolist all 

三、调试SELinux

题目:
在mars.lab.example.com 上执行非标准端口82上运行的 Web 服务器在提供内容时遇到问题。
根据需要调试并解决问题, 使其满足以下条件:
系统上的 Web 服务器能够提供/var/www/html 中所有现有的 HTML 文件( 注: 不要删除或以其他方式改动现有的文件内容)
Web服务器在端口82 上提供此内容
Web服务器在系统启动时自动启动

解答:
# 解题:
[root@mars ~]# ll /var/www/html/
-rw-r--r--. 1 root root 12 Aug 8 09:59 file1
# 查看服务是否服务启动
[root@mars ~]# systemctl status httpd

# 启动服务
[root@mars ~]# systemctl enable httpd --now

# 发现报错 ,APACHE默认监听在80端口上面,像上面这种非标准端口我们需要给它添加一个标签
[root@mars ~]# semanage port -l|grep http
[root@mars ~]# semanage port -a -t http_port_t -p tcp 82  # 在上面再加一个82端口
[root@mars ~]# systemctl start httpd

我们在外面的终端进行一下测试,看网页能否访问
无法访问是因为我们需要放行防火墙
再次测试,发现可以访问
现在我们再来测试一下能否访问file1文件

[root@mars ~]# netstat -tnlp | grep http
[root@mars ~]# ps aux| grep httpd
[root@mars ~]# firewall-cmd --permanent --add-port=82/tcp
success
[root@mars ~]# firewall-cmd --reload
success
文件无法访问,我们可以查看一下它的标签
[root@mars ~]# ll /var/www/html/file1
-rw-r--r--. 1 root root 12 Aug 8 09:59
/var/www/html/file1
[root@mars ~]# ll -Z /var/www/html/file1
-rw-r--r--. 1 root root
unconfined_u:object_r:samba_share_t:s0 12 Aug 8 09:59
/var/www/html/file1
[root@mars ~]# ll -dZ /var/www/html
drwxr-xr-x. 2 root root
system_u:object_r:httpd_sys_content_t:s0 19 Aug 8 09:59
/var/www/html
[root@mars ~]# restorecon -Rv /var/www/html/ # 根据上级目录把它重置一下
Relabeled /var/www/html/file1 from
unconfined_u:object_r:samba_share_t:s0 to
unconfined_u:object_r:httpd_sys_content_t:s0
[root@mars ~]# ll -Z /var/www/html/file1
-rw-r--r--. 1 root root
unconfined_u:object_r:httpd_sys_content_t:s0 12 Aug 8
09:59 /var/www/html/file1
# 如果可以我们可以给他添加一个标签,当然不能添加也没事
[root@mars ~]# semanage fcontext -l | grep var/www|head
[root@mars ~]# semanage fcontext -a -t httpd_sys_content_t /var/www/html/file1
再次测试file1文件

四、创建用户账户

创建用户帐户
在mars.lab.example.com 上执行
创建下列用户、 组和组成员资格:
名为admins 的组
用户lucy , 作为次要组从属于admins
用户harry , 作为次要组还从属于admins
用户jams , 无权访问系统上的交互式shell且不是admins 的成员
lucy 、 harry 和jams 的密码应当都是redhat

# 开始操作
[root@mars ~]# groupadd admins
[root@mars ~]# useradd lucy -G admins
[root@mars ~]# useradd harry -G admins
[root@mars ~]# useradd jams -s /usr/sbin/nologin
[root@mars ~]# echo redhat |passwd --stdin lucy
Changing password for user lucy.
passwd: all authentication tokens updated successfully.
[root@mars ~]# echo redhat |passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@mars ~]# echo redhat |passwd --stdin jams
Changing password for user jams.
passwd: all authentication tokens updated successfully.

# 检查
[root@mars ~]# su - lucy
[lucy@mars ~]$ su - harry
Password:redhat
[harry@mars ~]$

五、配置cron计划任务

配置cron作业
在mars.lab.example.com 上执行
用户lucy 必须配置一个cron 作业, 该作业每隔 2 分钟( 当地时间) 运行
且执行: /bin/echo hiya

# 开始操作
 # 第一步:确认服务是否启动
[root@mars ~]# systemctl status crond

[root@mars ~]# systemctl enable crond --now              # 设置开机立即自启动
[root@mars ~]# crontab -u lucy -e                        # 编写定时任务
*/2 * * * * /bin/echo hiya

# 检查
[root@servera ~]# crontab -u lucy -l 
*/2 * * * * echo hello 

六、创建协作目录(共享目录)

创建协作目录
在mars.lab.example.com 上执行
创建具有以下特征的协作目录/home/test
/home/test 的组所有权是admins
目录应当可被admins的成员读取、 写入和访问, 但任何其他用户不具这些权限。(当然, root用户有权访问系统上的所有文件和目录)
/home/test 中创建的文件自动将组所有权设置到admins 组

[root@mars ~]# mkdir /home/test
[root@mars ~]# ll -d /home/test
drwxr-xr-x. 2 root root 6 Aug 8 18:48 /home/test
[root@mars ~]# chgrp admins /home/test
[root@mars ~]# ll -d /home/test
drwxr-xr-x. 2 root admins 6 Aug 8 18:48 /home/test
[root@mars ~]# chmod g=rwx,o=- /home/test
[root@mars ~]# ll -d /home/test
drwxrwx---. 2 root admins 6 Aug 8 18:48 /home/test
[root@mars ~]# chmod g+s /home/test
[root@mars ~]# ll -d /home/test
drwxrws---. 2 root admins 6 Aug 8 18:48 /home/test
[root@mars ~]# touch /home/test/test.txt
[root@mars ~]# ll /home/test/test.txt
-rw-r--r--. 1 root admins 0 Aug 8 18:50
/home/test/test.txt
[root@mars ~]# rm -f /home/test/test.txt

七、配置NTP

配置 NTP
在mars.lab.example.com 上执行
配置您的系统, 使其成为classroom.example.com 的 NTP 客户端。
考试时提示: classroom.example.com 是 sidecar.lab.example.com 的 DNS 别名
我们这里使用NTP服务器ntp.aliyun.com 做练习。

# 先检查服务是否启动(考试环境没有安装这个包,需要手动安装)
[root@mars ~]# rpm -qa | grep chrony
chrony-3.3-3.el8.x86_64
[root@mars ~]# systemctl status chronyd
# 编辑配置文件,修改server行
[root@mars ~]# vim /etc/chrony.conf (下面server在配置文
件中没有,需要手动编写,如果不会,查看man chrony.conf)
server classroom.example.com iburst
[root@mars ~]# systemctl restart chronyd
[root@mars ~]# chronyc sources -v

八、配置autofs

在mars.lab.example.com 上执行
以按照如下所述自动挂载远程用户的主目录:
classroom.example.com(192.168.122.100)NFS 导出/rhome 到您的系统。此文件系统包含为用户lily 预配置的主目录。
lily 的主目录是classroom.example.com:/rhome/lily 。
lily 的主目录应自动挂载到本地/rhome 下的/rhome/lily 。
主目录必须可供其用户写入。
lily 的密码是redhat

1> 先安装需要的软件包
[root@mars ~]# grep lily /etc/passwd
lily:x:2001:2001::/rhome/lily:/bin/bash
[root@mars ~]# yum -y install autofs # 安装autofs软件包

2> 修改配置文件
[root@mars ~]# cd /etc/auto.master.d/ #在这个目录内添
加一个主映射文件,此文件确定用于挂载点的基础目录,并确
定用于创建自动挂载的映射文件
[root@mars auto.master.d]# ls
[root@mars auto.master.d]# vim nfs.autofs # 注意后缀一
定要是autofs,文件的名称是任意的
[root@mars auto.master.d]# cat nfs.autofs
/rhome /etc/auto.rhome #此条目/rhome目录为间接自动
挂载的基础目录,也可以称它为监视目录, 如果有触
发/etc/auto.nfs(自定义,用于被监视)的关键字就进行挂载,使
用绝对路径
[root@mars auto.master.d]# cd ..
[root@mars etc]# cp auto.misc /etc/auto.rhome #创建映射文
件,用来确定自动挂载的挂载点,挂载选项及挂载的位置
[root@mars etc]# cat /etc/auto.master.d/nfs.autofs
/rhome /etc/auto.rhome
[root@mars etc]# cat /etc/auto.rhome # 访问规则
lily -fstype=nfs,rw,sync
classroom.example.com:/rhome/lily
[root@mars etc]# systemctl enable autofs.service
[root@mars etc]# systemctl restart autofs.service
[root@mars etc]# ssh lily@mars
[lily@mars ~]$ df -h

九、配置文件权限(配置/var/tmp/fstab 权限)

配置/var/tmp/fstab 权限
在mars.lab.example.com 上执行
将文件/etc/fstab 复制到/var/tmp/fstab 。 配置/var/tmp/fstab 的权限以满足如下条件:
文件/var/tmp/fstab 由root 用户所有
文件/var/tmp/fstab 属于组root
文件/var/tmp/fstab 应不能被任何人执行
用户lucy 能够读取和写入/var/tmp/fstab
用户harry 无法写入或读取/var/tmp/fstab
所有其他用户( 当前或未来) 能够读取/var/tmp/fstab

[root@mars ~]# cp /etc/fstab /var/tmp/fstab
[root@mars ~]# ll /var/tmp/fstab
-rw-r--r--. 1 root root 427 Aug 8 23:08 /var/tmp/fstab
[root@mars ~]# setfacl -m u:lucy:rw,u:harry:- /var/tmp/fstab
[root@mars ~]# getfacl /var/tmp/fstab

十、配置用户账户

配置用户帐户
在mars.lab.example.com 上执行
配置用户jacks , 用户ID 为 3533 。 此用户的密码应当为redhat 。

[root@mars ~]# id jacks
uid=2002(jacks) gid=2002(jacks) groups=2002(jacks)
[root@mars ~]# usermod -u 3533 jacks
[root@mars ~]# id jacks
uid=3533(jacks) gid=2002(jacks) groups=2002(jacks)
[root@mars ~]# echo redhat | passwd --stdin jacks
Changing password for user jacks.
passwd: all authentication tokens updated successfully.

十一、查找文件

查找文件
在mars.lab.example.com 上执行
查找用户querys 所有的文件并将其副本放入/root/findfiles 目录。

[root@mars ~]# mkdir /root/findfiles
[root@mars ~]# find / -user querys -exec cp -a {} /root/findfiles \; 2>/dev/null
[root@mars ~]# ls /root/findfiles/

十二、查找字符串

查找字符串
在mars.lab.example.com 上执行
查找文件/usr/share/doc/words/readme.txt 中包含字符串crosswords 的所有行。
将所有这些行的副本按原始顺序放在文件/root/list 中。
/root/list 不得包含空行, 且所有行必须是/usr/share/doc/words/readme.txt 中原始行的确切副本
 
[root@mars ~]# ll /usr/share/doc/words/readme.txt
-rw-r--r--. 1 root root 5125 Aug 13 2018
/usr/share/doc/words/readme.txt
[root@mars ~]# grep "crosswords" /usr/share/doc/words/readme.txt
113,809 official crosswords
4,160 official crosswords delta
When combined with the 113,809 crosswords file, it
produces the
[root@mars ~]# grep "crosswords" /usr/share/doc/words/readme.txt > /root/list
[root@mars ~]# cat /root/list

十三、 创建归档

创建存档
在mars.lab.example.com 上执行
创建一个名为/root/backup.tar.gz 的tar存档, 其应包含/usr/local 的内容。
该tar 存档必须使用gzip 进行压缩

归档:把很多文件归纳到一起tar
压缩:减小文件占用空间的大小gzip、bzip2、xz
# tar命令的选项
-c:创建新文档
-x:释放备份文档
-f:指定文档名称
-z:处理.gz格式
-j:处理.bz2格式
-J:处理.xz格式
-t:显示文档列表
-p:保持原有权限
-P:保持绝对路径
-C:制定释放备份文件时的目标位置
--exclude=排除的子目录
# 开始操作
[root@mars ~]# tar zvcf /root/backup.tar.gz /usr/local

# 检查
[root@servera ~]# ls -lh ~/backup.tar.gz
-rw-r--r-- 1 root root 504 Mar 16 22:20 /root/backup.tar.gz

总结

2023年7月17日考的

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
RHCSA考试是红帽认证中的一种,是一项针对Linux系统管理员的认证考试。下面是一些RHCSA考试认证题目的解析,供您参考: 1. 题目:在Linux系统中,如何查看当前用户的登录记录? 解析:可以使用last命令来查看当前用户的登录记录。例如,输入以下命令: ``` last ``` 将会显示最近的登录记录,包括登录时间、登录IP地址、登录方式等信息。 2. 题目:如何在Linux系统中查看当前系统的CPU使用情况? 解析:可以使用top命令来查看当前系统的CPU使用情况。例如,输入以下命令: ``` top ``` 将会显示当前系统的进程信息,包括每个进程的CPU使用情况、内存使用情况等。 3. 题目:如何在Linux系统中创建一个名为test的用户并设置密码为123456? 解析:可以使用useradd命令来创建一个名为test的用户,同时使用passwd命令来设置密码。例如,输入以下命令: ``` useradd test passwd test ``` 将会创建一个名为test的用户,并设置该用户的密码为123456。 4. 题目:如何在Linux系统中查看当前系统的IP地址? 解析:可以使用ifconfig命令来查看当前系统的IP地址。例如,输入以下命令: ``` ifconfig ``` 将会显示当前系统的网络接口信息,包括每个接口的IP地址、MAC地址等。 需要注意的是,RHCSA考试的题目内容可能会涉及到Linux系统的各个方面,包括系统管理、网络管理、安全管理等。因此,在备考过程中需要全面掌握Linux系统的基本操作和管理技能,并且要多做练习题、模拟试题等来提高自己的实际操作能力。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_50509873

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值