极乐门资源网 Design By www.ioogu.com

1.1 将nginx的安装包,和安装脚本copy到客户端,并安装脚本

vim /ansible/roles/nginx/tasks/nginx.yml

- name: copy nginx_tar_gz to client
 copy: src=nginx-1.8.0.tar.gz dest=/tmp/nginx-1.8.0.tar.gz
- name: copy install_shell to client
 copy: src=install_nginx.sh dest=/tmp/install_nginx.sh
- name: install nginx
 shell: /bin/bash /tmp/install_nginx.sh

1.2 Nginx 安装脚本

vim /ansible/roles/nginx/files/install_nginx.sh

#!/bin/bash
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx
cd /tmp
tar xf nginx-1.8.0.tar.gz;cd nginx-1.8.0
mkdir /application/nginx/;chown nginx.nginx /application/nginx/
./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/application/nginx/nginx.pid --user=nginx --group=nginx --with-http_ssl_module
make && make install
egrep -v "#|^$" /etc/nginx/nginx.conf >/etc/nginx/nginx.conf.bak
rm -rf /etc/nginx/nginx.conf
mv /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf
sed -i "/^\s*index / i proxy_pass http://localhost:8080;" /etc/nginx/nginx.conf
/usr/sbin/nginx

1.3 执行ansible 命令

cd /ansible
ansible-playbook nginx.yml --syntax-check #检查语法
ansible-playbook nginx.yml #执行

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
Ansible批量部署Nginx,Ansible,部署Nginx

极乐门资源网 Design By www.ioogu.com
极乐门资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com

评论“Ansible批量部署Nginx的示例代码”

暂无Ansible批量部署Nginx的示例代码的评论...