Ansible批量部署工具的安装

1、系统安装gcc,以及python2.6以上(2.6.8);

第一种比较简单的安装方法:

  1)直接yum install -y ansible;

  2)然后更改配置,/etc/ansible/ansible.cfg,将里面的host_key_checking = False前的#去掉,ssh在首次连接出现检查keys 的提示,通过设置,不会有这些提示

  3)去设置hosts文件,在最后加入以下配置,10.139.11.118是要远程的服务器IP,ansible_ssh_user登录服务器的用户,ansible_ssh_pass登录服务器的密码

[test]
10.139.11.118 ansible_ssh_user=root ansible_ssh_pass='1qaz!QAZ'
10.139.11.119 ansible_ssh_user=root ansible_ssh_pass='1qaz!QAZ'

4)测试ansible是否可用

[root@lrrvd ansible]# ansible test -m command -a 'uptime'
10.139.11.118 | SUCCESS | rc=0 >>
 14:23:41 up 4 days, 21:01,  2 users,  load average: 0.00, 0.01, 0.05

10.139.11.119 | SUCCESS | rc=0 >>
 14:23:39 up 4 days, 21:00,  2 users,  load average: 0.00, 0.01, 0.05

 

 第二种原始方法,通过包去安装:

1)准备好ansible的依赖包:

python-devel-2.6.8-0.15.1.x86_64;setuptools-18.2.tar;PyYAML-3.11.tar;Jinja2-2.8-py2.py3-none-any.whl;pyasn1-0.1.8.tar;pycrypto-2.6.1.tar;ecdsa-0.13.tar;paramiko-1.13.3.tar;ansible-1.9.2.tar;simplejson-3.6.5.tar.gz;

2)各个安装包可以通过yum provides ***查找安装;也可以通过wget https。。。。

https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz
# tar xvzf pycrypto-2.6.1.tar.gz
# cd pycrypto-2.6.1
# python setup.py install

http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz

https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz

https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.9.3.tar.gz

https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz

 https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.11.tar.gz

https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz

https://pypi.python.org/packages/source/s/simplejson/simplejson-3.6.5.tar.gz

https://github.com/ansible/ansible/archive/v1.7.2.tar.gz

3)SSH免密钥登录设置

## 生成公钥/私钥

ssh-keygen -t rsa -P ''  #一路回车即可

##将/root/.ssh/id_rsa.pub分发到其他服务器

scp /root/.ssh/id_rsa.pub root@10.139.6.152:/root/.ssh/

##并在所有服务器上执行如下指令

cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

chmod 600 /root/.ssh/authorized_keys

4)生成ansible配置文件

a 配置文件/etc/ansible/ansible.cfg

mkdir -p /etc/ansible

cp ansible-1.7.2/examples/ansible.cfg /etc/ansible/

b 配置文件/etc/ansible/hosts

# vim /etc/ansible/hosts
[test]
192.168.110.20
192.168.110.30—这是要控制的机器ip

5)测试

[root@ansible ansible]# ansible test -m command -a 'uptime'
10.139.6.156 | success | rc=0 >>
17:39:23 up 1:29, 2 users, load average: 0.00, 0.01, 0.05

10.139.6.152 | success | rc=0 >>
17:39:22 up 1:31, 2 users, load average: 0.08, 0.03, 0.05

10.139.6.154 | success | rc=0 >>
17:39:23 up 1:30, 2 users, load average: 0.05, 0.03, 0.05

10.139.6.147 | success | rc=0 >>
17:39:23 up 1:32, 2 users, load average: 0.06, 0.12, 0.09

ansible安装成功。

posted @ 2017-02-27 18:48  Lrr-Alysa  阅读(1138)  评论(0编辑  收藏  举报