RHCE习题

RHCE习题考试说明:RH294系统信息在练习期间,您将操作下列虚拟系统:真实机: foundation:kiosk:redhatroot: Asimov
workstation.lab.example.com 172.25.250.9 Ansible control nodeservera.lab.example.com 172.25.250.10 Ansible managed nodeserverb.lab.example.com 172.25.250.11 Ansible managed nodeserverc.lab.example.com 172.25.250.12 Ansible managed nodeserverd.lab.example.com 172.25.250.13 Ansible managed nodebastion.lab.example.com 172.25.250.254 Ansible managed node
workstation为ansible节点servera、serverb、serverc、serverd、bastion为受控主机已经全部配置好ssh的基于密钥认证
Ansible 控制节点上已创建了用户帐户 student 。此帐户预装了 SSH密钥 , 允许在 Ansible 控制节点和各个 Ansible 受管节点之间进行SSH 登录 。请勿对系统上的 student SSH 配置文件进行任何修改 。您可以从 root 帐户使用 su 访问此用户帐户
二、前提环境准备1、
[kiosk@foundation ~]$ virt-manager[kiosk@foundation ~]$ rht-vmctl reset all输入y确认重置所有主机[kiosk@foundation ~]$ ssh -X root@workstation[root@workstation ~]# dnf install -y ansible[root@workstation ~]# vim /etc/sudoers.d/studentstudent ALL=(ALL) NOPASSWD: ALL[root@workstation ~]# for i in server{a..d} bastion> do scp /etc/sudoers.d/student root@$i:/etc/sudoers.d/> done2、更改workstation、servera、serverb、serverc、serverd、bastion主机的/etc/hosts文件,把文件中content.example.com对应的ip改为172.25.254.250
[root@workstation ~]# for i in server{a..d} bastion> do scp /etc/hosts root@$i:/etc/hosts> done3、使用xshell将考试环境需要的那些文件都上传到/content/目录下
4、关闭bastion的httpd服务
sshroot@bastionsystemctlstophttpdsystemctldisable httpd正式答题1、安装和配置Ansible按照下方所述,在控制节点workstation.lab.example.com 上安装和配置Ansible:安装所需的软件包创建名为/home/student/ansible/inventory的静态清单文件, 以满足以下需求:servera是dev主机组的成员serverb是test主机组的成员serverc和serverd是prod主机组的成员bastion是balancers主机组的成员prod组是webservers主机组的成员创建名为/home/student/ansible/ansible.cfg的配置文件, 以满足以下要求:主机清单文件为/home/student/ansible/inventoryplaybook中使用的角色的位置包括/home/student/ansible/roles
解答:[student@workstation ~]$ mkdir ansible[student@workstation ~]$ cd ansible[student@workstation ansible]$ cp /etc/ansible/ansible.cfg/home/student/ansible/[student@workstation ansible]$ mkdir /home/student/ansible/roles[student@workstation ansible]$ vi ansible.cfg[defaults]inventory = /home/student/ansible/inventoryremote_user = studentroles_path = /home/student/ansible/roleshost_key_checking = false[privilege_escalation]become = truebecome_method = sudobecome_user = rootbecome_ask_pass = false[student@workstation ansible]$ vim inventory[dev]servera[test]serverb[prod]servercserverd[balancers]bastion[webservers:children]prod验证:[student@workstation ansible]$ ansibleall-mping2、创建和运行Ansible临时命令作为系统管理员, 您需要在受管节点上安装软件.请按照下方所述, 创建一个名为/home/student/ansible/adhoc.sh的shell脚本,该脚本将使用Ansible临时命令在各个受管节点上安装yum存储库:存储库1:存储库的名称为 rh294_BASE描述为 rh294 base software基础URL为 http://content.example.com/rhel8.0/x86_64/dvd/BaseOSGPG签名检查为启用状态GPG密钥URL为 http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release存储库为开启状态存储库2:存储库的名称为 rh294_STREAM描述为 rh294 stream software基础URL为 http://content.example.com/rhel8.0/x86_64/dvd/AppStreamGPG签名检查为启用状态GPG密钥URL为 http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release存储库为开启状态
解答:[student@workstation ansible]$ vim adhoc.sh#!/bin/bashansible all -m yum_repository -a "name=rh294_BASE description='rh294 base software'file=rhel_dvd baseurl=http://content.example.com/rhel8.0/x86_64/dvd/BaseOS gpgcheck=yesgpgkey=http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release enabled=yes"ansible all -m yum_repository -a "name=rh294_STREAM description='rh294 stream software' file=rhel_dvd baseurl=http://content.example.com/rhel8.0/x86_64/dvd/AppStreamgpgcheck=yes gpgkey=http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release enabled=yes"[student@workstation ansible]$ chmod +x adhoc.sh[student@workstation ansible]$ ./adhoc.sh3、安装软件包创建一个名为 /home/student/ansible/packages.yml的 playbook:将 php 和 mariadb 软件包安装到 dev、test 和 prod 主机组中的主机上将 RPM Development Tools 软件包组安装到 dev主机组中的主机上将 dev 主机组中主机上的所有软件包更新为最新版本
解答:

推荐阅读