ansible源码安装nginx
yum search ansible #检查ansible
yum -y install centos-release-ansible-29 #安装centos-release-ansible-29
安装ansible
yum –y install ansible #安装ansible
ansible --version #查看版本
密钥
ssh-keygen #生成密钥
ssh-copy-id root@192.168.126.141 #发送到被管理主机
ssh-copy-id root@192.168.126.137
配置ansible清单文件,添加主机
vim /etc/ansible/hosts #清单目录
[webservers] #写一个组组名随意
192.168.126.141 #除本机外另外多台的IP
192.168.126.137
测试被管理主机是否可达
ansible webservers –m ping #ansible [设置清单里面的组] -m [调用的模块]
(绿色通过无更改)
(红色警告)
(黄色通过有更改)
#安装编译环境
ansible webserver -m yum -a ‘name=gcc,pcre-devel,zlib-devel state=latest’
#分发并解压安装包
ansible webserver -m unarchive -a 'src=nginx-1.18.0.tar.gz dest=/root/’
#检查安装环境,编译安装,安装
ansible webserver -m shell -a ‘cd /root/nginx-1.18.0 && ./configure && make && make install’
#启动nginx
ansible webserver -m shell -a ‘/usr/local/nginx/sbin/nginx’