Why a high availability configuration is needed
Single Nginx Load balance the whole system , If nginx Hang up , Then the whole system will crash , At this point, we need to make sure we're on time 1 individual Nginx Hang up , The whole system is also available .
Now we need to implement Nginx High availability ,nginx High availability needs to be matched with keepalived Together .
The deployment of two Linux node ,ip Respectively 192.168.12.120 and 198.168.12.121, To start, respectively, nginx
yum install -y keepalived
modify /etc/keepalived/keepalivec.conf The configuration file
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.17.129
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/usr/local/src/nginx_check.sh"
interval 2 #( Detects the interval between script execution )
weight 2
}
vrrp_instance VI_1 {
state BACKUP
# On the backup server MASTER Change it to BACKUP
interface ens33 // network card
virtual_router_id 51
# Lord 、 Standby virtual_router_id It has to be the same
priority 90
# Lord 、 The standby machine takes different priorities , The main engine is worth a lot , The value of the backup machine is small
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.12.150 // VRRP H Virtual address
}
}
stay /usr/local/src Add detection script
#!/bin/bash
A=`ps -C nginx –no-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
Put two servers on nginx and keepalived start-up
start-up nginx:./nginx
start-up keepalived:systemctl start keepalived.service
Enter in the address bar 192.168.12.150:8088
Successful visit
From the node ,
take master Corresponding nginx and keepalived Stop
The service is still available .
Indicates that the configuration is in effect .