Ansible implements Nginx dual master mode inversion, keepalived high availability, memcached cache

Source: Internet
Author: User
Tags fpm memcached vars

Ansible automatic operation and Maintenance tool configuration Ngnix front end to back-end real machine, and set keepalived high availability, on the back end a real host configuration httpd,mysql,php-fpm; set memcached cache server on this real host (Because of my Computer configuration problem, can not open so many virtual machines, so simply build a bit)

IP configuration:

Directory1 (MASTER):

eno16777736:172.16.72.5

eno16777736:0:172.16.72.1 (Virtual VIP)

eno33554976:192.168.72.1

eno33554976:0:192.168.72.5 (Virtual Dip)

Directory2 (BACKUP):

eno16777736:172.16.72.4

eno33554976:192.168.72.2

RS1:

eno16777736:192.168.72.3

① installation Ansible

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/07/b8ee57df44ba6098cbf12a4376b8ef3e.jpg-wh_500x0-wm_3 -wmp_4-s_2677827236.jpg "title=" qq20171107212437.jpg "alt=" B8ee57df44ba6098cbf12a4376b8ef3e.jpg-wh_ "/>

Networked installation can

② configuring Ansible's hosts Inventory

/etc/ansible/hosts for profile files

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/5b535a7a0bca616b5fba6e9a30c72380.jpg-wh_500x0-wm_3 -wmp_4-s_1668585324.jpg "title=" qq20171107212622.jpg "alt=" 5b535a7a0bca616b5fba6e9a30c72380.jpg-wh_ "/>

The nginxproxy is the real IP of the two hosts that are highly available for the counter server, and the back-end parameters are the variables that exist, which will be mentioned later;

RS is the IP declaration of the backend real host, so that ansible can make different configuration operation for different hosts.

③ Set role roles:

The role roles needs to create a corresponding role directory under/etc/ansible/roles, such as

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/da4c3819dfa53bd45b940ccc68b5cf73.jpg-wh_500x0-wm_3 -wmp_4-s_243630332.jpg "title=" qq20171107212939.jpg "alt=" Da4c3819dfa53bd45b940ccc68b5cf73.jpg-wh_ "/>

Created roles need to be in each directory corresponding to the tasks (tasks) that create the role, handlers,templates, etc. need to use the directory;

Such as

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/07/873a07e6ade0a0e7a1476f97b222bc5c.jpg-wh_500x0-wm_3 -wmp_4-s_1317123798.jpg "title=" qq20171107213248.jpg "alt=" 873a07e6ade0a0e7a1476f97b222bc5c.jpg-wh_ "/>

A directory such as Tasks,handlers,vars needs a master profile main.yml for setting tasks, defining the processing operations and defining variables that are modified by the configuration file, and the templates directory is used to store files transferred by the template module. Files that need to end in J2; files directory is the file used for copying copy module;

④nginx Role Creation:

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/79ec79adbc5e499366862714a02ecb29.jpg-wh_500x0-wm_3 -wmp_4-s_2337066866.jpg "title=" qq20171107221109.jpg "alt=" 79ec79adbc5e499366862714a02ecb29.jpg-wh_ "/>

First task: Send Nginx related yum source, (again not directly installed Nginx, because the network is not connected, using the previous installation Denginx to operate)

The second task: Transfer the configured nginx.conf file, which is stored under/etc/ansible/roles/nginx/templates;

The nginx.conf is well-configured:

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/07/0fa7436a1dcd5d74843767d4c6833d4c.jpg-wh_500x0-wm_3 -wmp_4-s_1928288128.jpg "title=" qq20171107230048.jpg "alt=" 0fa7436a1dcd5d74843767d4c6833d4c.jpg-wh_ "/>

The third task: Configure the Ip_forward core parameters of the Nginx anti-generation server, and can transfer the configuration file for permanent storage;

⑤keepalived Role Creation:

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/07/0d91ca4a5c38c19147b03d6cda8995f4.jpg-wh_500x0-wm_3 -wmp_4-s_752837343.jpg "title=" qq20171107221551.jpg "alt=" 0d91ca4a5c38c19147b03d6cda8995f4.jpg-wh_ "/>

First task: Install keepalived, install with Yum module;

The second task: Transfer the pre-configured keepalived configuration file, and when the configuration file is modified, go to MAIN.YML in the handlers directory to perform the restart service operation, and set the variable parameters in the configuration file as follows:

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/07/e643c68598cc9788dadeed6ff5a718fc.jpg-wh_500x0-wm_3 -wmp_4-s_4009670683.jpg "title=" qq20171107222422.jpg "alt=" E643c68598cc9788dadeed6ff5a718fc.jpg-wh_ "/>

The value of the variable is obtained at the hosts inventory, or it can be written directly in the VARs directory of the role main.yml;

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/5b535a7a0bca616b5fba6e9a30c72380.jpg-wh_500x0-wm_3 -wmp_4-s_1668585324.jpg "title=" qq20171107212622.jpg "alt=" 5b535a7a0bca616b5fba6e9a30c72380.jpg-wh_ "/>

Configuration in Handlers:

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/07/c56bdf578fd7782ff3c9277db95f7aab.jpg-wh_500x0-wm_3 -wmp_4-s_123649891.jpg "title=" qq20171107222713.jpg "alt=" C56bdf578fd7782ff3c9277db95f7aab.jpg-wh_ "/>

The third task: start the keepalived service;


Nginx implementation of the keepalived high-availability dual Master mode:

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/07/e643c68598cc9788dadeed6ff5a718fc.jpg-wh_500x0-wm_3 -wmp_4-s_4009670683.jpg "title=" qq20171107222422.jpg "alt=" E643c68598cc9788dadeed6ff5a718fc.jpg-wh_ "/>

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/07/dfc212cffadb6f4b04fcc01372b037f4.jpg-wh_500x0-wm_3 -wmp_4-s_2033735354.jpg "title=" qq20171107225912.jpg "alt=" Dfc212cffadb6f4b04fcc01372b037f4.jpg-wh_ "/>

⑥ backend Real Server Apache configuration

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/f1e6484d225c4d0eb443fb94cd061ae0.jpg-wh_500x0-wm_3 -wmp_4-s_3282533899.jpg "title=" qq20171107222824.jpg "alt=" F1e6484d225c4d0eb443fb94cd061ae0.jpg-wh_ "/>

First task: Install the httpd;

The second task: Transfer the configured httpd configuration file, if the configuration file is changed, the service can be restarted by notify call handlers;

The httpd.conf is well-configured:

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/07/b01a6de3c1878195db11a3c655e669b3.jpg-wh_500x0-wm_3 -wmp_4-s_2241758266.jpg "title=" qq20171107225743.jpg "alt=" B01a6de3c1878195db11a3c655e669b3.jpg-wh_ "/>

Configuration in Handlers:

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/07/b11a5a8d0320666e52df928fd98925c4.jpg-wh_500x0-wm_3 -wmp_4-s_1645602783.jpg "title=" qq20171107223232.jpg "alt=" B11a5a8d0320666e52df928fd98925c4.jpg-wh_ "/>

The third task: control the HTTPD service, the Httpd_status variable is started by default, you can set the variable by the-E option on the command line;

Configuration in the VARs directory:

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/db6f688fddd79b707e514b615659cca1.jpg-wh_500x0-wm_3 -wmp_4-s_1699649863.jpg "title=" qq20171107223331.jpg "alt=" Db6f688fddd79b707e514b615659cca1.jpg-wh_ "/>

⑦ backend Real server MySQL configuration:

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/07/ceca28cf826244037ddda4f7484e3a07.jpg-wh_500x0-wm_3 -wmp_4-s_1689943989.jpg "title=" qq20171107223452.jpg "alt=" Ceca28cf826244037ddda4f7484e3a07.jpg-wh_ "/>

First task: Install MARIADB, for CENTOS7; use when to verify, determine the host version number;

Second task: Install mysqld, for CENTOS6; use when to verify, determine the host version number;

The third task and the fourth task are to start the corresponding MySQL;

VARs Configuration File Settings:

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/07/edd76b7febedd8e7cc5da103e841fd16.jpg-wh_500x0-wm_3 -wmp_4-s_2251266450.jpg "title=" qq20171107223704.jpg "alt=" Edd76b7febedd8e7cc5da103e841fd16.jpg-wh_ "/>

⑧ backend Real server PHP configuration:

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/07/2d2b53e715f0480b7fb769ce8471d605.jpg-wh_500x0-wm_3 -wmp_4-s_654351594.jpg "title=" qq20171107223801.jpg "alt=" 2d2b53e715f0480b7fb769ce8471d605.jpg-wh_ "/>

First task: Install the PHP-FPM;

Second task: operation of the PHP-FPM service;

Configuration in the VARs directory:

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/07/9338757974ee4029b0d7b7236585aa1e.jpg-wh_500x0-wm_3 -wmp_4-s_3687642067.jpg "title=" qq20171107223914.jpg "alt=" 9338757974ee4029b0d7b7236585aa1e.jpg-wh_ "/>

⑨ back-end Real server memcached configuration:

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/07/d4acd8fa157667f6990d07f1a402a6f6.jpg-wh_500x0-wm_3 -wmp_4-s_2439614268.jpg "title=" qq20171107224412.jpg "alt=" D4acd8fa157667f6990d07f1a402a6f6.jpg-wh_ "/>

First task: Install the memcached;

The second task: Install memcached about the PHP cache required by the software Php-prcl-memcache;

The third task: to transfer the PHP configuration files that need to be PHP cached after installing memcached; (for PHP-FPM) if the configuration file is modified, go to handlers by notify;

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/e07f9cf4f9ee419c9b8abad7a6e23e45.jpg-wh_500x0-wm_3 -wmp_4-s_2160155878.jpg "title=" qq20171107224753.jpg "alt=" E07f9cf4f9ee419c9b8abad7a6e23e45.jpg-wh_ "/>

Handlers:

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/7e71f22d7fe47345008720d3ad30758d.jpg-wh_500x0-wm_3 -wmp_4-s_1478731567.jpg "title=" qq20171107224849.jpg "alt=" 7e71f22d7fe47345008720d3ad30758d.jpg-wh_ "/>

VARs

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/99134ee68672a8cbfbd0df2c915bb22e.jpg-wh_500x0-wm_3 -wmp_4-s_1313141027.jpg "title=" qq20171107224926.jpg "alt=" 99134ee68672a8cbfbd0df2c915bb22e.jpg-wh_ "/>

⑩ Transfer the phpMyAdmin package to the past

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/07/9fc29d5ce3a715310e3b4366955d24f2.jpg-wh_500x0-wm_3 -wmp_4-s_2676977123.jpg "title=" qq20171107225341.jpg "alt=" 9fc29d5ce3a715310e3b4366955d24f2.jpg-wh_ "/>

Put in the files directory;

Then unzip it at the real server;

Final execution

#ansible rs-m shell-a "route add default GW 192.168.72.5"

Let the output of the backend server go to the virtual dip;

Output Result:

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/07/ed4442ed52bb27f314fecc44adffb5a9.jpg-wh_500x0-wm_3 -wmp_4-s_1709568563.jpg "title=" qq20171107225633.jpg "alt=" Ed4442ed52bb27f314fecc44adffb5a9.jpg-wh_ "/>


Ansible implements Nginx dual master mode inversion, keepalived high availability, memcached cache

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.