RHC E 模拟测试
系统环境说明:
X 是你的主机号
宿主机:foundationX.ilt.exam ple.com
虚拟机:
ser ver X.exam ple.com IP: 172.25.X.11/24
desktopX.exam ple.com
IP: 172.25.X.10/24
G AT EW AY: 172.25.X.254
DNS: 172.25.254.254
YUM 安装源:
http://content.exam ple.com /r hel7
SEL INUX 要求 enfor cing 模式
fir ew alld 防火墙启动
操作题目
:
###########################################################
注意:
1.操作时间 2 小时
2. 以下题目在检测是系统会被重新启动,在重新启动后设定仍然生效
视为正确!!
###########################################################
1. 进入系统单用户模式,修改 r oot 用户密码为 w estosexam ,并设置系统默认进
入多用户模式
进入选择系统界面的时候按上下键e进入以下界面,修改为内容
linux16…那一行删除ro以及ro以后的内容,然后添加rw rd.break
chroot /sysroot/ ##切换到root权限
passwd root ##修改密码为westosexam
exit
exit
2. 在 ser ver X 上添加两块虚拟网卡,用以配置主备负载接口 team 0,并分配 ip
地址为 172.25.X.100/24
nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.1.100/24 ##建立team方式
nmcli connection add con-name eth1 ifname eth1 type team-slave master team0 ##添加网卡eth1到team0
nmcli connection add con-name eth0 ifname eth0 type team-slave master team0 ##添加网卡eth0到team0
teamdctl team0 stat ##查看team的状态
添加网卡
添加端口
3. 配置 iSC SI 服务:
a) 在 ser ver X 上安装服务端程序,设置开机自启,防火墙允许此服务
b) 在 vdb 磁 盘上 分一 个 1G 大 小的 L VM 分 区 ,用 以创 建逻 辑卷 组
iSC SI_vg 和一个 100M 大小的逻辑卷 disk1_lv
c)
使用 disk1_lv 作为 iSC SI 的后端存储名称为 ser ver X.disk1
d) 定义 IQ N 为 iqn.2015-01.com .exam ple:ser ver X
e)
设置 AC L 允许 initiator nam e 为 iqn.2018-01.com .exam ple:desktopX
的 客 户 端 可 以 连 接 , 设 置
AC L
允 许
initiator nam e 为
iqn.2018-01.com .exam ple:desktopX 的客户端可以连接
f)
desktopX 安装客户端程序,连接 ser ver X 的 iSC SI 目标资源到本地,用
以创建一个 xfs 文件系统,并开机自动挂载到/iscsidisk
服务端
yum install targetcli.noarch -y ##安装服务端程序
systemctl start target ##开启服务
systemctl enable target ##设置开机自启
firewall-cmd --permanent --add-port=3260/tcp ##添加该服务使用的端口
firewall-cmd --reload ##重新加载火墙
fdisk /dev/vdb ##新建一个1G的分区,并且设置类型为LVM
partprobe ##同步分区表
pvcreate /dev/vdb1 ##创建逻辑分区
vgcreate iSCSI_vg /dev/vdb1 ##创建逻辑卷组iSCSI_vg
lvcreate -L 100M -n disk1_lv iSCSI_vg ##创建逻辑卷disk1_lv
targetcli ##调出iSCSI软件
/> backstores/block create server1.diskl /dev/iSCSI_vg/disk1_lv
/> iscsi/ create iqn.2015-01.com.example:server1
/> iscsi/iqn.2015-01.com.example:server1/tpg1/luns create /backstores/block/server1.diskl
/> iscsi/iqn.2015-01.com.example:server1/tpg1/acls create iqn.2018-01.com.example:desktop1
/> iscsi/iqn.2015-01.com.example:server1/tpg1/portals create 172.25.1.11
exit
客户端
yum install iscsi-initiator-utils -y
vim /etc/iscsi/initiatorname.iscsi ##修改为下列内容
InitiatorName=iqn.2018-01.com.example:desktop1
systemctl restart iscsid.service
iscsiadm -m discovery -t st -p 172.25.1.11
iscsiadm -m node -T iqn.2015-01.com.example:server1 -p 172.25.1.11 -l
fdisk -l ##查看一下是否添加上了网络硬盘
mkfs.xfs /dev/sda
mkdir /iscsidisk
vim /etc/fstab ##添加以下内容
/dev/sda /iscsidisk xfs defaults,_netdev 0 0
mount -a ##挂载
4.配置 NFS 服务
a) 在 ser ver X 上设置服务开机自启动,防火墙允许此服务
b) 在 ser ver X 上共享本地目录/nfsshar e,desktopX 可以读写访问此共享,
并且开机自动挂载到/m nt/nfsshar e 目录上
c)
在 sever x 上共享目录/autonfs,当 desktop 进入到/nfsauto/ser ver x 后自
动挂载 sever x 上共享目录/autonfs 到 desktop 上的/nfsauto/ser ver x 上
yum install nfs-utils -y
systemctl start nfs-server
systemctl enable nfs-server
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=ntp
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload
服务端
yum install nfs-utils -y
systemctl start nfs-server
systemctl enable nfs-server
mkdir /nfsshare
vim /etc/exports
/nfsshare 172.25.1.11(sync,rw)
客户端
yum install nfs-utils autofs -y
systemctl start autofs
systemctl enable autofs.service
showmount -e 172.25.1.11
mkdir /mnt/nfsshare
vim /etc/fstab
172.25.1.11:/nfsshare /mnt/nfsshare nfs defaults 0 0
mount -a
mkdir /autonfs
vim /etc/exports
/autonfs 172.25.1.11(sync,rw)
exportfs -rv
showmount -e 172.25.1.11
mkdir /nfsauto/server1
vim /etc/auto.master
8 /nfsauto /etc/auto.nfs
vim /etc/auto.nfs
server5 -rw 172.25.1.11:/autonfs
systemctl restart autofs.service
cd nfsauto/
cd server1
df ##查看是否挂载
5.配 SM B 服务:
a) 在 ser ver X 上配置 sm b 共享服务,要求开机自启,防火墙允许此服务
yum install samba samba-common samba-client -y
systemctl start smb
systemctl enable smb firewall-cmd --permanent --add-service=samba
firewall-cmd --permanent --add-port=139/tcp
firewall-cmd --permanent --add-port=445/tcp
firewall-cmd --reload
b) 创 建 共 享 目 录 为 /smbshar e, 共 享 名 为sm bshar e, 工 作 组 为W EST O S,marketing 组成员可以读写此共享,不属于 m ar keting 组的人只能读
mkdir /smbshare
vim /etc/samba/smb.conf
89 workgroup = WESTOS
322 [smbshare]
323 comment= dir share
324 path= /smbshare
325 write list =@marketing
groupadd marketing
chgrp marketing /smbshare/
chmod 2775 /smbshare/ ##权限修改
semanage fcontext -a -t samba_share_t '/smbshare(/.*)?' ##永久更改安全上下文
restorecon -RvvF /smbshare/ ##刷新
c)创建 samba-only 用户 brian 和 rob,其中 brian 用户属于 marketing
组,用户密码都是 westos
useradd -s /sbin/nologin brian ##指定用户默认sell(此shell特点是用户不能登陆系统,但能使用某些服务)
useradd -s /sbin/nologin rob
echo westos | passwd --stdin brain ##给用户设置密码(stdin:标准输入),这一步也不需要做
echo westos | passwd --stdin rob
usermod -g marketing brian
smbpasswd -a brian ##密码都设置为westos
smbpasswd -a rob
pdbedit -L ##查看用户
systemctl restart smb.service
d) 在 desktopX 上建立挂载点/m nt/multiuser 目录,开机自动挂载 server X
上的 smbshare 共享,激活 smb 多用户挂载支持。
yum install samba-client cifs-utils -y
mkdir /mnt/multiuser
smbclient //172.25.1.11/smbshare -U brian ##登陆
smbclient //172.25.1.11/smbshare -U rob
vim /root/smbpass
username=brian
password=westos
chmod 600 /root/smbpass
cifscreds add -u brian 172.25.1.11 ##给root添加brian用户的挂载认证
vim /etc/fstab ##永久挂载
//172.25.1.11/smbshare /mnt/multiuser cifs credentials=/root /smbpass,sec=ntlmssp,multiuser 0 0
mount -a
6 配置 M ar iadb 数据库服务:
a) 在 ser ver X 上安装 m ar iadb 数据库,开机自启动,防火墙允许此服务
yum install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload
netstat -antlupe | grep mysql ##查看远程访问端口
mysql_secure_installation ##第一个回车,后面都是y ,设置root密码为westos
systemctl restart mariadb.service
b) 给 数 据 库 设 置 root 管 理 员 密 码 为 westos, 限 制 root 用 户 只 能 从
localhost 登录,移除匿名用户,删除 test 库
mysql -uroot -pwestos -e "CREATE database redhat;"
mysql -uroot -pwestos -e "SHOW DATABASES;"
c)创建一个名为 r edhat 的库,并从备份文件中恢复数据到此数据库,备份
文件的位置在:
http://classroom .example.com /pub/materials/mariadb/maradb.dump 。
此处的备份文件考试机的电脑里,这里模拟下载下来之后的步骤
mysql -uroot -pwestos redhat</mnt/mariadb.dump
d) 创建数据库用户 m ar y,对 r edhat 数据库具有查询、插入、更新、删除
权限,密码为 m ar y_passw d。 natasha 用户可以从 desktopX 上登录数据
库,对 r edhat 库拥有查询权限,密码为 natasha_passw d
对server
mysql -uroot -pwestos
[root@game ~]# mysql -uroot -pwestos
MariaDB [(none)]> CREATE USER mary@‘localhost’ identified by ‘mary_passwd’;
MariaDB [(none)]> CREATE USER natasha@‘172.25.1.10’ identified by ‘natasha_passwd’;
MariaDB [(none)]> SELECT User,Host FROM mysql.user;
MariaDB [(none)]> GRANT SELECT on redhat.* TO natasha@‘172.25.1.10’;
MariaDB [(none)]> GRANT SELECT,INSERT,UPDATE,DROP on redhat.* TO mary@localhost;
MariaDB [(none)]> SHOW GRANTS FOR mary@localhost; ##查看权限
对desktop
desktop客户端:
yum install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
mysql -unatasha -pnatasha_passwd -h 172.25.64.10
7.配置 w eb 服务:
a) 在 ser ver X 上安装 httpd 服务,要求开机自启动,防火墙允许此服务
yum install httpd httpd-manual -y
systemctl start httpd
systemctl enable httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
b) 配置虚拟主机,监听_default_:80,默认发布目录在/var /w w w /htm l,日志位
置在 logs/default-vhost.log,日志格式为 com bined
cd /etc/httpd/conf.d
vim a_default.conf
<VirtualHost default:80>
DocumentRoot /var/www/html
CustomLog logs/default-vhost.log combined
</VirtualHost>
vim /var/www/html/index.html
systemctl restart httpd
c)建立虚拟主机
www X.exam ple.com , 监 听 *:80, 默 认 发 布 目 录 在
/srv/www X.exam ple.com /w w w ,日志存储在 logs/w w w X.exam ple.com .log,
日志格式为 com bined。
vim www1.conf
<VirtualHost :80>
ServerName www1.example.com
DocumentRoot /srv/www1.example.com/www
CustomLog logs/www1.example.com.log combined
</VirtualHost>
<Directory “/srv/www1.example.com/www”>
Require all granted
</Directory>
mkdir /srv/www1.example/www -p
cd /srv/www1.example/www
vim index.html
anything is possible
ls -Zd /var/www/html
semanage fcontext -a -t httpd_sys_content_t '/srv(/.*)?'
restorecon -RvvF /srv
systemctl restart httpd
d) 建立虚拟主机 w ebappX.exam ple.com ,监听*443,
默认发布目录/sr v/w ebappX.exam ple.com /w w w ,
C A 机构证书的位置:
http://classr oom .exam ple.com /pub/exam ple-ca.cr t,
webappX 站点证书和私钥位置在:
http://classr oom .exam ple.com /pub/tls/cer ts/w ebappX.cr t
http://classr oom .exam ple.com /pub/tls/pr ivate/w ebappX.key
私钥的权限是 0600
在访问 w ebappX.exam ple.com 的 80 端口时,会被重定向到 443 端口
下载文件:
http://classr oom .exam ple.com /pub/m ater ials/w ebapp.cgi
并在访问域名 https://w ebappX.exam ple.com 时直接可以看到其运行结
果
yum install mod_ssl -y
yum install crypto-utils -y
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
从老师那里下载下来密钥后,按照题目要求分别放入对应的文件夹
vim /etc/httpd/conf.d/ssl.conf
注释100行和107行
101 SSLCertificateFile /etc/pki/tls/certs/webap1.crt
108 SSLCertificateKeyFile /etc/pki/tls/private/webapp1.key
vim webapp1.conf
<VirtualHost *:443>
SSLEngine on
ServerName webapp1.example.com
DocumentRoot /srv/webapp1.example.com/www
CustomLog logs/webapp.example.com.log combined
SSLCertificateFile /etc/pki/tls/certs/webapp1.crt
SSLCertificateKeyFile /etc/pki/tls/private/webapp1.key
</VirtualHost>
<Directory “/srv/webapp1.example.com/www”>
Require all granted
</Directory>
<VirtualHost *:80>
ServerName webapp1.example.com
RewriteEngine on
RewriteRule ^(/.)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>
8.脚本编程要求如下:
a) 运行 scr ipt1.sh dog 输出结果为 cat
b) 运行 scr ipt1.sh cat 输出结果为 dog 除此以外都输出结果为 er r or
#!/bin/bash
if [ "$1" == "dog" ]
then
echo "cat"
elif [ "$1" != "dog" -a "$1" != "cat" ]
then
echo "dog"
elif [ "$1" != "dog" -a "$1" != "cat" ]
then
echo "error"
fi
**9.**建立用户脚本要求如下:
a) 如果系统存在用户 luck,并且使用/bin/bash,则输出 user ok
b) 如果系统村存在用户 luck,则输出 user exist
c)如果系统不存在用户 luck,则运行 user add luck 命令来创建
d) 当在系统上运行命令 user cm d 时,将输出指令“echo hello;ls-l” 的结果,并
在重启后也生效。