ansible批量管理服务部署
1. 安装部署软件
[root@muban ~]# yum install -y ansible
2. 编写主机清单
[root@muban ~]# vim /etc/ansible/hosts
# 添加 172.16.1.10 和 172.16.1.11 被管理主机
在/etc/ansible/hosts文件尾添加
172.16.1.10
172.16.1.11
3. 配置密钥免密码连接认证
[root@muban ~]# ssh-keygen -t dsa
[root@muban ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub root@172.16.1.31
# 批量传递密钥
// 脚本批量传递密钥
#!/bin/bash
for ip in 10 11
do
ssh-copy-id -i /root/.ssh/id_dsa.pub root@172.16.1.$ip
done
// 免交互批量传递密钥
步骤一:
yum install -y sshpass
for ip in 10 11
步骤二:
do
sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub root@172.16.1.$ip "-o StrictHostKeyChecking=no" &>/dev/null
done
3. 测试被管理主机
[root@muban ~]# ansible all -a "hostname"
172.16.1.41 | CHANGED | rc=0 >>
db01
172.16.1.99 | CHANGED | rc=0 >>
muban
网友评论