自动化运维:ansible之环境配置

准备三台机器:
server.example.com
node1.example.com
node2.example.com
配置IP,主机名,/etc/hosts
然后去配置免密登录
配置yum源使用Centos-stream.repo
安装ansible
使用ansible --version去验证
配置清单:/etc/ansible/hosts
[node]
node1.example.com
node2.example.com
使用ansible node -m ping去验证

控制机:

[root@server ~]# hostnamectl set-hostname server.examle.com

[root@server ~]# nmcli c modify ens160 ipv4.addresses 192.168.30.133/24 ipv4.gateway 192.168.30.2 ipv4.dns 8.8.8.8 ipv4.method manual
[root@server ~]# nmcli c up ens160

[root@server ~]# nmcli c show ens160 | grep method
ipv4.method:                            manual
ipv6.method:                            auto
proxy.method:                           none

使用xshell的工具同时将三个ip的映射关系写进三个机器的/etc/hosts文件中

[root@node2 ~]# echo 192.168.30.133  server.example.com >> /etc/hosts
[root@node2 ~]# echo 192.168.30.137  node1.example.com >> /etc/hosts
[root@node2 ~]# echo 192.168.30.136  node2.example.com >> /etc/hosts

[root@server ~]# ssh-keygen -t rsa

[root@server ~]# ssh-copy-id root@192.168.30.137
[root@server ~]# ssh-copy-id root@192.168.30.136

[root@server yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@server yum.repos.d]# yum install ansible -y
[root@server yum.repos.d]# ansible --version                 #查看ansible的版本
[root@server yum.repos.d]# vim /etc/ansible/ansible.cfg 

[root@server yum.repos.d]# vim /etc/ansible/hosts

[root@server yum.repos.d]# ansible node -m ping

 

因为ansible是基于python开发的,所以在工作的时候需要依赖Python的环境,所以,在受控制集群应该具备两个条件:ssh服务和Python环境


受控制机群:

Redhat 8:

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

[root@node1 ~]# nmcli c modify ens160 ipv4.addresses 192.168.30.137/24 ipv4.gateway 192.168.30.2 ipv4.dns 8.8.8.8 ipv4.method manual

[root@node1 ~]# nmcli c up ens160

Centos 7:

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

[root@node2 ~]# nmcli c modify ens33 ipv4.addresses 192.168.30.136/24 ipv4.gateway 192.168.30.2 ipv4.dns 8.8.8.8 ipv4.method manual
[root@node2 ~]# nmcli c up ens33
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shadow_58

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值