rhce 9 考题与解析笔记
本人于4月份完成 rhce 考试,以下是我的备考时刷的题,每题都有附上解题步骤和验证方式,祝大家考试顺利!
一、安装和配置Ansible
题目要求:
解题步骤:
1、安装所需的软件包
# 登录到 root 用户安装ansible
$ ssh control
$ su -
$ yum -y install ansible-core
2、创建静态文件清单
[greg@system2 ~]$ mkdir ansible
[greg@system2 ~]$ cd ansible
[greg@system2 ansible]$ vim inventory
[dev]
node1[test]
node2[prod]
node3
node4[balancers]
node5[webservers:children]
prod
3、创建配置文件
[greg@system2 ansible]$ vim ansible.cfg
[defaults]
inventory=/home/greg/ansible/inventory
remote user= greg
roles_path=/home/greg/ansible/roles:/usr/share/ansible/roles
collections_paths=/home/greg/ansible/collections[privilege_escalation]
become=True
become_method=sudo
become_user=root
become ask_pass=False
验证:
[greg@system2 ansible]$ ansible all -m ping
二、配置软件仓库
题目要求:
解题步骤:
1) 写一个 adhoc.sh 脚本在各个节点上安装yum存储库:
$ vim adhoc.sh
ansible all -m yum_repository -a "name='name1' description='description1' baseurl='baseurl1' gpgcheck=1 gpgkey='gpgkey1'enabled='yes'"ansible all -m yum_repository -a "name='name2' description='description2' baseurl='baseurl2' gpgcheck=1 gpgkey='gpgkey2'enabled='yes'"
2) 写一个 yum.yml 的palybook在各个节点上安装yum存储库:
$ vim yum.yaml
---
- name: set repohosts: 192.168.178.118tasks:- name: add base repoyum_repository:name: basedescription: CentOS-$releasever - Base - mirrors.aliyun.combaseurl: http://mirrors.aliyun.com/centos/$releasever/os/$basearch/gpgcheck: yesgpgkey: http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7enabled: yes$ ansible-playbook yum.yml
验证:
登录到各个节点、检查是否已完成 yum 仓库配置、检查各节点是否可以正常安装应用
$ ansible all -m shell -a 'ls /etc/yum.repos.d'
node2 | CHANGED | rc=0 >>
EX294_BASE.repo
………………$ ansible all -m shell -a "cat /etc/yum.repos.d/EX294_BASE.repo"$ ansible all -m yum -a 'name="wget" state="present"'
三、安装软件包
题目要求:
解题步骤:
$ vim packages.yml
---
- name: install packageshosts: dev,test,prodtasks: - name: install php mariadb tftpyum:name:- php- mariadb- tftpstate: present- name: install package grouphosts: devtasks:- name: install RPM Development tools groupyum:name: "@RPM Development Tools"state: present- name: upgrade all packageshosts: devtasks:- name: yum updateyum:name: '*'state: latest
验证:登录到远程主机检查是否安装了对应的软件/软件包组
# 验证是否安装了各个软件包
$ rpm -q mariadb
mariadb-5.5.68-1.el7.x86_64
$ rpm -q php
php-5.4.16-48.el7.x86_64
$ rpm -q tftp
tftp-5.2-22.el7.x86_64$ ansible dev,test,prod -m shell -a "rpm -qa | grep -e 'php' -e 'mariadb' -e 'tftp'"# 查看是否安装了软件包组
$ yum grouplist
$ ansible dev -m shell -a 'yum grouplist | grep Development'
四、配置计划任务
题目要求:
解题步骤:
$ cat crond.yml
---
- name: create crontabhosts: testtasks:- name: create user