Sample code for batch deployment of Nginx with Ansible

Sample code for batch deployment of Nginx with Ansible

1.1 Copy the nginx installation package and installation script to the client and install the script

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 installation script

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 Execute ansible command

cd /ansible
ansible-playbook nginx.yml --syntax-check #Check syntax ansible-playbook nginx.yml #Execute

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Detailed explanation of Nodejs array queue and forEach application

>>:  Mysql inner join on usage examples (must read)

Recommend

Learn MySQL database in one hour (Zhang Guo)

Table of contents 1. Database Overview 1.1 Develo...

Using Apache ab to perform http performance testing

Mac comes with Apache environment Open Terminal a...

translate(-50%,-50%) in CSS achieves horizontal and vertical centering effect

translate(-50%,-50%) attributes: Move it up and l...

5 ways to determine whether an object is an empty object in JS

1. Convert the json object into a json string, an...

SMS verification code login function based on antd pro (process analysis)

Table of contents summary Overall process front e...

The vue project realizes drawing a watermark in a certain area

This article shares with you how to use Vue to dr...

Detailed explanation of how to copy and backup docker container data

Here we take the Jenkins container as an example ...

How to implement Vue timer

This article example shares the specific code of ...

Detailed explanation of root directory settings in nginx.conf

There are always some problems when configuring n...

No-nonsense quick start React routing development

Install Enter the following command to install it...

Implementation of breakpoint resume in vue-video-player

In a recent project, I needed to implement the fu...

WeChat Mini Program to Implement Electronic Signature

This article shares the specific code for impleme...

Example of MySQL slow query

Introduction By enabling the slow query log, MySQ...