RHCE考试题型及解答

1.进入系统单用户模式,修改 root用户密码为 westosexam ,并设置系统默认进
入多用户模式:
开机时按上下键 在按e
修改vm…那一行 rw rd.break
ctrl+x执行
chroot /sysroot/
passwd 密码为westosexam
touch /.autorelabel
exit两次

2.在 ser ver X 上添加两块虚拟网卡,用以配置主备负载接口 team 0,并分配 ip
地址为 172.25.X.100/24:
再添加两块网卡 eth1 eth2
[root@game ~]# nmcli connection add con-name team0 ifname team0 type team config ‘{“runner”:{“name”:“activebackup”}}’ ip4 172.25.5.100/24

[root@game ~]# nmcli connection add con-name eth1 ifname eth1 type team-slave master team0

[root@game ~]# nmcli connection add con-name eth2 ifname eth2 type team-slave master team0

[root@game ~]# teamdctl team0 stat查看

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
的客户端可以连接,设置ACL允许initiator name为iqn.2018-01.com .exam ple:desktopX 的客户端可以连接
f)desktopX 安装客户端程序,连接 ser ver X 的iSCSI目标资源到本地,用
以创建一个 xfs 文件系统,并开机自动挂载到/iscsidisk

server服务端:
[root@game ~]# yum install targetcli -y
[root@game ~]# systemctl start target
[root@game ~]# systemctl enable target.service
[root@game ~]# fdisk /dev/vdb n添加分区给+1G,t改为8e,wq保存
[root@game ~]# pvcreate /dev/vdb1
[root@game ~]# vgcreate iSCSI_vg /dev/vdb1
[root@game ~]# lvcreate -L 100M -n disk_lv iSCSI_vg
[root@game ~]# targetcli
/> backstores/block create server5.diskl /dev/iSCSI_vg/disk_lv
/> iscsi/ create iqn.2015-01.com.example:server5
/> iscsi/iqn.2015-01.com.example:server5/tpg1/luns create /backstores/block/server5.diskl
/> iscsi/iqn.2015-01.com.example:server5/tpg1/acls create iqn.2018-01.com.example:desktop5
/> iscsi/iqn.2015-01.com.example:server5/tpg1/portals create 172.25.64.11
/> exit
[root@game ~]# firewall-cmd --permanent --add-port=3260/tcp
[root@game ~]# firewall-cmd --reload
接下来两步不一定要作
vim /etc/iscsi/initiatorname.iscsi
改iqn那个
iscsiadm -m discovery -t sp -p 172.25.64.11

desktop客户端:
[root@apache-server ~]# yum search iscsi
[root@apache-server ~]# yum install iscsi-initiator-utils.x86_64 -y
[root@apache-server mnt]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2018-01.com.example:desktop5
[root@apache-server mnt]# systemctl restart iscsid.service
[root@apache-server mnt]# iscsiadm -m discovery -t st -p 172.25.64.11
172.25.64.11:3260,1 iqn.2015-01.com.example:server5
[root@apache-server mnt]# iscsiadm -m node -T iqn.2015-01.com.example:server5 -p 172.25.64.11 -l
[root@apache-server mnt]# fdisk -l
[root@apache-server mnt]# mkfs.xfs /dev/sda
[root@apache-server mnt]# mkdir /iscsidisk
[root@apache-server mnt]# vim /etc/fstab
/dev/sda /iscsidisk xfs defaults,_netdev 0 0
[root@apache-server mnt]# 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 上

server服务端:
[root@game ~]# yum install nfs-utils -y
[root@game ~]# systemctl start nfs-server
[root@game ~]# systemctl enable nfs-server
[root@game ~]# firewall-cmd --permanent --add-service=nfs
[root@game ~]# firewall-cmd --permanent --add-service=ntp
[root@game ~]# firewall-cmd --permanent --add-service=mountd
[root@game ~]# firewall-cmd --permanent --add-service=rpc-bind
[root@game ~]# firewall-cmd --reload
[root@game ~]# mkdir /nfsshare
[root@game ~]# mkdir /autonfs
[root@game ~]# vim /etc/exports
/nfsshare 172.25.64.10(sync,rw)
/autonfs 172.25.64.10(sync,rw)
[root@game ~]# exportfs -rv
exporting 172.25.64.10:/autonfs
exporting 172.25.64.10:/nfsshare

desktop客户端:
[root@apache-server ~]# yum install nfs-utils autofs -y
[root@apache-server ~]# systemctl start autofs
[root@apache-server ~]# systemctl enable autofs.service
[root@apache-server ~]# showmount -e 172.25.64.11
Export list for 172.25.64.11:
/autonfs 172.25.64.10
/nfsshare 172.25.64.10
[root@apache-server ~]# mkdir /mnt/nfsshare
[root@apache-server ~]# vim /etc/fstab
172.25.64.11:/nfsshare /mnt/nfsshare nfs defaults 0 0
[root@apache-server ~]# mount -a
[root@apache-server ~]# vim /etc/auto.master
8 /nfsauto /etc/auto.nfs
[root@apache-server ~]# vim /etc/auto.nfs
server5 -rw 172.25.64.11:/autonfs
[root@apache-server ~]# systemctl restart autofs.service
[root@apache-server /]# cd nfsauto/
[root@apache-server nfsauto]# cd server5/
[root@apache-server server5]# umount /mnt/nfsshare/
[root@apache-server server5]# 查看是否挂载上
172.25.64.11:/autonfs 10473984 3173888 7300096 31% /nfsauto/server5

5.配 SM B 服务:
a) 在 ser ver X 上配置 sm b 共享服务,要求开机自启,防火墙允许此服务
b) 创建共享目录为/smbshare,共享名为smbshar e,工作组为WESTOS,marketing组成员可以读写此共享,不属于marketing组的人只能读
c)创建samba-only用户brian和rob,其中brian用户属于marketing组,用户密码都是westos
d) 在desktopX上建立挂载点/mnt/multiuser目录,开机自动挂载serverX上的smbshare共享,激活smb多用户挂载支持

server服务端:
[root@game ~]# yum install samba samba-common samba-client -y
[root@game ~]# systemctl start smb
[root@game ~]# systemctl enable smb
[root@game ~]# firewall-cmd --permanent --add-service=samba
success
[root@game ~]# firewall-cmd --permanent --add-port=139/tcp
success
[root@game ~]# firewall-cmd --permanent --add-port=445/tcp
success
[root@game ~]# firewall-cmd --reload
success
[root@game ~]# mkdir /smbshare
[root@game ~]# vim /etc/samba/smb.conf
89 workgroup = WESTOS
322 [smbshare]
323 comment= dir share
324 path= /smbshare
325 write list =@marketing
[root@game ~]# groupadd marketing
[root@game ~]# chgrp marketing /smbshare/
[root@game ~]# chmod 2775 /smbshare/
[root@game ~]# semanage fcontext -a -t samba_share_t ‘/smbshare(/.*)?’
[root@game ~]# restorecon -RvvF /smbshare/
[root@game ~]# useradd -s /sbin/nologin brian ##指定用户默认sell(此shell特点是用户不能登陆系统,但能使用某些服务)
[root@game ~]# useradd -s /sbin/nologin rob
echo westos | passwd --stdin brain ##给用户设置密码(stdin:标准输入),这一步也不需要做
echo westos | passwd --stdin rob
[root@game ~]# usermod -g marketing brian
[root@game ~]# smbpasswd -a brian
[root@game ~]# smbpasswd -a rob
[root@game ~]# pdbedit -L
rob:2018:
brian:2017:
[root@game ~]# systemctl restart smb.service

desktop客户端:
[root@apache-server ~]# yum install samba-client cifs-utils -y
[root@apache-server ~]# mkdir /mnt/multiuser
[root@apache-server ~]# smbclient //172.25.64.11/smbshare -U brian
Enter brian’s password:
Domain=[WESTOS] OS=[Unix] Server=[Samba 4.1.1]
smb: > exit
[root@apache-server ~]# smbclient //172.25.64.11/smbshare -U rob
Enter rob’s password:
Domain=[WESTOS] OS=[Unix] Server=[Samba 4.1.1]
smb: > ls
[root@apache-server ~]# vim /root/smbpass
username=brian
password=westos
[root@apache-server ~]# chmod 600 /root/smbpass
[root@apache-server ~]# cifscreds add -u brian 172.25.64.11 ##给root添加brian用户的挂载认证
[root@apache-server ~]# vim /etc/fstab
//172.25.64.11/smbshare /mnt/multiuser cifs credentials=/root/smbpass,sec=ntlmssp,multiuser 0 0
[root@apache-server ~]# mount -a

6.配置 M ar iadb 数据库服务:
a) 在serverX上安装mariadb数据库,开机自启动,防火墙允许此服务
b) 给 数 据 库 设 置 r oot 管理员密码为westos,限制root用户只能从localhost登录,移除匿名用户,删除test库
c) 创建一个名为redhat的库,并从备份文件中恢复数据到此数据库,备份文件的位置在:http://classr oom .exam ple.com /pub/m ater ials/m ar iadb/m ar iadb.dum p 。
d) 创建数据库用户mary,对redhat数据库具有查询、插入、更新、删除
权限,密码为mary_passwd.natasha用户可以从desktopX上登录数据库,对redhat库拥有查询权限,密码为natasha_passwd

server服务端:
[root@game ~]# yum install mariadb-server -y
[root@game ~]# systemctl start mariadb
[root@game ~]# systemctl enable mariadb
[root@game ~]# firewall-cmd --permanent --add-service=mysql
root@game ~]# firewall-cmd --reload
[root@game ~]# netstat -antlupe | grep mysql
[root@game ~]# mysql_secure_installation ##第一个回车,后面都是y
[root@game ~]# vim /etc/my.cn
10 skip-networking=1
[root@game ~]# systemctl restart mariadb.service
[root@game ~]# mysql -uroot -pwestos -e “CREATE database redhat;”
[root@game ~]# mysql -uroot -pwestos -e “SHOW DATABASES;”
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| redhat |
[root@game ~]# mysql -uroot -pwestos redhat</mnt/mariadb.dump
[root@game ~]# mysql -uroot -pwestos
MariaDB [(none)]> CREATE USER mary@‘localhost’ identified by ‘mary_passwd’;
MariaDB [(none)]> CREATE USER natasha@‘172.25.64.10’ identified by ‘natasha_passwd’;
MariaDB [(none)]> SELECT User,Host FROM mysql.user;
±--------±-------------+
| User | Host |
±--------±-------------+
| root | 127.0.0.1 |
| natasha | 172.25.64.10 |
| root | ::1 |
| mary | localhost |
| root | localhost |
±--------±-------------+
MariaDB [(none)]> GRANT SELECT on redhat.* TO natasha@‘172.25.64.10’;
MariaDB [(none)]> GRANT SELECT,INSERT,UPDATE,DROP on redhat.* TO mary@localhost;
MariaDB [(none)]> SHOW GRANTS FOR mary@localhost; ##查看权限

desktop客户端:
[root@apache-server ~]# yum install mariadb-server -y
[root@apache-server ~]# systemctl start mariadb
[root@apache-server ~]# systemctl enable mariadb
[root@apache-server ~]# mysql -unatasha -pnatasha_passwd -h 172.25.64.10

7.配置 w eb 服务:
a) 在 ser ver X 上安装 httpd 服务,要求开机自启动,防火墙允许此服务
b) 配置虚拟主机,监听_default_:80,默认发布目录在/var /w w w /htm l,日志位
置在 logs/default-vhost.log,日志格式为 com bined
c)建立虚拟主机
wwwX.example.com ,监听*:80,默认发布目录在/srv/wwwX.example.com/www,日志存储在logs/wwwX.example.com.log,日志格式为combined。
d) 建立虚拟主机webappX.example.com ,监听*443,
默认发布目录/srv/w ebappX.example.com/www,
C A 机构证书的位置:
http://classroom .example.com/pub/exam ple-ca.cr t,
w ebappX 站点证书和私匙位置在:
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在访问webappX.example.com的80端口时,会被重定向到443端口
下载文件:http://classroom.example.com/pub/materials/webapp.cgi
并在访问域名 https://w ebappX.exam ple.com 时直接可以看到其运行结

(a):
[root@game ~]# yum install httpd httpd-manual -y
[root@game ~]# systemctl start httpd
[root@game ~]# systemctl enable httpd
[root@game ~]# firewall-cmd --permanent --add-service=http
[root@game ~]# firewall-cmd --reload

(b):

[root@game ~]# cd /etc/httpd/conf.d
[root@game conf.d]# vim a_default.conf
<VirtualHost default:80
DocumentRoot /var/www/html
CustomLog logs/default-vhost.log combined
</VirtualHost
[root@game conf.d]# vim /var/www/html/index.html
[root@game conf.d]# systemctl restart httpd

©:

[root@game conf.d]# vim www5.conf
<VirtualHost :80
ServerName www5.example.com
DocumentRoot /srv/www5.example.com/www
CustomLog logs/www5.example.com.log combined
</VirtualHost
<Directory “/srv/www5.example.com/www”
Require all granted
</Directory
[root@game conf.d]# mkdir /srv/www5.example/www -p
[root@game conf.d]# cd /srv/www5.example/www
[root@game www]# vim index.html
h1>www5.example.com</h1
[root@game www]# ls -Zd /var/www/html
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
[root@game www]# semanage fcontext -a -t httpd_sys_content_t ‘/srv(/.*)?’
[root@game www]# restorecon -RvvF /srv
[root@game www]# systemctl restart httpd

(d):

[root@game conf.d]# yum install mod_ssl -y
[root@game conf.d]# yum install crypto-utils -y
[root@game conf.d]# firewall-cmd --permanent --add-service=https
[root@game conf.d]# firewall-cmd --reload
生成密钥方式一:执行命令genkey webapp5.example.com
生成密钥方式二:从老师那拷贝http://classr oom .exam ple.com /pub/tls/cer ts/w ebappX.cr t;http://classr oom .exam ple.com /pub/tls/private/webappX.key分别拷贝到/etc/pki/tls/certs/和/etc/pki/tls/private/两个目录下
[root@game conf.d]# vim /etc/httpd/conf.d/ssl.conf
注释掉100行和107行
101 SSLCertificateFile /etc/pki/tls/certs/webap5.crt
108 SSLCertificateKeyFile /etc/pki/tls/private/webapp5.key
[root@game conf.d]# vim webapp5.conf
<VirtualHost :443(冒号前有个星号)
SSLEngine on
ServerName webapp5.example.com
DocumentRoot /srv/webapp5.example.com/www
CustomLog logs/webapp.example.com.log combined
SSLCertificateFile /etc/pki/tls/certs/webapp5.crt
SSLCertificateKeyFile /etc/pki/tls/private/webapp5.key
</VirtualHost
<Directory “/srv/webapp5.example.com/www”>
Require all granted
</Directory
<VirtualHost :80(冒号前有个星号)
ServerName webapp5.example.com
RewriteEngine on
RewriteRule ^(/.)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost
(第七题所有的解答内容每一个小于号结尾都有一个大于号,它们成对出现,只是我没有写而已,不知道为什么我都写上的话别人就看不到里面的内容,所以此处我用文字说明一下)
[root@game srv]# mkdir /srv/webapp5.example.com/www -p
从老师那下载webapp.cgi文件到/srv/webapp5.example.com/www/目录下
[root@game srv]# semanage fcontext -a -t httpd_sys_content_t '/srv/webapp5.example.com/www(/.
)?’
[root@game srv]# restorecon -RvvF /srv/webapp5.example.com/www
[root@game srv]# cd /srv/webapp5.example.com/www/
[root@game www]# chmod +x webapp5.cgi
[root@game www]# systemctl restart httpd

8.脚本编程要求如下:
a)运行 script1.sh dog输出结果为cat
b)运行 scr ipt1.sh cat输出结果为 dog 除此以外都输出结果为 error
[root@server5 Desktop]# vim script1.sh
#!/bin/bash
if [ “$1” == “dog”]
then
echo “cat”
elif
[ “$1” == “cat” ]
then
echo “dog”
elif
[ “$1” != “dog” -a “$1” != “cat” ]
then
echo “error”
fi
测试:
[root@server5 ~]# sh script1.sh dog
cat
[root@server5 ~]# sh script1.sh cat
dog
[root@server5 ~]# sh script1.sh yy
error
9.建立用户脚本要求如下:
a)如果系统存在用户 luck,并且使用/bin/bash,则输出 user ok
b)如果系统村存在用户 luck,则输出 user exist
c)如果系统不存在用户 luck,则运行 user add luck 命令来创建
d)当在系统上运行命令 user cm d 时,将输出指令“echo hello;ls-l” 的结果,并
在重启后也生效。

猜你喜欢

转载自blog.csdn.net/y_yang666/article/details/84986342