当前位置: 首页 > news >正文

ansible的搭建与安装

ansible的搭建与安装

一、安装RHEL9版本虚拟机

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

没有特别指明的直接默认

在这里插入图片描述

在这里插入图片描述

导入镜像

在这里插入图片描述

在这里插入图片描述

然后开机

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

然后开始安装,安装完成之后重启,用root用户登录
二、在虚拟机中配置IP地址
[root@localhost ~]# hostnamectl hostname ansible.example.com
[root@localhost ~]# bash
[root@ansible ~]# nmcli connection show
NAME    UUID                                  TYPE      DEVICE 
lo      b3a08762-cb04-4218-82fc-035bfb994a2d  loopback  lo     
ens160  fec9c85e-c7d8-36d8-9fc8-b88af59fbf33  ethernet  --     
[root@ansible ~]# nmcli connection modify ens160 ipv4.addresses 192.168.100.100/24 ipv4.gateway 192.168.100.254 ipv4.dns 114.114.114.114 ipv4.method manual connection.autoconnect yes
[root@ansible ~]# nmcli connection up ens160
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@ansible ~]# nmcli connection show
NAME    UUID                                  TYPE      DEVICE 
ens160  fec9c85e-c7d8-36d8-9fc8-b88af59fbf33  ethernet  ens160 
lo      b3a08762-cb04-4218-82fc-035bfb994a2d  loopback  lo     
三、配置本地yum源

在这里插入图片描述

需要连接光驱

在这里插入图片描述

在这里插入图片描述

[root@ansible yum.repos.d]# cd /mnt
[root@ansible mnt]# ls
AppStream  EULA              images      RPM-GPG-KEY-redhat-beta
BaseOS     extra_files.json  isolinux    RPM-GPG-KEY-redhat-release
EFI        GPL               media.repo
[root@ansible mnt]# find / -name repodata
/run/media/root/RHEL-9-2-0-BaseOS-x86_64/AppStream/repodata
/run/media/root/RHEL-9-2-0-BaseOS-x86_64/BaseOS/repodata
/mnt/AppStream/repodata
/mnt/BaseOS/repodata
[root@ansible mnt]# vim /etc/yum.repos.d/server.repo

在这里插入图片描述

四、安装软件包组,重启libvirtd服务,并设置下次启动生效
[root@ansible ~]# yum -y group install "Virtualization Client" "Virtualization Hypervisor" "Virtualization Tools"
[root@ansible ~]# systemctl restart libvirtd
[root@ansible ~]# systemctl enable libvirtd
Created symlink /etc/systemd/system/multi-user.target.wants/libvirtd.service → /usr/lib/systemd/system/libvirtd.service.
Created symlink /etc/systemd/system/sockets.target.wants/libvirtd.socket → /usr/lib/systemd/system/libvirtd.socket.
Created symlink /etc/systemd/system/sockets.target.wants/libvirtd-ro.socket → /usr/lib/systemd/system/libvirtd-ro.socket.
五、让虚拟机可以进行远程连接
[root@ansible ~]# vim /etc/ssh/sshd_config
[root@ansible ~]# systemctl restart sshd
[root@ansible ~]# systemctl enable sshd

在这里插入图片描述

六、4、将本地RHEL9.2镜像上传到虚拟机
[root@ansible ~]# ls
anaconda-ks.cfg  Documents  Music     Public                   Templates
Desktop          Downloads  Pictures  rhel-9.2-x86_64-dvd.iso  Videos

在这里插入图片描述

七、在虚拟机中再安装一台虚拟机

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

八、克隆出来5台+刚刚安装的一台,一起6台主机
所有主机,配置IP的时候注意,要删除网卡配置文件的UUID

192.168.122.100 master.example.com

192.168.122.10 node1.example.com

192.168.122.20 node2.example.com

192.168.122.30 node3.example.com

192.168.122.40 node4.example.com

192.168.122.50 node5.example.com

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

九、所有主机,编辑/etc/hosts
[root@ansible ~]# vim /etc/hosts

在这里插入图片描述

将文件发送给master
[root@ansible ~]# scp /etc/hosts root@master:/etc/hosts
The authenticity of host 'master (192.168.122.100)' can't be established.
ED25519 key fingerprint is SHA256:SeY88CrzFNCdL06cUzAp8fkEzSxM7HszUt0C+zebcfs.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'master' (ED25519) to the list of known hosts.
root@master's password: 
hosts                                                              100%  461   342.5KB/s   00:00    
[root@ansible ~]# ssh root@master
root@master's password: 
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Tue Aug 26 20:05:48 2025
[root@master ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.122.1  ansible.example.com  ansible
192.168.122.100  master.example.com  master
192.168.122.10   node1.example.com   node1
192.168.122.20   node2.example.com   node2
192.168.122.30   node3.example.com   node3
192.168.122.40   node4.example.com   node4
192.168.122.50   node5.example.com   node5
每次发送都需要密码比较麻烦所以先做一下免密钥的操作(root和Student都需要做免密钥操作并且受控主机的root和Student用户都需要发送)

root------>root

root------->Student

Student-------->root

Student-------->root

[root@master ~]# ssh-keygen 
[root@master ~]# for i in node{1..5}
> do ssh-copy-id -i ~/.ssh/id_rsa.pub root@$i
> done
[root@master ~]# for i in node{1..5}; do ssh-copy-id -i ~/.ssh/id_rsa.pub student@$i; done
[root@master ~]# su - student
Last login: Tue Aug 26 21:30:24 CST 2025 on tty1
[student@master ~]$ ssh-keygen 
[student@master ~]$ for i in node{1..5}; do ssh-copy-id -i ~/.ssh/id_rsa.pub root@$i; done
[student@master ~]$ for i in node{1..5}; do ssh-copy-id -i ~/.ssh/id_rsa.pub student@$i; done
将配置文件发送到每台主机
[student@master ~]$ exit
logout
[root@master ~]# for i in node{1..5}
> do scp /etc/hosts root@$i:/etc/hosts
> done
hosts                                                              100%  461   151.7KB/s   00:00    
hosts                                                              100%  461   227.7KB/s   00:00    
hosts                                                              100%  461   145.8KB/s   00:00    
hosts                                                              100%  461   127.6KB/s   00:00    
hosts                                                              100%  461    70.2KB/s   00:00    
[root@master ~]# ssh root@node1
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Tue Aug 26 21:39:40 2025
[root@node1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.122.1  ansible.example.com  ansible
192.168.122.100  master.example.com  master
192.168.122.10   node1.example.com   node1
192.168.122.20   node2.example.com   node2
192.168.122.30   node3.example.com   node3
192.168.122.40   node4.example.com   node4
192.168.122.50   node5.example.com   node5
十、配置yum仓库(自己做一个网络源)

在宿主机ansible中配置本地yum仓库,然后安装httpd服务

将包文件上传到/var/www/html/目录下,然后重启httpd服务,并设置下次启动生效

关闭防火墙和selinux

[root@ansible ~]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@ansible ~]# yum -y install httpd
[root@ansible ~]# cd /var/www/html
[root@ansible html]# ls
[root@ansible html]# systemctl stop firewalld.service 
[root@ansible html]# systemctl disable firewalld.service 
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@ansible html]# setenforce 0
[root@ansible html]# getenforce 
Permissive
[root@ansible html]# vim /etc/selinux/config 
将文件上传

在这里插入图片描述

[root@ansible html]# ls
ansible-automation-platform  materials  rhel9  roles
[root@ansible html]# systemctl restart httpd
[root@ansible html]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@ansible html]# cd
[root@ansible ~]# 
[root@ansible ~]# ssh root@master
[root@master ~]# cd /etc/yum.repos.d/
[root@master yum.repos.d]# ls
[root@master yum.repos.d]# vi /etc/yum.repos.d/server.repo
[root@master yum.repos.d]# cd
[root@master ~]# yum -y install vim bash-completion net-tools

在这里插入图片描述

没测试安装之前应该是黑色字体
十一、student用户提权
[root@master ~]# vim /etc/sudoers.d/student
[root@master ~]# for i in node{1..5}; do scp /etc/sudoers.d/student root@$i:/etc/sudoers.d/; done
student                                                            100%   36     9.8KB/s   00:00    
student                                                            100%   36     9.5KB/s   00:00    
student                                                            100%   36    16.6KB/s   00:00    
student                                                            100%   36     5.7KB/s   00:00    
student                                                            100%   36    16.9KB/s   00:00    

在这里插入图片描述

十二、安装ansible
[root@master ~]# su - student
Last login: Tue Aug 26 22:13:52 CST 2025 on pts/0
[student@master ~]$ sudo yum -y install ansible-core   ansible-navigator
1、主机清单的位置
[student@master ~]$ pwd
/home/student
[student@master ~]$ mkdir ansible
[student@master ~]$ cd ansible
[student@master ansible]$ pwd
/home/student/ansible
[student@master ansible]$ vim /etc/ansible/ansible.cfg 
[student@master ansible]$ ansible-config init --disabled > ansible.cfg
[student@master ansible]$ ls
ansible.cfg
[student@master ansible]$ vim ansible.cfg 
[student@master ansible]$ vim inventory

在这里插入图片描述

在这里插入图片描述

2、管理ansible的用户
[student@master ansible]$ vim ansible.cfg 

在这里插入图片描述

3、角色目录,以及模块和关闭密码检查
[student@master ansible]$ mkdir roles
[student@master ansible]$ vim ansible.cfg 
[student@master ansible]$ mkdir collections
[student@master ansible]$ ls
ansible.cfg  collections  inventory  roles

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

十三、测试

在这里插入图片描述

http://www.dtcms.com/a/349824.html

相关文章:

  • BIO、NIO 和 AIO
  • 智慧城市SaaS平台/交通设施运行监测系统之桥梁运行监测、城市道路塌陷风险运行监测系统架构内容
  • v-slot 与 slot-scope区别
  • 开源零信任本地化部署实战指南:Keycloak + OpenZiti 完整方案
  • [element-plus] el-table在行单击时获取行的index
  • JAVA高级工程师--云服务模式多租户SAAS项目商业模式架构全景
  • 【数据可视化-98】2025年上半年地方财政收入Top 20城市可视化分析:Python + Pyecharts打造炫酷暗黑主题大屏
  • 【Java基础】快速掌握Java泛型机制:基本概念与具体应用
  • 工具系列:JsonViewKit
  • Frida 加密解密算法实现与应用指南
  • kafka 原理详解
  • 代码随想录算法训练营30天 | ​​01背包理论基础、416. 分割等和子集
  • Radxa Rock 5B vs Rock 5B+ 、香橙派、鲁班猫、正点原子及RK3588 的AI/音视频任务的选择
  • springboot项目每次启动关闭端口仍被占用
  • 第 93 场周赛:二进制间距、重新排序得到 2 的幂、优势洗牌、最低加油次数
  • Agent实战教程:LangGraph相关概念介绍以及快速入门
  • Reachability Query
  • 算法每日一题 | 入门-分支结构-肥胖问题
  • 【modbus学习】野火Modbus主机接收到数据后的完整函数调用流程
  • Ajax笔记(上)
  • Vue3在一个对象的list中,找出update_date最大的一条数据
  • MCP 协议原理与系统架构详解—从 Server 配置到 Client 应用
  • vscode--快捷键
  • ESP8266学习
  • 嵌入式开发学习———Linux环境下网络编程学习(六)
  • 驾驭 Glide 的引擎:深度解析 Module 与集成之道
  • 音视频学习(五十六):单RTP包模式和FU-A分片模式
  • ESP32开发WSL_VSCODE环境搭建
  • *解决 Visual Studio 编译时的字符编码问题
  • 41_基于深度学习的小麦病害检测识别系统(yolo11、yolov8、yolov5+UI界面+Python项目源码+模型+标注好的数据集)