ansible自动化运维——安装 ansible;保姆级安装,看完不会来打断博主的腿;

发布于:2023-02-02 ⋅ 阅读:(1269) ⋅ 点赞:(0)

安装 ansible

一、准备三台Linux机器:

server.example.com
node1.example.com
node2.example.com
在对应的三台Linux机器上,修改成自己想要的主机名:

[root@localhost ~]# hostnamectl set-hostname server.example.com
[root@localhost ~]# hostnamectl set-hostname node1.example.com
[root@localhost ~]# hostnamectl set-hostname node2.example.com

二、配置:

  1. 配置IP:
[root@node1 ~]# nmcli c show ens160 | grep method
ipv4.method:                            auto
ipv6.method:                            auto
proxy.method:                           none
[root@node1 ~]# nmcli c modify ens160 ipv4.addresses 192.168.126.130/24 ipv4.gateway 192.168.126.2 ipv4.dns 8.8.8.8 ipv4.method manual
[root@node1 ~]# nmcli c show ens160 | grep method
ipv4.method:                            manual
ipv6.method:                            auto
proxy.method:                           none

在这里插入图片描述
确保ip为静态
2. 在三台主机上 配置 /etc/hosts 让主机名映射到对应的ip:

echo "192.168.126.128 server.example.com" >> /etc/hosts
echo "192.168.126.130 node1.example.com" >> /etc/hosts
echo "192.168.126.129 node2.example.com" >> /etc/hosts

打开 /etc/hosts 进行配置:
在这里插入图片描述

三、配置免密登录

  1. 生成密钥
[root@server ~]# ssh-keygen -t rsa

在 /root/.ssh 查看密钥:
在这里插入图片描述
2. 把公钥拷贝到要登录的机器端:

[root@server .ssh]# ssh-copy-id root@node1.example.com

在这里插入图片描述

[root@server .ssh]# ssh-copy-id root@node2.example.com

在这里插入图片描述

四、配置yum源使用Centos-stream.repo

  1. 用xftp将 Centos-stream.repo 移动到 /etc/yum.repos.d
    在这里插入图片描述
    没有这个源的,可以私信骚扰我!!!
    查看一下:
    在这里插入图片描述
  2. 清理缓存:
[root@server yum.repos.d]# yum clean all

在这里插入图片描述
3. 创建缓存:

[root@server yum.repos.d]# yum makecache

在这里插入图片描述

五、安装两个软件软:

[root@server yum.repos.d]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-
release-6.0-1.el8.noarch.rpm

在这里插入图片描述

[root@server yum.repos.d]# yum install -y https://mirrors.tuna.tsinghua.edu.cn/epel/epel-release-latest-8.noarch.rpm

在这里插入图片描述
查看一下:
在这里插入图片描述
下载新的源之后,记得清空缓存和重建缓存

六、安装ansible:

[root@server yum.repos.d]# yum install ansible -y

时间可能很漫长,耐心等待。。。。

七、验证:

[root@server yum.repos.d]# ansible --version

在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到