正文
在centOS 7 上部署ansible自动化运维环境(01)
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
环境:
3台centos 7
mycat : 10.0.0.2
mariadb1: 10.0.0.3
mariadb2: 10.0.0.4
为了实验方便 firewalld、selinux均处于关闭状态
[root@mycat ~]# systemctl stop firewalld
[root@mycat ~]# systemctl disable firewalld
[root@mycat ~]# setenforce
hosts文件均添加如下映射:
10.0.0.2 mycat
10.0.0.3 mariadb1
10.0.0.4 mariadb2
1、安装 ansible工具
[root@mycat ~]# yum -y install ansible
2、设置ssh免密登陆
[root@mycat ~]# ssh-keygen // 生成密钥
[root@mycat ~]# ssh-copy-id -i .ssh/id_rsa.pub root@***ip*** // 把密钥导入
[root@mycat ~]# ssh ***ip*** // 登陆
[root@mariadb1 ~]# exit // 登出
3、修改/etc/ansible/hosts文件,添加管理主机组,以后可根据组成员进行批量操作
[root@mycat ~]# vim /etc/ansible/hosts [mariadb] //名为mariadb的主机组,包含 0.3、0.4两台主机
10.0.0.3
10.0.0.4 [mycat] //名为mycat的组机组,包含0.2主机
10.0.0.2
4、用ping模块测试
[root@mycat ~]# ansible mariadb -m ping
10.0.0.4 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.0.0.3 | SUCCESS => {
"changed": false,
"ping": "pong"
}