• 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.9dev 主机组的成员

      • 172.25.250.10test 主机组的成员

      • 172.25.250.11172.25.250.12prod 主机组的成员

      • 172.25.250.13balancers 主机组的成员

      • prod 组是 webservers 主机组的成员

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

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

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

    1. [kiosk@foundation0 ~]$ ssh greg@172.25.250.254
    2. Activate the web console with: systemctl enable --now cockpit.socket
    3. 启动所有的虚拟机:手动:virt-manager  或者   命令:rht-vmctl start all
    4. #登录root用户装包
    5. [greg@bastion ~]$ su -
    6. Password:
    7. Last login: Fri Mar 31 11:17:37 GMT 2023 from 172.25.250.250 on pts/0
    8. [root@bastion ~]$ sudo yum install -y ansible
    9. #返回grep用户
    10. [root@bastion ~]# exit
    11. logout
    12. 检查:
    13. [greg@bastion ~]$ ansible --version
    14. ansible 2.8.0
    15. config file = /etc/ansible/ansible.cfg
    16. configured module search path = ['/home/greg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    17. ansible python module location = /usr/lib/python3.6/site-packages/ansible
    18. executable location = /usr/bin/ansible
    19. python version = 3.6.8 (default, Apr 3 2019, 17:26:03) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]
    20. #创建目录并在目录下创建清单文件
    21. [greg@bastion ~]$ mkdir ansible
    22. [greg@bastion ~]$ cd ansible
    23. [greg@bastion ansible]$ cat inventory
    24. [dev]
    25. 172.25.250.9
    26. [test]
    27. 172.25.250.10
    28. [prod]
    29. 172.25.250.11
    30. 172.25.250.12
    31. [balancers]
    32. 172.25.250.13
    33. [webservers:children]
    34. prod
    35. [all:vars]
    36. ansible_user=root
    37. ansible_password=redhat # 填写考试环境提供的密码。(粘贴到虚拟机时要删除注释)
    1. #从ansible中复制配置文件
    2. [greg@bastion ansible]$ cp /etc/ansible/ansible.cfg ./
    3. [greg@bastion ansible]$ vim ansible.cfg
    4. [defaults]
    5. inventory = /home/greg/ansible/inventory
    6. roles_path = /home/greg/ansible/roles
    7. host_key_checking = False #主机是否校验
    8. [greg@bastion ansible]$ mkdir /home/greg/ansible/roles
    9. 测试:
    10. [greg@bastion ansible]$ ansible-inventory --graph
    11. @all:
    12. |--@balancers:
    13. | |--172.25.250.13
    14. |--@dev:
    15. | |--172.25.250.9
    16. |--@test:
    17. | |--172.25.250.10
    18. |--@ungrouped:
    19. |--@webservers:
    20. | |--@prod:
    21. | | |--172.25.250.11
    22. | | |--172.25.250.12
    23. #使用ansible ping所有主机,-m:模块 -o:所有主机
    24. [greg@bastion ansible]$ ansible all -m ping -o
    25. 172.25.250.13 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
    26. 172.25.250.12 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
    27. 172.25.250.11 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
    28. 172.25.250.10 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
    29. 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. #配置仓库 :仓库1和仓库2
    2. [greg@bastion ansible]$ cat adhoc.sh
    3. #!/bin/bash
    4. ansible all -m yum_repository -a 'name=EX294_BASE description="EX294 base software" \
    5. baseurl=http://content/rhel8.0/x86_64/dvd/BaseOS \
    6. gpgcheck=yes \
    7. gpgkey=http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release \
    8. enabled=yes'
    9. ansible all -m yum_repository -a 'name=EX294_STREAM description="EX294 stream software" \
    10. baseurl=http://content/rhel8.0/x86_64/dvd/AppStream \
    11. gpgcheck=yes \
    12. gpgkey=http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release \
    13. enabled=yes'
    14. -m :
    15. -a : 指定参数
    16. description: 描述
    17. gpgcheck=yes : GPG 签名检查为启用状态
    18. enabled=yes : 存储库为启用状态
    19. [greg@bastion ansible]$ chmod +x /home/greg/ansible/adhoc.sh
    20. [greg@bastion ansible]$ ./adhoc.sh
    21. 检查:
    22. #查看机器仓库
    23. [greg@bastion ansible]$ ansible all -m shell -a 'yum repolist'
    24. [WARNING]: Consider using the yum module rather than running 'yum'. If you need to use command because yum is insufficient you can add 'warn:
    25. false' to this command task or set '
  • 相关阅读:
    Codeforces Round #725 (Div. 3) F. Interesting Function
    经典面试题 之 Dubbo和Zookeeper
    设计和实施
    最新面试必问:怎么写一个又好又快的日志库
    电缆隧道在线监测系统:提升电力设施安全与效率的关键
    vue 刷新当前页面的方式
    数字人IP为何成家电品牌年轻化营销黑马?
    支付通道的安全性探讨
    云计算高级课程作业
    linux下二进制安装docker最新版docker-24.0.6
  • 原文地址:https://blog.csdn.net/m0_60154718/article/details/129876994