This article mainly introduces the implementation process of nginx high-availability cluster. The example code in this article is very detailed and has a certain reference value for everyone's study or work. Friends in need can refer to it. 1. Configuration: (1) Two nginx servers are required (2) Keepalived is required (3) A virtual IP is required 2. Preparation for high availability configuration (1) Two servers are required: 192.168.180.113 and 192.168.180.112 (2) Install nginx on both servers (3) Install keepalived on both servers 3. Install keepalived on two servers (1) Install using the yum command (2) After installation, a directory called keepalived is created in etc, and a file called keepalived.conf is created. [root@topcheer dev]# yum install keepalived -y Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.cn99.com * epel: ftp.riken.jp * extras: mirrors.cn99.com * updates: mirror.lzu.edu.cn gitlab_gitlab-ce/x86_64/signature | 836 B 00:00:00 gitlab_gitlab-ce/x86_64/signature | 1.0 kB 00:00:00 !!! gitlab_gitlab-ce-source/signature | 836 B 00:00:00 gitlab_gitlab-ce-source/signature | 951 B 00:00:00 !!! Resolving dependencies--> Checking transactions---> Package keepalived.x86_64.0.1.3.5-16.el7 will be installed--> Processing dependency libnetsnmpmibs.so.31()(64bit), which is needed by package keepalived-1.3.5-16.el7.x86_64--> Processing dependency libnetsnmpagent.so.31()(64bit), which is needed by 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--> Dependency resolution completed Dependency resolution ========================================================================================================================================== Package Architecture Version Source Size === ... Installing: keepalived x86_64 1.3.5-16.el7 base 331 k Install for dependencies: net-snmp-agent-libs x86_64 1:5.7.2-43.el7 base 706 k Transaction Summary= ... Install 1 package (+1 dependent package) Total downloads: 1.0M Installation size: 3.0 M Downloading packages: (1/2): net-snmp-agent-libs-5.7.2-43.el7.x86_64.rpm | 706 kB 00:00:00 (2/2): keepalived-1.3.5-16.el7.x86_64.rpm | 331 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------------ Total 1.8 MB/s | 1.0 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing: 1:net-snmp-agent-libs-5.7.2-43.el7.x86_64 1/2 Installing: keepalived-1.3.5-16.el7.x86_64 2/2 Verifying: keepalived-1.3.5-16.el7.x86_64 1/2 Verifying: 1:net-snmp-agent-libs-5.7.2-43.el7.x86_64 2/2 Installed: keepalived.x86_64 0:1.3.5-16.el7 Installed as a dependency: net-snmp-agent-libs.x86_64 1:5.7.2-43.el7 complete! 4. Modify the configuration file Both need to be replaced, one master and one slave [root@topcheer keepalived]# cat keepalived.conf global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] 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 # (interval between detection script execution) weight 2 } vrrp_instance VI_1 { state BACKUP # Change MASTER to BACKUP on the backup server interface ens33 //Network card virtual_router_id 51 # The virtual_router_id of the master and backup machines must be the same priority 40 # The master and backup machines have different priorities, the master has a larger value and the backup has a smaller 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 nginx_check.sh #!/bin/bash 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 fi fi[root@topcheer src]# Start nginx and keepalived on both servers Start nginx: ./nginx Since I installed gitlab's own nginx on 112, I don't need to start it. Start keepalived: systemctl start keepalived.service 5. Testing Turn off nginx and keepalived on 113 and find that it will switch to 112 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. You may also be interested in:
|
<<: How to use webSocket to update real-time weather in Vue
>>: How to add, delete and modify columns in MySQL database
background Last week the company trained on MySQL...
I just started learning database operations. Toda...
This article will introduce how to query data in ...
1. Four startup methods: 1.mysqld Start mysql ser...
I divide the whole process into four steps: Downl...
1. Create a scheduling task instruction crontab -...
The so-called three-column adaptive layout means ...
1. View openjdk rpm -qa|grep jdk 2. Delete openjd...
need Add a paging bar, which can jump to the page...
1. Environmental Preparation Tencent Cloud Server...
Click here to return to the 123WORDPRESS.COM HTML ...
This article uses examples to describe the basic ...
The “Cancel” button is not part of the necessary ...
Classification of website experience 1. Sensory e...
The installation tutorial of mysql 8.0.11 winx64 ...