ansible尝试

1.下载软件

http://releases.ansible.com/ansible/

2.软件安装

[root@Yangjian-VM02-241 ansible-stable-2.0.0.1]# python setup.py build

[root@Yangjian-VM02-241 ansible-stable-2.0.0.1]# python setup.py install

安装过程中需要依赖的软件包括

Searching for pycrypto==2.6.1

Searching for setuptools==0.6c11

Searching for PyYAML==3.10

Searching for Jinja2==2.8

Searching for paramiko==1.12.2

Searching for MarkupSafe==0.23

Searching for ecdsa==0.12

3.软件版本

[root@Yangjian-VM02-241 tools]# ansible --version
ansible 2.0.0.2
config file = /etc/ansible/ansible.cfg
configured module search path = /usr/share/ansible

4.拷贝配置文件

[root@Yangjian-VM02-241 ansible]# cp /application/tools/ansible-stable-2.0.0.1/examples/ansible.cfg /etc/ansible/ansible.cfg

5.基本配置

inventory = /etc/ansible/hosts                     #被管理主机组文件
library = /usr/share/ansible                          #ansible模块路径
remote_tmp = $HOME/.ansible/tmp            #remote临时目录
forks = 5                                                       #并发数
sudo_user = root                                          #sudo后使用的用户
remote_port = 12345                                   #端口

6.主机组配置文件添加被管理节点

[ansible@Yangjian-VM01-240 ~]$ cat /etc/ansible/hosts 
[mysql_test]
172.16.1.190
172.16.1.201

7.拷贝模块文件

编译安装后需要拷贝ansible模块文件

[root@Yangjian-VM02-241 ansible]# mv ansible-modules-core-stable-2.0.0.1 /usr/share/ansible

8.配置用户信任

[root@Yangjian-VM02-241 ansible]#useradd ansible

[root@Yangjian-VM02-241 ansible]#passwd ansible

[root@Yangjian-VM02-241 ansible]#chown ansible:ansible /etc/ansible -R

[ansible@Yangjian-VM01-240 ~]$ ssh-keygen -t rsa

[ansible@Yangjian-VM01-240 ~]$ ssh-keygen -t dsa

[ansible@Yangjian-VM01-240 ~]$ scp -P12345 .ssh/authorized_keys ansible@172.16.1.190:/home/ansible/.ssh/authorized_keys

[ansible@Yangjian-VM01-240 ~]$ scp -P12345 .ssh/authorized_keys ansible@172.16.1.201:/home/ansible/.ssh/authorized_keys

9.测试用户信任

[ansible@Yangjian-VM01-240 ~]$ ssh -p 12345 ansible@172.16.1.190
  Last login: Mon Apr 25 14:44:58 2016 from 172.16.1.240

[ansible@Yangjian-VM01-240 ~]$ ssh -p 12345 ansible@172.16.1.201
  Last login: Mon Apr 25 15:17:16 2016 from 172.16.1.240

10.测试ansible简单命令

[ansible@Yangjian-VM01-240 ansible]$ ansible mysql_test -u ansible -m command -a "sudo uptime"

172.16.1.201 | SUCCESS | rc=0 >>
10:32:06 up 25 days, 16:36, 1 user, load average: 0.12, 0.09, 0.04
172.16.1.190 | SUCCESS | rc=0 >>
10:20:54 up 25 days, 15:46, 2 users, load average: 0.00, 0.00, 0.00

[ansible@Yangjian-VM01-240 ansible]$ ansible mysql_test -u ansible -m shell -a "sudo df -h | grep data"

172.16.1.201 | SUCCESS | rc=0 >>
/dev/sdb1 939G 329G 563G 37% /data
172.16.1.190 | SUCCESS | rc=0 >>
/dev/xvda5 9.9G 2.8G 6.6G 30% /data
/dev/xvdb1 197G 103G 85G 55% /mysqldata

上一篇:lca 最近公共祖先


下一篇:【转】双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计