4.1-ansible Instance-Installing Nginx

Source: Internet
Author: User

Ansible Installing Nginx


* Idea: First on a machine to compile and install the Nginx, packaging, and then use Ansible to the issued


1./usr/local/nginx/is an nginx file that has been compiled and installed, and the startup scripts and configuration files are configured.

2.cd/usr/local #进入上一级目录

3.tar CZVF nginx.tar.gz Nginx #将目录打包

4.cd/etc/ansible entering the Ansible profile directory

5.mkdir Nginx_install Create a Nginx_install directory for easy Management

6.CD Nginx_install

7.mkdir-p Roles/{common,install}/{handlers,files,meta,tasks,templates,vars}


Description: There are two roles under the roles directory, common for some preparatory operations, such as installing some dependent packages. Install for nginx operation. There are several directories under each role, handlers the following is the action to take when a change occurs, usually with a change in the configuration file, to restart the service. Files for the installation of some documents, meta for the description of information, the role depends on the information, tasks inside is the core configuration file, templates usually save some configuration files, startup scripts and other template files, according to different machine configuration, issued a different configuration file. Variables defined under VARs

8.cd/etc/ansible/nginx_install/roles/common/tasks


* Define Common/tasks File

9.vim main.yml #定义common的tasks, Nginx needs some dependent packages. The content is as follows

---

-Name:install initializtion require software #名称

yum:name={{Item}} state=installed #yum模块, loop install package

With_items:

-Zlib-devel

-Pcre-devel

-Openssl-devel

Note: Regardless of directory, the total Portal configuration file is named Main.yml


* Define Install/files File

10.cd/etc/ansible/nginx_install/roles/install/

11.cp/usr/local/nginx.tar.gz/etc/ansible/nginx_install/roles/install/files/nginx.tar.gz #复制包到指定目录files下


* Define Install/templates File

12.cp/usr/local/nginx/conf/nginx.conf templates/#复制配置文件到templates下

Cp/etc/init.d/nginx templates/#复制启动脚本到templates下


* Define Install/vars File

13.vim vars/main.yml #内容如下

Nginx_user:www

Nginx_port:80 #可不写, not to use

Nginx_basedir:/usr/local/nginx #定义客户端解压到哪个目录下去


* Define the Install/tasks file, copy the relevant files to the specified directory

14.vim tasks/copy.yml

-Name:copy Nginx software #模块copy的src相对目录为files/, so you can write directly.

copy:src=nginx.tar.gz dest=/tmp/nginx.tar.gz Owner=root Group=root

-Name:uncompression Nginx Software #解压到客户端指定目录

Shell:tar zxf/tmp/nginx.tar.gz-c/usr/local/

-Name:copy Nginx Start Script #template模块和copy模块功能相似

Template:src=nginx Dest=/etc/init.d/nginx owner=root group=root mode=0755

-Name:copy Nginx Config #引用的变量在vars中已经定义了

template:src=nginx.conf dest={{nginx_basedir}}/conf/owner=root group=root mode=0644


15.vim tasks/install.yml #定义建立用户, start the service, delete the compressed package

-Name:create Nginx User #www用户是nginx的配置文件中定义的, there will be no error, so to add users

user:name={{Nginx_user}} state=present createhome=no Shell=/sbin/nologin

-Name:start Nginx Service

Service:name=nginx state=started

-Name:add Boot Start Nginx Service

Shell:chkconfig--level 345 Nginx on

-Name:delete Nginx compression files

Shell:rm-rf/tmp/nginx.tar.gz


Description: State=present represents the creation of a user createhome=no means that the home directory is not created

4.1-ansible Instance-Installing Nginx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.