ansible进阶

使用源码安装Python3.5

安装支持包

[root@ansible ~]# yum -y install lrzsz vim net-tools gcc gcc-c++ ncurses ncurses-devel unzip zlib-devel zlib openssl-devel openssl

源码编译Python3.5

[root@ansible Python-3.5.2]# tar xf Python-3.5.2.tgz -C /usr/src/
[root@ansible Python-3.5.2]# cd /usr/src/Python-3.5.2/
[root@ansible Python-3.5.2]# ./configure --prefix=/usr/local/python/
[root@ansible Python-3.5.2]# make && make install
[root@ansible Python-3.5.2]# ln -s /usr/local/python/bin/python3 /usr/bin/python3
[root@ansible Python-3.5.2]# which python3
/usr/bin/python3
[root@ansible Python-3.5.2]# python3 -V
Python 3.5.2

使用pip3安装ansible

安装ansible最新版本

[root@ansible Python-3.5.2]# /usr/local/python/bin/pip3 install ansible

ansible安装完毕后

[root@ansible python]# ln -s /usr/local/python/bin/ansible /usr/local/bin/
[root@ansible python]# which ansible
/usr/local/bin/ansible
[root@ansible python]# ansible --version
ansible 2.5.4
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/python/lib/python3.5/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.5.2 (default, Jun 13 2018, 09:13:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

| Host | IP |
|ansible|192.168.200.137|
|webA |192.168.200.132|
|webB |192.168.200.138|

生成密钥对

[root@ansible python]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P “”

分发密钥

[root@ansible python]# ssh-copy-id -i ~/.ssh/id_rsa.pub “-o StrictHostKeyChecking=no” 192.168.163.136

进行免密码登陆测试

[root@ansible python]# ssh 192.168.200.132

ansible的配置文件

[root@ansible python]# mkdir -p /etc/ansible
[root@ansible python]# vim /etc/ansible/hosts
[root@ansible python]# cat /etc/ansible/hosts   #ansible主机管理配置文件
[nginx]         #被管理的主机组名称
webA ansible_ssh_host=192.168.163.136 ansible_ssh_port=22 ansible_ssh_user=root #第一台主机
webB ansible_ssh_host=192.168.163.146 ansible_ssh_port=22 ansible_ssh_user=root  ansible_ssh_pass=111111    #第二台主机

下载epel源安装sshpass

[root@ansible python]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@ansible python]# yum -y install sshpass
[root@ansible python]# which sshpass
/usr/bin/sshpass

ssh-copy-id 192.168.163.136
ssh-copy-id 192.168.163.146

[root@localhost script]# cat auto_nginx.sh 
#!/bin/sh
#nginx install shell scripts

test -d /media/cdrom || mkdir -p /media/cdrom
mount /dev/sr0 /media/cdrom &>/dev/null
yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel &>/dev/null
test -d /service/script || exit 3
cd /service/script/
tar xf nginx-1.10.2.tar.gz -C /usr/src/
cd /usr/src/nginx-1.10.2/
./configure --prefix=/usr/local/nginx --with-http_ssl_modul --with-http_stub_status_module &>/dev/null
make &>/dev/null
make install &>/dev/null
exit 0

猜你喜欢

转载自blog.csdn.net/weixin_43586287/article/details/84852117
今日推荐