环境:
3台centos 7
mycat : 10.0.0.2 mariadb1: 10.0.0.3 mariadb2: 10.0.0.4
为了实验方便 firewalld、selinux均处于关闭状态
hosts文件均添加如下映射:
10.0.0.2 mycat 10.0.0.3 mariadb1 10.0.0.4 mariadb2
1、安装 ansible工具
[[email protected] ~]# yum -y install ansible
2、设置ssh免密登陆
[[email protected] ~]# ssh-keygen // 生成密钥 [[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]***ip*** // 把密钥导入 [[email protected] ~]# ssh ***ip*** // 登陆 [[email protected] ~]# exit // 登出
3、修改/etc/ansible/hosts文件,添加管理主机组,以后可根据组成员进行批量操作
[[email protected] ~]# 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模块测试
[[email protected] ~]# ansible mariadb -m ping 10.0.0.4 | SUCCESS => { "changed": false, "ping": "pong" } 10.0.0.3 | SUCCESS => { "changed": false, "ping": "pong" }
原文地址:https://www.cnblogs.com/BrotherCat/p/11254875.html
时间: 2024-10-13 04:33:00