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 repo
  hosts: 192.168.178.118
  tasks:
    - name: add base repo
      yum_repository:
        name: base
        description: CentOS-$releasever - Base - mirrors.aliyun.com
        baseurl: http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        gpgcheck: yes
        gpgkey: http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
        enabled: 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 packages
  hosts: dev,test,prod
  tasks: 
  - name: install php mariadb tftp
    yum:
      name:
      - php
      - mariadb
      - tftp
      state: present

- name: install package group
  hosts: dev
  tasks:
  - name: install RPM Development tools group
    yum:
      name: "@RPM Development Tools"
      state: present

- name: upgrade all packages
  hosts: dev
  tasks:
  - name: yum update
    yum:
      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 crontab
  hosts: test
  tasks:
  - name: create user
    user:
      name: natasha
  - name: create crond
    cron:
      name: test
      minute: "*/5"
      job: echo test
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值