You are on page 1of 14

资源由 www.eimhe.com 美河学习在线收集提供

RHCE7

1 课程介绍
2 RHEL7的考试分为RHCSA与RHCE两部分,本章节为RHCE。
3 RHCE考试共4小时,总分300分,210分通过。通过RHCSA与RHCE两部分考试后可获得RHCE认证。
4 考试为实验考试,考试中,每个考生会有一台已安装好RHEL7的物理机,在真实机系统中,安装有两台RHEL7虚拟机
,所有实验在虚拟机中完成,考试结束后,虚拟机会被重启,然后评分。所以,所有的实验操作都必须重启后依然
生效,否则,不能得分。
5 您在考试中的两个系统信息如下:
6 servce30.example.com 是一个主要的服务器
7 desktop30.example.com 主要用作客户端
8 两个系统的root密码为redhat,系统的IP地址由DHCP提供,您可以视其为正常,也可以按照以下信息重新设置为静
态IP:
9 servce30.example.com 172.16.30.130/24
10 desktop30.example.com 172.16.30.30/24
11 您的系统是DNS域example.com的成员,所在域中的系统都在子网172.16.30.0/24中,所有要求配置的服务都必须能
被example.com中的系统访问
12 Ldap.example.com提供了集中认证的服务域example.com,两个系统server30与desktop30已预先配置成此域的客户
端,此域提供用户账户guest2001, guest2002, guest2003,密码为redhat
13 防火墙默认是打开的,您认为合适的时候可以关闭,其他关于防火墙的设置可能在单独的要求中。系统重启要要求
能自动进入合适的多用户级别,而无需人工协助,如果考试用的虚拟机不能启动或者不能正常启动,将被计零分。
14 可以使用http://ldap.example.com/dvd/配置您的YUM仓库
15 您将会注意到一些要求明确不允许被域my133t.org访问,这个域中的系统在172.16.1.0/24的子网中。
16 您没有物理机的root密码,普通用户已经自动登录到您的物理机。
17
18 注意:为了简化文档,凡是有需要在两台虚拟机上做相同配置的,都只截取一台机上的操作过程!!!!!!!
19
20
21
22 第一题:SElinux有三种模式,请将server30与desktop30运行与强制模式
23 解答:
24 编辑配置文件/etc/selinux/config,确保SELINUX=enforcing
25 如果初始配置SELINUX=disabled,那么修改后需要重启系统
26 如果初始配置SELINUX=permissive,那么修改后可以执行命令setenforce 1,而不用重启系统
27 #cat /etc/selinux/config
28 SELINUX=enforcing
29 验证:
30 [root@server30 ~]# getenforce
31 Enforcing
32
33
34 第二题:按照以下要求配置SSH:
35 2.1用户能够从域exampl.com内的客户端通过SSH访问您的两个虚拟机系统
36 2.2在域my133t.org内的客户端不能访问您的两个虚拟机系统
37 解答:
38 如果需要严格限制ssh访问,需要使用firewall的rich rule,如下:
39 [root@server30 ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.16.30.0/24
service name=ssh accept' --permanent
40 success
41 [root@server30 ~]# firewall-cmd --remove-service=ssh --permanent
42 success
43 [root@server30 ~]# firewall-cmd --reload
44 success
45 [root@server30 ~]# firewall-cmd --list-all
46 public (default, active)
47 interfaces: eno16777736
48 sources:
49 services: dhcpv6-client
50 ports:
51 masquerade: no
52 forward-ports:
53 icmp-blocks:
54 rich rules:
55 rule family="ipv4" source address="172.16.30.0/24" service name="ssh" accept

Page 1 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

56
57 但是在这里,我们是为应付考试,所以越简单越好,我们只需要使用允许所有来自于域example.com的访问即可,
同时也满足了后续题目中关于防火墙的要求,防火墙的默认策略就是禁止的,所以不需要再去明确禁止my133t.org
这个域,如下:
58 [root@server30 ~]# firewall-cmd --remove-service=ssh --permanent
59 success
60 [root@server30 ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.16.30.0/24
accept' --permanent
61 success
62 [root@server30 ~]# firewall-cmd --reload
63 success
64 [root@server30 ~]# firewall-cmd --list-all
65 public (default, active)
66 interfaces: eno16777736
67 sources:
68 services: dhcpv6-client
69 ports:
70 masquerade: no
71 forward-ports:
72 icmp-blocks:
73 rich rules:
74 rule family="ipv4" source address="172.16.30.0/24" accept
75
76
77 第三题:在系统server30和desktop30上创建自定义命令为psa,此自定义命令将执行/bin/ps –aux,此命令对系统中
所有用户有效。
78 解答:
79 [root@server30 ~]# vim /etc/bashrc ###在文件末尾加入如下内容
80 alias psa='/bin/ps -aux'
81 验证:
82 [root@server30 ~]# su -
83 Last login: Fri Nov 28 20:18:38 CST 2014 from 172.16.30.1 on pts/1
84 [root@server30 ~]# psa |head -2
85 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
86 root 1 0.0 0.3 53776 7604 ? Ss 19:05 0:03 /usr/lib/systemd/systemd
87
88
89
90 第四题:在server30上配置端口转发,在172.16.30.0/24中的系统,访问server30的本地端口5423将被转发到80,
此设置永久生效
91 解答:
92 [root@server30 ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.16.0.30/24
forward-port port=5423 protocol=tcp to-port=80' --permanent
93 success
94 [root@server30 ~]# firewall-cmd --reload
95 success
96 [root@server30 ~]# firewall-cmd --list-all
97 public (default, active)
98 interfaces: eno16777736
99 sources:
100 services: dhcpv6-client
101 ports:
102 masquerade: no
103 forward-ports:
104 icmp-blocks:
105 rich rules:
106 rule family="ipv4" source address="172.16.30.0/24" accept
107 rule family="ipv4" source address="172.16.0.30/24" forward-port port="5423" protocol="tcp"
to-port="80"
108
109
110 第五题:在server30和desktop30 之间按一下要求配置链路聚合:

Page 2 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

111 5.1此链路使用接口slave1和slave2
112 5.2此链路在一个接口失效后,仍然能工作
113 5.3此链路在server30上使用地址192.168.0.11/24
114 5.4此链路在desktop30上使用地址192.168.0.10/24
115 5.5此链路在系统重启后依然保持正常状态
116 解答:
117 [root@server30 ~]# nmcli connection add con-name team0 type team ifname team0 config '{"runner":
{"name": "activebackup"}}'
118 Connection 'team0' (67ed06e9-918c-40e7-b9cf-2497c8794db0) successfully added.
119 [root@server30 ~]# nmcli connection modify team0 ipv4.addresses 192.168.0.11/24 ipv4.method manual
connection.autoconnect yes
120 [root@server30 ~]# nmcli connection add con-name team0-port1 type team-slave ifname eno33554992
master team0
121 Connection 'team0-port1' (73d01446-61ca-4e88-a7fd-b18354c40691) successfully added.
122 [root@server30 ~]# nmcli connection add con-name team0-port2 type team-slave ifname eno50332216
master team0
123 Connection 'team0-port2' (434d5be4-5ba9-4741-a226-813aa0772bca) successfully added.
124 [root@server30 ~]# nmcli connection up team0
125 Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/4)
126
127 在desktop30上执行上边同样的步骤
128 验证:
129 [root@server30 ~]# ping 192.168.0.10
130 PING 192.168.0.10 (192.168.0.10) 56(84) bytes of data.
131 64 bytes from 192.168.0.10: icmp_seq=1 ttl=64 time=1.05 ms
132 64 bytes from 192.168.0.10: icmp_seq=2 ttl=64 time=1.18 ms
133
134
135
136 第六题:在您的考试系统上配置接口eth0使用如下IPv6地址:
137 6.1server30上的IP地址应该是fd00:ba5e:ba11:10::10/64
138 6.2desktop30上的IP地址应该是fd00:ba5e:ba11:10::11/64
139 6.3两个系统必须能与网络fd00:ba5e:ba11:10::fe内的系统通信
140 6.4地址必须在重启后依然生效
141 6.5两个系统保持当前的IPv4地址并能通信
142 解答:
143 [root@server30 ~]# nmcli connection modify eno16777736 ipv6.method manual ipv6.addresses
"fd00:ba5e:ba11:10::10/64"
144 [root@server30 ~]#
145 [root@server30 ~]# nmcli connection up eno16777736
146 Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/7)
147 在desktop30上执行同样的步骤。
148 验证:
149 [root@server30 ~]# ping6 fd00:ba5e:ba11:10::11
150 PING fd00:ba5e:ba11:10::11(fd00:ba5e:ba11:10::11) 56 data bytes
151 64 bytes from fd00:ba5e:ba11:10::11: icmp_seq=1 ttl=64 time=2.77 ms
152 64 bytes from fd00:ba5e:ba11:10::11: icmp_seq=2 ttl=64 time=0.754 ms
153
154
155
156 第七题:7在server30和desktop30上配置邮件服务,满足如下要求:
157 7.1这些系统不接受外部发来的邮件
158 7.2在这些系统上本地发送任何邮件都回被路由到ldap.example.com
159 7.3从这些系统上发送的邮件显示来自于example.com
160 7.4您可以通过发送邮件到dave来测试您的配置
161 7.5您可以通过访问http://ldap.example.com/email/dave来验证您的配置
162 解答:
163 配置YUM,在/etc/yum.repos.d/目录下创建一个以.repo结尾的文件
164 [root@server30 ~]# vim /etc/yum.repos.d/dvd.repo ###包含如下内容
165 [base]

Page 3 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

166 name=base
167 baseurl=http://ldap.example.com/dvd
168 gpgcheck=0
169 安装postfix,配置相关参数:
170 [root@server30 ~]# yum install postfix -y
171 [root@server30 ~]# vim /etc/postfix/main.cf
172 myorigin = example.com
173 mydestination =
174 mynetworks = 127.0.0.0/8
175 relayhost = [ldap.example.com]
176 [root@server30 ~]# postconf -n ###可检查配置错误
177 [root@server30 ~]# systemctl restart postfix.service
178 [root@server30 ~]# systemctl enable postfix.service
179 验证:可在邮件日志中查看是否已经转发至ldap.example.com,也可以再网页中查看
180 [root@server30 ~]# mail -s "test" dave
181 TTTTTTTTTTTTTT
182 EOT
183 [root@server30 Desktop]# firefox http://ldap.example.com/email/dave ###查看是否有刚发送的邮件
184
185
186
187 第八题:在server30上配置SAMBA服务:
188 8.1您的samba服务器必须是STAFF工作组的一个成员
189 8.2共享/common目录,共享名为common
190 8.3只有example.com域内的客户端可以访问common共享
191 8.4Common必须是可以浏览的
192 8.5用户floyd必须能够读取共享中的内容,如果需要的话,验证密码是redhat
193 解答:
194 [root@server30 ~]# yum install samba samba-client -y
195 [root@server30 ~]# mkdir /common
196 [root@server30 ~]# semanage fcontext -a -t samba_share_t '/common(/.*)?'
197 [root@server30 ~]# restorecon -vvFR /common/
198 restorecon reset /common context
unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
199 编辑配置文件修改如下内容:
200 [root@server30 ~]# vim /etc/samba/smb.conf
201 workgroup = STAFF ###修改WORKGROUP为STAFF
202 [common]
203 comment = Common Stuff
204 path = /common
205 browseable = yes
206 valid users = floyd
207 [root@server30 ~]# useradd floyd
208 [root@server30 ~]# smbpasswd -a floyd
209 New SMB password: redhat
210 Retype new SMB password: redhat
211 Added user floyd.
212 [root@server30 ~]# systemctl enable smb.service nmb.service
213 ln -s '/usr/lib/systemd/system/smb.service'
'/etc/systemd/system/multi-user.target.wants/smb.service'
214 ln -s '/usr/lib/systemd/system/nmb.service'
'/etc/systemd/system/multi-user.target.wants/nmb.service'
215 [root@server30 ~]# systemctl start smb.service nmb.service
216
217 验证:
218 [root@server30 ~]# smbclient -L localhost ###不使用任何账户登录能看到共享名common
219 [root@server30 ~]# smbclient //localhost/common -U floyd ###使用floyd用户登录,能查看
common内的文件
220
221
222
223 第九题:配置多用户samba挂载:

Page 4 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

224 9.1在server30上通过samba共享目录/devops
225 9.2共享名为devops
226 9.3共享目录只能被example.com域内的客户端使用
227 9.4共享目录devops必须可以被浏览
228 9.5用户kenji能以读的方式访问此共享,访问密码是redhat
229 9.6用户chihiro能以读写的方式访问此共享,访问密码是redhat
230 9.7此共享永久挂载在desktop30上的/mnt/dev目录,并使用用户kenji进行认证,任何用户可临时通过chihiro来
获得读写权限
231 解答:
232 [root@server30 ~]# mkdir /devops
233 [root@server30 ~]# semanage fcontext -a -t samba_share_t '/devops(/.*)?'
234 [root@server30 ~]# restorecon -vvFR /devops/
235 restorecon reset /devops context
unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
236 因为第二题设置SSH的时候,已经允许了域内用户访问所有本机资源,所以这里不用再考虑防火墙的问题,后面其
他题目,雷同。
237 [root@server30 ~]# vim /etc/samba/smb.conf ###增加如下内容
238 [devops]
239 comment = Devops Stuff
240 path = /devops
241 browseable = yes
242 valid users = kenji, chihiro
243 write list = chihiro
244 [root@server30 ~]# useradd kenji
245 [root@server30 ~]# smbpasswd -a kenji
246 New SMB password:
247 Retype new SMB password:
248 Added user kenji.
249 [root@server30 ~]# useradd chihiro
250 [root@server30 ~]# smbpasswd -a chihiro
251 New SMB password:
252 Retype new SMB password:
253 Added user chihiro.
254 [root@server30 ~]# setfacl -m u:chihiro:rwx /devops/
255
256 Desktop30上:
257 配置YUM,安装cifs-utils
258 [root@desktop30 ~]# yum install cifs-utils -y
259 [root@desktop30 ~]# mkdir /mnt/dev
260 [root@desktop30 ~]# vim /etc/fstab ###增加如下内容
261 //172.16.30.130/devops /mnt/dev cifs
username=kenji,password=redhat,multiuser,sec=ntlmssp 0 0
262
263 验证:
264 [root@desktop30 ~]# mount -a
265 [root@desktop30 dev]# echo dddd > /mnt/dev/ddd ###测试kenji用户写权限
266 -bash: /mnt/dev/ddd: Permission denied
267 [root@desktop30 dev]# cat /mnt/dev/mmm ###测试kenji用户读权限
268 asdfadsf
269 [root@desktop30 dev]# su - student
270 [student@desktop30 ~]$ cifscreds add -u chihiro 172.16.30.130
271 Password:
272 [student@desktop30 ~]$ cat /mnt/dev/mmm ###测试chihiro用户读权限
273 asdfadsf
274 [student@desktop30 ~]$ echo ddddd > /mnt/dev/testfile ###测试chihiro用户写权限
275 [student@desktop30 ~]$ cat /mnt/dev/testfile
276 ddddd
277
278
279
280 第十题:在server30上配置NFS服务
281 10.1以只读的方式共享/public,同时只能被example.com内用户访问

Page 5 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

282 10.2以读写的方式共享/protected能被example.com内用户访问
283 10.3访问/protected需要通过kerberos安全加密,您可以使用下边链接的秘钥:
284 http://ldap.example.com/pub/server30.keytab
285 10.4目录/protected应该包含名为project拥有人为guest2001的子目录
286 10.5用户guest2001能以读写的方式访问/protected/project
287 解答:
288 [root@server30 ~]# yum install nfs-utils -y
289 [root@server30 ~]# mkdir /public
290 [root@server30 ~]# vim /etc/exports ###增加如下内容
291 /public 172.16.30.0/24(ro)
292 [root@server30 ~]# systemctl enable nfs-server.service
293 ln -s '/usr/lib/systemd/system/nfs-server.service'
'/etc/systemd/system/nfs.target.wants/nfs-server.service'
294 [root@server30 ~]# systemctl restart nfs-server.service
295
296 [root@server30 ~]# mkdir /protected
297 [root@server30 ~]# vim /etc/exports
298 /public 172.16.30.0/24(ro)
299 /protected 172.16.30.0/24(rw,sec=krb5p)
300 [root@server30 ~]# wget -O /etc/krb5.keytab http://ldap.example.com/pub/server30.keytab
301 [root@server30 ~]# systemctl restart nfs-server.service
302 [root@server30 ~]# systemctl enable nfs-secure-server.service
303 ln -s '/usr/lib/systemd/system/nfs-secure-server.service'
'/etc/systemd/system/nfs.target.wants/nfs-secure-server.service'
304 [root@server30 ~]# systemctl start nfs-secure-server.service
305 [root@server30 protected]# mkdir project
306 [root@server30 protected]# chown guest2001 project/ ###这里要注意,guest2001是网络用户,所以两台
虚拟机事先都要加入LDAP,考试的时候不需要手动加入
307
308
309
310
311 第十一题:在desktop30上挂载来自于server30的NFS共享:
312 11.1/public挂载在目录/mnt/nfsmount上
313 11.2/protected挂载在目录/mnt/nfssecure,并使用安全的方式,秘钥在
http://ldap.example.com/pub/desktop30.keytab
314 11.3用户guest2001能在/mnt/nfssecure/project上创建文件
315 11.4这些文件系统在系统启动时自动挂载
316 解答
317 [root@desktop30 mnt]# systemctl enable nfs-secure.service
318 ln -s '/usr/lib/systemd/system/nfs-secure.service'
'/etc/systemd/system/nfs.target.wants/nfs-secure.service'
319 [root@desktop30 mnt]# systemctl start nfs-secure.service
320 [root@desktop30 mnt]# mkdir nfsmount
321 [root@desktop30 mnt]# mkdir nfssecure
322 [root@desktop30 mnt]# wget -O /etc/krb5.keytab http://ldap.example.com/pub/desktop30.keytab
323 [root@desktop30 mnt]# vim /etc/fstab
324 172.16.30.130:/public /mnt/nfsmount nfs ro 0 0
325 server30.example.com:/protected /mnt/nfssecure nfs rw,sec=krb5p 0 0
326
327 验证:
328 [root@desktop30 ~]# mount -a
329 [root@desktop30 ~]# df -h
330 Filesystem Size Used Avail Use% Mounted on
331 172.16.30.130:/public 4.9G 3.0G 2.0G 61% /mnt/nfsmount
332 server30.example.com:/protected 4.9G 3.0G 2.0G 61% /mnt/nfssecure
333 [root@desktop30 ~]# ssh guest2001@localhost
334 Last login: Sat Nov 29 00:51:48 CST 2014 on pts/1
335 su: warning: cannot change directory to /rhome/guest2001: No such file or directory
336 mkdir: cannot create directory '/rhome': Permission denied
337
338 -bash-4.2$ cd /mnt/nfssecure/

Page 6 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

339 -bash-4.2$ ll -d project/


340 drwxr-xr-x. 2 guest2001 root 35 Nov 29 00:54 project/
341 -bash-4.2$ cd project/
342 -bash-4.2$ touch testfile
343 -bash-4.2$ ll
344 total 0
345 -rw-rw-r--. 1 guest2001 guest2001 0 Nov 29 00:58 testfile
346
347
348
349
350 第十二题:在server30上配置一个web站点http://server30.example.com
351 12.1从http://ldap.example.com/pub/example.html下载文件,并重命名为index.html,不要修改文件内容。
352 12.2将文件index.html拷贝到您的DocumentRoot目录下
353 12.3来自于example.com的客户端可以访问该web服务器
354 12.4来自于my133t.org的客户端的访问会被拒绝
355 解答:
356 [root@server30 ~]# yum install httpd -y
357 [root@server30 ~]# cd /var/www/html/
358 [root@server30 html]# wget -O index.html http://ldap.example.com/pub/example.html
359 [root@server30 html]# systemctl enable httpd.service
360 ln -s '/usr/lib/systemd/system/httpd.service'
'/etc/systemd/system/multi-user.target.wants/httpd.service'
361 [root@server30 html]# systemctl start httpd.service
362
363
364
365 第十三题:为站点http://server30.example.com配置TLS加密:
366 13.1已签名证书从http://ldap.example.com/pub/server30.crt获取
367 13.2证书的秘钥从http://ldap.example.com/pub/server30.key获取
368 13.3证书的签名授权信息从http://ldap.example.com/pub/group30.crt获取
369 解答:
370 [root@server30 html]# yum install mod_ssl -y
371 [root@server30 html]# vim /etc/httpd/conf.d/ssl.conf ###修改如下几行:
372 DocumentRoot "/var/www/html"
373 ServerName server30.example.com
374 SSLCertificateFile /etc/pki/tls/certs/server30.crt
375 SSLCertificateKeyFile /etc/pki/tls/private/server30.key
376 SSLCACertificateFile /etc/pki/tls/certs/group30.crt
377 [root@server30 html]# cd /etc/pki/tls/certs/
378 [root@server30 certs]# wget http://ldap.example.com/pub/server30.crt
379 [root@server30 certs]# wget http://ldap.example.com/pub/group30.crt
380 [root@server30 certs]# cd /etc/pki/tls/private
381 [root@server30 private]# wget http://ldap.example.com/pub/server30.key
382 [root@server30 private]# systemctl restart httpd
383
384
385
386 第十四题:在server30上扩展您的WEB服务器,为站点http://www.example.com创建一个虚拟主机:
387 14.1设置DocumentRoot为/var/www/virtual
388 14.2从http://ldap.example.com/pub/www.html下载文件,并重命名为index.html,不要修改文件内容。
389 14.3将文件index.html拷贝到DocumentRoot目录下
390 14.4确保floyd用户能够在/var/www/virtual下创建文件
391 14.5注意:原站点server30.example.com必须仍然能够访问
392 解答:
393 [root@server30 private]# cd /etc/httpd/conf.d/
394 [root@server30 conf.d]# vim vhost.conf ####增加如下内容
395 <VirtualHost *:80>
396 DocumentRoot /var/www/html
397 ServerName server30.example.com
398 </VirtualHost>
399

Page 7 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

400 <VirtualHost *:80>


401 DocumentRoot /var/www/virtual
402 ServerName www.example.com
403 </VirtualHost>
404
405 [root@server30 conf.d]# cd /var/www/
406 [root@server30 www]# mkdir virtual
407 [root@server30 www]# cd virtual/
408 [root@server30 virtual]# wget -O index.html http://ldap.example.com/pub/www.html
409 [root@server30 virtual]# systemctl restart httpd
410
411 验证:
412 [root@server30 virtual]# httpd -S
413 VirtualHost configuration:
414 *:443 is a NameVirtualHost
415 default server server30.example.com (/etc/httpd/conf.d/ssl.conf:56)
416 port 443 namevhost server30.example.com (/etc/httpd/conf.d/ssl.conf:56)
417 *:80 is a NameVirtualHost
418 default server server30.example.com (/etc/httpd/conf.d/vhost.conf:1)
419 port 80 namevhost server30.example.com (/etc/httpd/conf.d/vhost.conf:1)
420 port 80 namevhost www.example.com (/etc/httpd/conf.d/vhost.conf:9)
421
422
423
424 第十五题:在您server30上的web服务器的DocumentRoot目录下创建一个名为private的目录,要求:
425 15.1从http://ldap.example.com/pub/private.html下载文件到这个目录,并重命名为index.html,不要修改文
件内容。
426 15.2从server30上,任何人都可以浏览private的内容,但是从其他系统不能访问这个目录的内容
427 解答:
428 [root@server30 virtual]# cd /var/www/html/
429 [root@server30 html]# mkdir private
430 [root@server30 html]# cd private/
431 [root@server30 private]# wget -O index.html http://ldap.example.com/pub/private.html
432 [root@server30 private]# vim /etc/httpd/conf.d/vhost.conf ###修改server30.example.com相关
部分,加入private目录的访问控制
433 <VirtualHost *:80>
434 DocumentRoot /var/www/html
435 ServerName server30.example.com
436 <Directory /var/www/html/private>
437 Require ip 172.16.30.130
438 </Directory>
439 </VirtualHost>
440
441 [root@server30 virtual]# systemctl restart httpd
442
443
444
445 第十六题:在server30上实现动态web内容:
446 16.1动态内容由名为alt.example.com的虚拟主机提供
447 16.2虚拟主机侦听端口为8909
448 16.3从http://ldap.example.com/pub/webapp.wsgi下载一个脚本,然后放在适当的位置,不要修改文件内容
449 16.4客户端访问http://alt.example.com:8909时,应该接收到动态生成的web页面
450 16.5此http://alt.example.com:8909必须能被example.com内所有的系统访问
451 解答:
452 [root@server30 private]# yum install mod_wsgi -y
453 [root@server30 private]# cd /var/www/html/
454 [root@server30 html]# wget http://ldap.example.com/pub/webapp.wsgi
455
456 [root@server30 html]# vim /etc/httpd/conf.d/vhost.conf ###增加如下内容
457 Listen 8909
458 <VirtualHost *:8909>
459 ServerName alt.example.com:8909

Page 8 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

460 WSGIScriptAlias / /var/www/html/webapp.wsgi


461 </VirtualHost>
462 [root@server30 html]# semanage port -a -t http_port_t -p tcp 8909
463 [root@server30 virtual]# systemctl restart httpd
464
465 验证:
466 [root@server30 html]# httpd -S
467 ...
468 ...
469 *:8909 is a NameVirtualHost
470 default server alt.example.com (/etc/httpd/conf.d/vhost.conf:24)
471 port 8909 namevhost alt.example.com (/etc/httpd/conf.d/vhost.conf:24)
472
473
474
475 vhost.conf最终内容:
476 [root@server30 conf.d]# cat vhost.conf
477 <VirtualHost *:80>
478 DocumentRoot /var/www/html
479 ServerName server30.example.com
480 <Directory /var/www/html/private>
481 Require ip 172.16.30.130
482 </Directory>
483 </VirtualHost>
484
485 <VirtualHost *:80>
486 DocumentRoot /var/www/virtual
487 ServerName www.example.com
488 </VirtualHost>
489
490 Listen 8909
491 <VirtualHost *:8909>
492 Servername alt.example.com:8909
493 WSGIScriptAlias / /var/www/html/webapp.wsgi
494 </VirtualHost>
495
496 第十七题:配置server30提供一个iSCSI有服务磁盘名为iqn.2014-09.com.example:server30.并符合下列要求:
497 17.1服务端口为3260
498 17.2使用iscsi_store作为其后端卷其大小为3G
499 17.3此服务只能被desktop30.example.com访问
500 解答:
501 [root@server30 ~]# yum install targetcli -y
502 [root@server30 ~]# fdisk /dev/sda #####创建一个大小为 3GB 的分区
503 Welcome to fdisk (util-linux 2.23.2).
504
505 Changes will remain in memory only, until you decide to write them.
506 Be careful before using the write command.
507
508
509 Command (m for help): p
510
511 Disk /dev/sda: 16.1 GB, 16106127360 bytes, 31457280 sectors
512 Units = sectors of 1 * 512 = 512 bytes
513 Sector size (logical/physical): 512 bytes / 512 bytes
514 I/O size (minimum/optimal): 512 bytes / 512 bytes
515 Disk label type: dos
516 Disk identifier: 0x000a167a
517
518 Device Boot Start End Blocks Id System
519 /dev/sda1 * 2048 411647 204800 83 Linux
520 /dev/sda2 411648 16812031 8200192 8e Linux LVM
521

Page 9 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

522 Command (m for help):


523 Command (m for help): n
524 Partition type:
525 p primary (2 primary, 0 extended, 2 free)
526 e extended
527 Select (default p): p
528 Partition number (3,4, default 3):
529 First sector (16812032-31457279, default 16812032):
530 Using default value 16812032
531 Last sector, +sectors or +size{K,M,G} (16812032-31457279, default 31457279): +3G
532 Partition 3 of type Linux and of size 3 GiB is set
533
534 Command (m for help): w
535 The partition table has been altered!
536
537 Calling ioctl() to re-read partition table.
538
539 WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
540 The kernel still uses the old table. The new table will be used at
541 the next reboot or after you run partprobe(8) or kpartx(8)
542 Syncing disks.
543 [root@server30 ~]# partx /dev/sda
544 NR START END SECTORS SIZE NAME UUID
545 1 2048 411647 409600 200M
546 2 411648 16812031 16400384 7.8G
547 3 16812032 23103487 6291456 3G
548 [root@server30 ~]# partprobe /dev/sda
549 [root@server30 ~]# targetcli
550 Warning: Could not load preferences file /root/.targetcli/prefs.bin.
551 targetcli shell version 2.1.fb34
552 Copyright 2011-2013 by Datera, Inc and others.
553 For help on commands, type 'help'.
554
555 /> cd backstores/block
556 /backstores/block> create iscsi_store /dev/sda3
557 Created block storage object iscsi_store using /dev/sda3.
558 /backstores/block> cd /iscsi
559 /iscsi> create iqn.2014-09.com.example:server30
560 Created target iqn.2014-09.com.example:server30.
561 Created TPG 1.
562 /iscsi> cd iqn.2014-09.com.example:server30/
563 /iscsi/iqn.20...mple:server30> cd tpg1/acls
564 /iscsi/iqn.20...r30/tpg1/acls> create iqn.2014-09.com.example:desktop30
565 Created Node ACL for iqn.2014-09.com.example:desktop30
566 /iscsi/iqn.20...r30/tpg1/acls> cd ../luns
567 /iscsi/iqn.20...r30/tpg1/luns> create /backstores/block/iscsi_store
568 Created LUN 0.
569 Created LUN 0->0 mapping in node ACL iqn.2014-09.com.example:desktop30
570 /iscsi/iqn.20...r30/tpg1/luns> cd ../portals
571 /iscsi/iqn.20.../tpg1/portals> create 172.16.30.130
572 Using default IP port 3260
573 Created network portal 172.16.30.130:3260.
574 /iscsi/iqn.20.../tpg1/portals> ls /
575 o- /
....................................................................................................
.... [...]
576 o- backstores
.............................................................................................
[...]
577 | o- block .................................................................................
[Storage Objects: 1]
578 | | o- iscsi_store ................................................... [/dev/sda3 (3.0GiB)

Page 10 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

write-thru activated]
579 | o- fileio .................................................................................
[Storage Objects: 0]
580 | o- pscsi ..................................................................................
[Storage Objects: 0]
581 | o- ramdisk ................................................................................
[Storage Objects: 0]
582 o- iscsi
............................................................................................
[Targets: 1]
583 | o- iqn.2014-09.com.example:server30
.................................................................. [TPGs: 1]
584 | o- tpg1 ................................................................................
[no-gen-acls, no-auth]
585 | o- acls
.......................................................................................... [ACLs:
1]
586 | | o- iqn.2014-09.com.example:desktop30 .....................................................
[Mapped LUNs: 1]
587 | | o- mapped_lun0 ......................................................... [lun0
block/iscsi_store (rw)]
588 | o- luns
.......................................................................................... [LUNs:
1]
589 | | o- lun0 ...................................................................
[block/iscsi_store (/dev/sda3)]
590 | o- portals
.................................................................................... [Portals: 1]
591 | o- 172.16.30.130:3260
............................................................................... [OK]
592 o- loopback
............................................................................................
[Targets: 0]
593 /iscsi/iqn.20.../tpg1/portals> exit
594 Global pref auto_save_on_exit=true
595 Last 10 configs saved in /etc/target/backup.
596 Configuration saved to /etc/target/saveconfig.json
597
598 [root@server30 ~]# systemctl enable target.service
599 ln -s '/usr/lib/systemd/system/target.service'
'/etc/systemd/system/multi-user.target.wants/target.service'
600 [root@server30 ~]# systemctl start target.service
601
602
603
604 第十八题:配置desktop30使其能连接在server30上提供的iqn.2014-09.com.example:server30并符合以下要求
605 18.1iSCSI设备在系统启动的期间自动加载
606 18.2块设备iSCSI上包含一个大小2100MiB的分区,并格式化为ext4
607 18.3此分区挂载在/mnt/data上同时在系统启动的期间自动加载
608 解答:
609 [root@desktop30 ~]# yum install iscsi-initiator* -y
610 [root@desktop30 ~]# systemctl enable iscsi
611 [root@desktop30 ~]# systemctl start iscsi.service
612 [root@desktop30 ~]# vim /etc/iscsi/initiatorname.iscsi
613 InitiatorName=iqn.2014-09.com.example:desktop30
614
615 [root@desktop30 ~]# iscsiadm -m discovery -t st -p 172.16.30.130
616 172.16.30.130:3260,1 iqn.2014-09.com.example:server30
617 [root@desktop30 ~]# iscsiadm -m node -T iqn.2014-09.com.example:server30 -p 172.16.30.130 -l
618 Logging in to [iface: default, target: iqn.2014-09.com.example:server30, portal: 172.16.30.130,3260]
(multiple)
619 Login to [iface: default, target: iqn.2014-09.com.example:server30, portal: 172.16.30.130,3260]

Page 11 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

successful
620
621 [root@desktop30 ~]# fdisk /dev/sdb ###分出一个2100MB的分区
622 [root@desktop30 ~]# mkfs.ext4 /dev/sdb1
623 [root@desktop30 ~]# mkdir /mnt/data
624 [root@desktop30 ~]# blkid /dev/sdb1 ###查出分区的UUID
625 /dev/sdb1: UUID="19350aab-61e6-4874-93e1-dc24e57b36c9" TYPE="ext4"
626
627 [root@desktop30 ~]# vim /etc/fstab ###增加如下内容
628 UUID="19350aab-61e6-4874-93e1-dc24e57b36c9" /mnt/data ext4 defaults,_netdev 0 0
629
630 [root@desktop30 ~]# df -h
631 Filesystem Size Used Avail Use% Mounted on
632 ...
633 /dev/sdb1 2.0G 6.2M 1.9G 1% /mnt/data
634
635
636 第十九题:写一个简单的脚本,编写一个位于/root/program的shell脚本,要求:
637 当执行/root/program kernel时,终端显示user
638 当执行/root/program user时,终端显示kernel
639 当仅执行/root/program不加参数,或者加上其他参数时,终端显示标准错误输出/root/program kernel|user
640 解答:
641 [root@server30 ~]# vim /root/program
642 #!/bin/bash
643
644 case "$1" in
645 kernel)
646 echo user
647 ;;
648 user)
649 echo kernel
650 ;;
651 *)
652 echo "/root/program kernel|user"
653 exit 1
654 esac
655 exit 0
656
657 [root@server30 ~]# chmod +x /root/program
658
659
660 第二十题:写一个创建用户的脚本,脚本名为/root/mkuser,脚本执行时添加一个参数,
661 如果没有参数,将提示:Usage:/root/mkuser
662 如果参数为不存在的文件,则提示:Input file not found
663 如果存在,则创建用户,用户不需要设置密码,用户的shell为/bin/flase
664 解答:
665 [root@server30 ~]# vim /root/mkuser
666
667 #!/bin/bash
668 if [ $# -eq 0 ]
669 then
670 echo "Usage: /root/mkuser"
671 elif [ -f $1 ]
672 then
673 for username in `cat $1`; do
674 useradd -s /bin/false $username
675 done
676 else
677 echo "Input file not found"
678 fi
679 [root@server30 ~]# chmod +x /root/mkuser
680

Page 12 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

681 验证:
682 [root@server30 ~]# /root/mkuser
683 Usage: /root/mkuser
684 [root@server30 ~]# /root/mkuser sdjfasdf
685 Input file not found
686 [root@server30 ~]# echo ggg >ggg
687 [root@server30 ~]# /root/mkuser ggg
688 [root@server30 ~]# id ggg
689 uid=1004(ggg) gid=1004(ggg) groups=1004(ggg)
690
691
692
693 第二十一题:在server30上创建一个MariaDB数据库,名为contacts,并符合以下条件:
694 21.1数据库应该包含来自数据库复制的内容。复制文件的URL为http://ldap.example.com/pub/user.mdb
695 21.2数据库只能被localhost访问
696 21.3除了root用户,此数据库只能被用户raikon查询,此用户密码为redhat
697 21.4root用户密码为redhat,同时不允许空密码登陆
698 解答:
699 [root@server30 ~]# yum install mariadb mariadb-server -y
700 [root@server30 ~]# systemctl enable mariadb.service
701 ln -s '/usr/lib/systemd/system/mariadb.service'
'/etc/systemd/system/multi-user.target.wants/mariadb.service'
702 [root@server30 ~]# systemctl start mariadb.service
703 [root@server30 ~]# mysql_secure_installation
704 ...
705 Set root password? [Y/n] Y ###设置root密码为redhat
706 Disallow root login remotely? [Y/n] Y ###禁止远程访问
707
708 [root@server30 ~]# wget http://ldap.example.com/pub/user.mdb
709 [root@server30 ~]# mysql -u root -p
710 Enter password:
711 ...
712
713 MariaDB [(none)]> create database contacts;
714 Query OK, 1 row affected (0.00 sec)
715 MariaDB [(none)]> use contacts;
716 Database changed
717 MariaDB [contacts]> source /root/user.mdb;
718 MariaDB [contacts]> GRANT SELECT on contacts.* to 'raikon'@'localhost' IDENTIFIED by 'redhat';
719 Query OK, 0 rows affected (0.01 sec)
720 MariaDB [contacts]> FLUSH PRIVILEGES;
721 Query OK, 0 rows affected (0.00 sec)
722 MariaDB [contacts]> QUIT
723 Bye
724
725
726
727 第二十二题:在server30上使用数据库contacts,并使用相应的sql查询以回答下列问题
728 22.1密码是123456的人的名字
729 22.2有多少人的姓名是barbara同时居住在sunnyvale
730 解答:
731 [root@server30 ~]# mysql -u root -p
732 Enter password:
733 ...
734
735 MariaDB [(none)]> show databases; ###列出所有数据库
736 +--------------------+
737 | Database |
738 +--------------------+
739 | information_schema |
740 | contacts |
741 | mysql |

Page 13 of 14
资源由 www.eimhe.com 美河学习在线收集提供
RHCE7

742 | performance_schema |
743 +--------------------+
744 4 rows in set (0.00 sec)
745
746 MariaDB [(none)]> use contacts ;
747 MariaDB [contacts]> show tables; ###列出所有的表
748 +--------------------+
749 | Tables_in_contacts |
750 +--------------------+
751 | user |
752 +--------------------+
753 1 row in set (0.00 sec)
754 MariaDB [contacts]>
755 MariaDB [contacts]> desc user; ###查看表结构
756 +-----------+-------------+------+-----+---------+-------+
757 | Field | Type | Null | Key | Default | Extra |
758 +-----------+-------------+------+-----+---------+-------+
759 | usernamer | varchar(50) | YES | | NULL | |
760 | password | varchar(50) | YES | | NULL | |
761 | live | varchar(50) | YES | | NULL | |
762 +-----------+-------------+------+-----+---------+-------+
763 3 rows in set (0.00 sec)
764
765 MariaDB [contacts]> select usernamer from user where password='123456';
766 +-----------+
767 | usernamer |
768 +-----------+
769 | harry |
770 +-----------+
771 1 row in set (0.00 sec)
772
773 MariaDB [contacts]> select count(*) from user where usernamer='barbara' and live='sunnyvale';
774 +----------+
775 | count(*) |
776 +----------+
777 | 2 |
778 +----------+
779 1 row in set (0.01 sec)
780
781
782 ==================================================== 完
=========================================================
783

Page 14 of 14

You might also like