环境准备
服务器系统 | Centos7.3 |
---|---|
内存 | 1G |
CPU | 2核 |
IP地址 | 10.0.0.43 |
服务器系统 | Centos7.3 |
---|---|
内存 | 1G |
CPU | 2核 |
IP地址 | 10.0.0.44 |
yum -y install ansible
ssh-keygen
ssh-copy-id 10.0.0.44
vim /etc/ansible/hosts
ansible webserver -m ping
mkdir nginx
cd nginx
tar zxf nginx-1.16.1.tar.gz
cd nginx-1.16.1/
cp conf/nginx.conf /root/nginx/
cd /root/nginx
rm -rf nginx-1.16.1
vim index.html
<h1>This is web1!<h1>
vim nginx.yml
---
- hosts: webserver
tasks:
- name: "推送Nginx源码包"
unarchive: src=nginx-1.16.1.tar.gz dest=/root/
- name: "安装依赖环境库"
yum: name=gcc,gcc-c++,pcre-devel,zlib-devel state=latest
- name: "安装Nginx"
shell: cd /root/nginx-1.16.1 && ./configure && make && make install
- name: "推送配置文件"
copy: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf
- name: "推送测试页面"
copy: src=index.html dest=/usr/local/nginx/html/index.html
- name: "启动Nginx服务"
shell: netstat -ntl | grep -qw 80 || /usr/local/nginx/sbin/nginx
ansible-playbook --syntax-check nginx.yml
ansible-playbook nginx.yml
版权声明:本文为aaronszm原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。