Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Implementation of nginx High availability Cluster

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you the implementation of nginx high availability cluster, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Configuration:

(1) two nginx servers are required. (2) keepalived is required. (3) Virtual ip is required.

2. Configure highly available preparations

(1) two servers 192.168.180.113 and 192.168.180.112 (2) install nginx on two servers (3) install keepalived on two servers

3. Install keepalived on two servers

(1) use yum command to install

(2) after installation, generate a directory keepalived and a file keepalived.conf in etc

[root@topcheer dev] # yum install keepalived-y loaded plug-in: fastestmirror LangpacksLoading mirror speeds from cached hostfile * base: mirrors.cn99.com * epel: ftp.riken.jp * extras: mirrors.cn99.com * updates: mirror.lzu.edu.cngitlab_gitlab-ce/x86_64/signature | 836B 00:00:00gitlab_gitlab-ce/x86_64/signature | 1.0 kB 00:00:00! ! gitlab_gitlab-ce-source/signature | 836B 00:00:00gitlab_gitlab-ce-source/signature | 951B 00:00:00! Resolving dependencies-- > checking transactions-- > package keepalived.x86_64.0.1.3.5-16.el7 will be installed-- > processing dependencies libnetsnmpmibs.so.31 () (64bit), which is required by package keepalived-1.3.5-16.el7.x86_64-- > processing dependencies libnetsnmpagent.so.31 () (64bit) It is required by the package keepalived-1.3.5-16.el7.x86_64-- > checking transactions-> package net-snmp-agent-libs.x86_64.1.5.7.2-43.el7 will be installed-- > resolve dependencies complete dependency resolution = Package schema version source is large Small = installing: keepalived x86ip64 1.3.5-16.el7 base 331k for dependency installation: net-snmp-agent-libs x86x61purl 5.7.2-43.el7 base 706k transaction summary = = install 1 package (+ 1 dependent package) total downloads : 1.0m installation size: 3.0m MDownloading packages: (1 MDownloading packages 2): net-snmp-agent-libs-5.7.2-43.el7.x86_64.rpm | 706 kB 00:00:00 (2 amp 2): keepalived-1.3.5-16.el7.x86_64.rpm | 331 kB 00 kB 00lv 00lue- - -Total 1. 8 MB/s | 1. 0 MB 00:00:00Running transaction checkRunning transaction testTransaction test succeededRunning transaction is being installed: 1:net-snmp-agent-libs-5.7.2-43.el7.x86_64 1 Candle 2 is being installed Installation: keepalived-1.3.5-16.el7.x86_64 2amp 2 Verification: keepalived-1.3.5-16.el7.x86_64 1 Accord 2 Verification: 1:net-snmp-agent-libs-5.7.2-43.el7.x86_64 2 keepalived.x86_64 2 has been installed: net-snmp-agent-libs.x86_64 0 net-snmp-agent-libs.x86_64 1.3.5-43.el7 is installed as a dependency: 43.el7 is over!

4. Modify the configuration file

Two sets have to be replaced, one host and one slave.

[root@topcheer keepalived] # cat keepalived.confglobal_defs {notification_email {acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc} notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.180.113 smtp_connect_timeout 30 router_id LVS_DEVEL} vrrp_script chk_http_port {script "/ usr/local/src/nginx_check.sh" interval 2 # (detection script execution interval) weight 2} Vrrp_instance VI_1 {state BACKUP # backup server change MASTER to BACKUP interface ens33 / / network card virtual_router_id 51 # master, The virtual_router_id of the standby must be the same as that of the priority 40 # master and standby with different priorities Larger host value, smaller backup machine value advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.180.114 / / VRRP H virtual address}}

Script:

[root@topcheer src] # cat nginxboxes check.shrunk hash A = `ps-C nginx ▒ Cno-header | wc-l`if [$A-eq 0]; then / usr/local/nginx/sbin/nginx sleep 2 if [`ps-C nginx-- no-header | wc-l`-eq 0]; then killall keepalived fifi [root@topcheer src] #

Start nginx and keepalived on two servers

Start nginx:./nginx since I have installed gitlab with nginx on my 112, do not start keepalived:systemctl start keepalived.service

5. Test

Turn off the nginx and keepalived of 113, and find that it will switch to 112.

The above is the implementation of nginx high availability cluster. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report