导航菜单
首页 >  rhce8考试题库  > RHCE8练习题

RHCE8练习题

在系统上执行以下任务。

目录

1、安装和配置 Ansible

2、创建和运行 Ansible 临时命令

3、安装软件包

4、使用 RHEL 系统角色

5、使用 Ansible Galaxy 安装角色

6、创建和使用角色

7、从 Ansible Galaxy 使用角色

8、创建和使用逻辑卷

9、生成主机文件

10、修改文件内容

11、创建 Web 内容目录

12、生成硬件报告

14、创建用户帐户

15、更新 Ansible 库的密

1、安装和配置 Ansible

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

安装所需的软件包

创建名为 /home/greg/ansible/inventory 的静态清单文件,以满足以下要求:

172.25.250.9 是 dev 主机组的成员

172.25.250.10 是 test 主机组的成员

172.25.250.11 和 172.25.250.12 是 prod 主机组的成员

172.25.250.13 是 balancers 主机组的成员

prod 组是 webservers 主机组的成员

创建名为 /home/greg/ansible/ansible.cfg 的配置文件,以满足以下要求:

主机清单文件为 /home/greg/ansible/inventory

playbook 中使用的角色的位置包括 /home/greg/ansible/roles

[kiosk@foundation0 ~]$ ssh greg@172.25.250.254Activate the web console with: systemctl enable --now cockpit.socket启动所有的虚拟机:手动:virt-manager  或者   命令:rht-vmctl start all#登录root用户装包[greg@bastion ~]$ su -Password: Last login: Fri Mar 31 11:17:37 GMT 2023 from 172.25.250.250 on pts/0[root@bastion ~]$ sudo yum install -y ansible#返回grep用户[root@bastion ~]# exitlogout检查:[greg@bastion ~]$ ansible --versionansible 2.8.0 config file = /etc/ansible/ansible.cfg configured module search path = ['/home/greg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.6/site-packages/ansible executable location = /usr/bin/ansible python version = 3.6.8 (default, Apr 3 2019, 17:26:03) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)] #创建目录并在目录下创建清单文件 [greg@bastion ~]$ mkdir ansible [greg@bastion ~]$ cd ansible [greg@bastion ansible]$ cat inventory[dev]172.25.250.9[test]172.25.250.10[prod]172.25.250.11172.25.250.12[balancers]172.25.250.13[webservers:children]prod[all:vars]ansible_user=rootansible_password=redhat # 填写考试环境提供的密码。(粘贴到虚拟机时要删除注释) #从ansible中复制配置文件[greg@bastion ansible]$ cp /etc/ansible/ansible.cfg ./[greg@bastion ansible]$ vim ansible.cfg [defaults]inventory = /home/greg/ansible/inventoryroles_path= /home/greg/ansible/roleshost_key_checking = False #主机是否校验[greg@bastion ansible]$ mkdir /home/greg/ansible/roles测试:[greg@bastion ansible]$ ansible-inventory --graph@all: |--@balancers: | |--172.25.250.13 |--@dev: | |--172.25.250.9 |--@test: | |--172.25.250.10 |--@ungrouped: |--@webservers: | |--@prod: | | |--172.25.250.11 | | |--172.25.250.12#使用ansible ping所有主机,-m:模块 -o:所有主机[greg@bastion ansible]$ ansible all -m ping -o172.25.250.13 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}172.25.250.12 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}172.25.250.11 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}172.25.250.10 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}172.25.250.9 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"} 2、创建和运行 Ansible 临时命令

作为系统管理员,您需要在受管节点上安装软件。

请按照正文所述,创建一个名为 /home/greg/ansible/adhoc.sh 的 shell 脚本,该脚本将使用 Ansible 临时命令在各个受管节点上安装 yum 存储库:

存储库1:

存储库的名称为 EX294_BASE

描述为 EX294 base software

基础 URL 为 http://content/rhel8.0/x86_64/dvd/BaseOS

GPG 签名检查为启用状态

GPG 密钥 URL 为 http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release

存储库为启用状态

存储库2:

存储库的名称为 EX294_STREAM

描述为 EX294 stream software

基础 URL 为 http://content/rhel8.0/x86_64/dvd/AppStream

GPG 签名检查为启用状态

GPG 密钥 URL 为 http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release

存储库为启用状态

#配置仓库 :仓库1和仓库2[greg@bastion ansible]$ cat adhoc.sh#!/bin/bashansible all -m yum_repository -a 'name=EX294_BASE description="EX294 base software" \baseurl=http://content/rhel8.0/x86_64/dvd/BaseOS \gpgcheck=yes \gpgkey=http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release \enabled=yes'ansible all -m yum_repository -a 'name=EX294_STREAM description="EX294 stream software" \baseurl=http://content/rhel8.0/x86_64/dvd/AppStream \gpgcheck=yes \gpgkey=http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release \enabled=yes'-m :-a : 指定参数description: 描述gpgcheck=yes: GPG 签名检查为启用状态enabled=yes : 存储库为启用状态[greg@bastion ansible]$ chmod +x /home/greg/ansible/adhoc.sh[greg@bastion ansible]$ ./adhoc.sh 检查:#查看机器仓库[greg@bastion ansible]$ ansible all -m shell -a 'yum repolist' [WARNING]: Consider using the yum module rather than running 'yum'. If you need to use command because yum is insufficient you can add 'warn:false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.172.25.250.13 | CHANGED | rc=0 >>repo id repo name statusEX294_BASE EX294 base software1,658EX294_STREAMEX294 stream software 4,672EX294 base software 7.0 MB/s | 2.2 MB 00:00EX294 stream software8.0 MB/s | 5.3 MB 00:00Last metadata expiration check: 0:00:02 ago on Sat 04 Dec 2021 10:17:47 AM GMT. 3、安装软件包

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

将 php 和 mariadb 软件包安装到 dev、test 和 prod 主机组中的主机上

将 RPM Development Tools 软件包组安装到 dev 主机组中的主机上

将 dev 主机组中主机上的所有软件包更新为最新版本

#按一个tab即是2个空格[greg@bastion ansible]$ cat ~/.vimrcautocmd FileType yaml setlocal ai ts=2 sw=2 et[greg@bastion ansible]$ vim /home/greg/ansible/packages.yml---- name: dev、test 、prod hosts: dev,test,prod tasks:- name: install php mariadb yum:name: - php - mariadb- name: dev hosts: dev tasks:- name: install RPM Development Tools yum:name: '@RPM Development Tools'- name: upgrade all packages yum:name: '*'state: latest[greg@bastion ansible]$ ansible-playbook packages.yml --syntax-checkplaybook: packages.yml[greg@bastion ansible]$ ansible-playbook packages.yml 4、使用 RHEL 系统角色

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

在所有受管节点上运行

使用 timesync 角色

配置该角色,以使用当前有效的 NTP 提供商

配置该角色,以使用时间服务器 172.25.254.254

配置该角色,以启用 iburst 参数

[greg@bastion ~]$ yum list | grep rolepolicycoreutils-newrole.x86_642.8-16.1.el8 rhel-8.0-for-x86_64-baseos-rpmsrhel-system-roles.noarch 1.0-5.el8rhel-8.0-for-x86_64-appstream-rpms [greg@bastion ~]$ sudo yum install rhel-system-roles.noarch -y[greg@bastion ~]$ rpm -qa | grep rhel-system-rolesrhel-system-roles-1.0-5.el8.noarch[greg@bastion ~]$ rpm -ql rhel-system-roles-1.0-5.el8.noarch[greg@bastion ansible]$ vim ansible.cfg roles_path= /home/greg/ansible/roles:/usr/share/ansible/roles测试:[greg@bastion ansible]$ ansible-galaxy list# /home/greg/ansible/roles# /usr/share/ansible/roles- linux-system-roles.kdump, (unknown version)- linux-system-roles.network, (unknown version)- linux-system-roles.postfix, (unknown version)- linux-system-roles.selinux, (unknown version)- linux-system-roles.timesync, (unknown v

相关推荐: