ansible环境准备

准备环境如下:

序号IP角色操作系统
1172.26.94.193mastercentos 7.6
2172.26.94.192node1centos 7.6
3172.26.94.194node2centos 7.6

修改各节点hosts文件:

vim /etc/hosts
172.26.94.193   master  
172.26.94.194   node1
172.26.94.192   node2

master节点安装ansible:

yum -y install ansible

进行ansible的基础配置:

vim /etc/ansible/ansible.cfg
inventory                 = /etc/ansible/host    #主机管理清单
remote_port               = 22   #操作主机的端口
timeout                   = 10    #连接主机的超时时间
log_path = /var/log/ansible.log    #设置日志路径
private_key_file = /root/.ssh/id_rsa  #指定认证密钥的私钥

将主机信息加入主机清单:

[root@master ~]# vim /etc/ansible/hosts
[master]
172.26.94.193	ansible_ssh_user=root	ansible_ssh_pass=123456
[web]
172.26.94.192   ansible_ssh_user=root
[db]
172.26.94.194   ansible_ssh_user=root

免密访问配置:

[root@master ~]# ssh-keygen 
Generating public/private rsa key pair.
……
[root@master ~]# ssh-copy-id root@172.26.94.194
……
Now try logging into the machine, with:   "ssh 'root@172.26.94.194'"
and check to make sure that only the key(s) you wanted were added.
[root@master ~]# ssh-copy-id root@172.26.94.192
……
Now try logging into the machine, with:   "ssh 'root@172.26.94.192'"
and check to make sure that only the key(s) you wanted were added.

访问测试:

[root@master ~]# ansible db -a "df -h"
172.26.94.194 | CHANGED | rc=0 >>
……
[root@master ~]# ansible web -a "df -h"
172.26.94.192 | CHANGED | rc=0 >>
……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值