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 主機組中主機上的所有軟件包更新為最新版本
解答:

推薦閱讀