红帽认证RHEL8考题 RHCE8考试题库(RHCE8)

RHCE没有满分,仅供参考,可以评论建议答案,以方便需要考证的朋友。

点击>>>RHCSA考试题库RHEL8.0<<<查看内容

RHCE8.0考试

考试有6台虚拟机,其中一台是需要操作ansible的,考试要求在greg用户下完成操作,其余5台是被控机器node1-5 所有机器密码均为123

安装和配置 Ansible

按照下方所述,在控制节点 control.example.com 上安装和配置 Ansible:

  • 安装所需的软件包
  • 创建名为 /home/greg/ansible/inventory 的静态清单文件,以满足以下要求:
  • node1 是 dev 主机组的成员
  • node2 是 test 主机组的成员
  • node3 和 node4 是 prod 主机组的成员
  • node5 是 balancers 主机组的成员
  • prod 组是 webservers 主机组的成员
  • 创建名为 /home/greg/ansible/ansible.cfg 的配置文件,以满足以下要求:
  • 主机清单文件为 /home/greg/ansible/inventory
  • playbook 中使用的角色的位置包括 /home/greg/ansible/roles

$ sudo yum install -y ansible
$ mkdir -p /home/greg/ansible/roles
$ cd /home/greg/ansible
$ cp /etc/ansible/ansible.cfg .
$ vim /home/greg/ansible/inventory
[all:vars]
ansible_password=123
[dev]
node1
[test]
node2
[prod]
node3
node4
[balancers]
node5
[webservers:children]
prod
#保存,退出
$ vim ansible.cfg
[defaults]
inventory = /home/greg/ansible/inventory
roles_path = /home/greg/ansible/roles
host_key_checking = False
remote_user = root
#保存,退出

创建和运行 Ansible 临时命令

为系统管理员,您需要在受管节点上安装软件。
照正文所述,创建一个名为 /home/greg/ansible/adhoc.sh 的 shell 脚本,该脚本将使用 Ansible 临时命令在各个受管节点上安装 yum 存储库:
储存库1:

  • 存储库的名称为 EX294_BASE
  • 描述为 EX294 base software
  • 基础 URL 为 http://xxx.example.com.com/BaseOS
  • GPG 签名检查为启用状态
  • GPG 密钥 URL 为 http://xxx.example.com/RHEL/RPM-GPG-KEY-redhat-release
  • 存储库为启用状态

存储库2:

  • 存储库的名称为 EX294_STREAM
  • 描述为 EX294 stream software
  • 基础 URL 为 http://xxx.example.com.com/AppStream
  • GPG 签名检查为启用状态
  • GPG 密钥 URL 为 http://xxx.example.com/RHEL/RPM-GPG-KEY-redhat-release
  • 存储库为启用状态
vim /home/greg/ansible/adhoc.sh

#!/bin/bash
ansible all -m yum_repository -a \
'name="EX294_BASE" \
description="EX294 base software" \
baseurl="http://xxx.example.com.com/BaseOS" \
gpgcheck=yes \
gpgkey="http://xxx.example.com/RHEL/RPM-GPG-KEY-redhat-release" \
enable=yes'
ansible all -m yum_repository -a \
'name="EX294_STREAM" \
description="EX294 stream software" \
baseurl="xxx.example.com/AppStream" \
gpgcheck=yes \
gpgkey="http://xxx.example.com/RHEL/RPM-GPG-KEY-redhat-release" \
enable=yes'

安装软件包

创建一个名为 /home/greg/ansible/packages.yml 的 playbook :

  • 将 php 和 mariadb 软件包安装到 dev、test 和 prod 主机组中的主机上
  • 将 RPM Development Tools 软件包组安装到 dev 主机组中的主机上
  • 将 dev 主机组中主机上的所有软件包更新为最新版本
vim /home/greg/ansible/packages.yml
---
- name: 安装软件包
  hosts: dev,test,prod 
  tasks:
  - name: install the latest version
    yum:
      name: "{{ item }}"
      state: latest
    loop:
    - php
    - mariadb
  - block:
    - name: install the '@RPM Development Tools' package group
      yum:
        name: "@RPM Development Tools"
        state: present
      when: "'dev' in group_names"
    - name: upgrade all packages
      yum:
        name: '*' 
        state: latest
    when: "'dev' in group_names"
ansible-playbook /home/greg/ansible/packages.yml

使用 RHEL 系统角色

安装 RHEL 系统角色软件包,并创建符合以下条件的 playbook /home/greg/ansible/timesync.yml :

  • 在所有受管节点上运行
  • 使用 timesync 角色
  • 配置该角色,以使用当前有效的 NTP 提供商
  • 配置该角色,以使用时间服务器 172.20.20.254
  • 配置该角色,以启用 iburst 参数
$ sudo yum -y install rhel-system-roles
$ vim ansible.cfg
#roles_path  = /home/greg/ansible/roles:/usr/share/ansible/roles
$ ansible-galaxy list
$ cp /usr/share/doc/rhel-system-roles/timesync/example-timesync-playbook.yml /home/greg/ansible/timesync.yml
$ vim /home/greg/ansible/timesync.yml
---
- hosts: all
  vars:
    timesync_ntp_servers:
      - hostname: 172.20.20.254
        iburst: yes
  roles:
    - rhel-system-roles.timesync
ansible-playbook /home/greg/ansible/timesync.yml

创建和使用角色

根据下列要求,在 /home/greg/ansible/roles 中创建名为 apache 的角色:

  • httpd 软件包已安装,设为在系统启动时启用并启动

  • 防火墙已启用并正在运行,并使用允许访问 Web 服务器的规则

  • 模板文件 index.html.j2 已存在,用于创建具有以下输出的文件 /var/www/html/index.html :
    Welcome to HOSTNAME on IPADDRESS
    其中,HOSTNAME 是受管节点的完全限定域名,IPADDRESS 则是受管节点的 IP 地址。

  • 创建 playbook /home/greg/ansible/apache.yml ,使用apache 的角色,在 webservers 主机组。

$ cd roles/
$ ansible-galaxy init apache
$ cd ..
$ ansible-galaxy list
$ vim roles/apache/tasks/main.yml
---
- name: install the latest version of Apache
  yum:
    name: httpd
    state: latest
- name: Start service httpd, if not started
  service:
    name: httpd
    state: started
    enabled: yes
- firewalld:
    service: http
    permanent: yes
    state: enabled
    immediate: yes
- name: Template a file
  template:
    src: index.html.j2
    dest: /var/www/html/index.html
$ vim roles/apache/templates/index.html.j2
# Welcome to {{ ansible_fqdn }} on {{ ansible_default_ipv4.address }}
vim /home/greg/ansible/apache.yml
---
- name: 使用角色
  hosts: webservers
  roles:
  - apache
$ ansible-playbook /home/greg/ansible/apache.yml

从 Ansible Galaxy 使用角色

根据下列要求,创建一个名为 /home/greg/ansible/roles.yml 的 playbook :

  • playbook 中包含一个 play, 该 play 在 balancers 主机组中的主机上运行并将使用 balancer 角色。
  • 此角色配置一项服务,以在 webservers 主机组中的主机之间平衡 Web 服务器请求的负载。
  • 浏览到 balancers 主机组中的主机(例如 http://node5.example.com/)将生成以下输出:
    Welcom to node3.example.com on 172.24.22.8
  • 重新加载浏览器将从另一 Web 服务器生成输出:
    Welcom to node4.example.com on 172.24.22.9
  • playbook 中包含一个 play, 该 play 在 webservers 主机组中的主机上运行并将使用 phpinfo 角色。
  • 请通过 URL /hello.php 浏览到 webservers 主机组中的主机将生成以下输出:
    Hello PHP World from FQDN
    其中,FQDN 是主机的完全限定名称。
  • 例如,浏览到 http://node3.example.com/hello.php 会生成以下输出:
    Hello PHP World from node3.example.com
    另外还有 PHP 配置的各种详细信息,如安装的 PHP 版本等。
  • 同样,浏览到 http://node4.example.com/hello.php 会生成以下输出:
    Hello PHP World from
    node4.example.com
    另外还有 PHP 配置的各种详细信息,如安装的 PHP 版本等
$ vim /home/greg/ansible/roles.yml
---
- name: one
  hosts: webservers
  roles:
  - apache

- name: two
  hosts: balancers
  roles:
  - balancer

- name:  san
  hosts: webservers
  roles:
  - phpinfo
$ ansible-playbook roles.yml

创建和使用逻辑卷

创建一个名为 /home/greg/ansible/lv.yml 的 playbook ,它将在所有受管节点上运行以执行下列任务:

  • 创建符合以下要求的逻辑卷:
  • 逻辑卷创建在 research 卷组中
  • 逻辑卷名称为 data
  • 逻辑卷大小为 1500 MiB
  • 使用 ext4 文件系统格式化逻辑卷
  • 如果无法创建请求的逻辑卷大小,应显示错误信息
    Could not create logical volume of that size,并且应改为使用大小 800 MiB。
  • 如果卷组 research 不存在,应显示错误信息
    Volume group done not exist。
  • 不要以任何方式挂载逻辑卷
$ vim /home/greg/ansible/lv.yml
---
- name: 创建和使用逻辑卷
  hosts: all
  tasks:
  - block:
    - name: Create a logical volume of 1500m
      lvol:
        vg: research
        lv: data
        size: 1500
    - name: Create a ext4
      filesystem:
        fstype: ext4
        dev: /dev/research/data
    rescue:
    - debug:
        msg: Could not create logical volume of that size
    - name: Create a logical volume of 800m
      lvol:
        vg: research
        lv: data
        size: 800
      when: ansible_lvm.vgs.research is defined
      ignore_errors: yes
    - debug:
        msg: Volume group done not exist
      when: ansible_lvm.vgs.research is undefined
$ ansible-playbook /home/greg/ansible/lv.yml

生成主机文件

生成主机文件

  • 将一个初始模板文件从 http://rhgls.realm8.example.com/materials/hosts.j2 下载到 /home/greg/ansible
  • 完成该模板,以便用它生成以下文件:针对每个清单主机包含一行内容,其格式与 /etc/hosts 相同
  • 创建名为 /home/greg/ansible/hosts.yml 的 playbook ,它将使用此模板在 dev 主机组中的主机上生成文件 /etc/myhosts 。
    该 playbook 运行后, dev 主机组中主机上的文件 /etc/myhosts 应针对每个受管主机包含一行内容:
    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
    172.242.6 node1.realm8.example.com node1
    172.242.7 node2.realm8.example.com node2
    172.242.8 node3.realm8.example.com node3
    172.242.9 node4.realm8.example.com node4
    172.242.10 node5.realm8.example.com node5
    注:清单主机名称的显示顺序不重要。
$ wget http://materials/hosts.j2
$ vim hosts.j2
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_facts']['default_ipv4']['address'] }} {{ hostvars[host]['ansible_facts']['fqdn'] }} {{ hostvars[host]['ansible_facts']['hostname'] }}
{% endfor %}
$ vim hosts.yml
---
- name: 生成主机文件
  hosts: all 
  tasks:
  - name: Template a file to /etc/myhosts
    template:
      src: /home/greg/ansible/hosts.j2
      dest: /etc/myhosts
    when: '"dev" in group_names'
$ ansible-playbook hosts.yml 

<–未完待续–>

点击RHCSA考试题库RHEL8.0查看考题

发布了3 篇原创文章 · 获赞 5 · 访问量 1763

猜你喜欢

转载自blog.csdn.net/qq_37789137/article/details/103709719