Keepalived achieves high Nginx availability
Keepalived achieves high Nginx availability
1. Install keepalived using yum
Yum install keepalived-y
2. modify the configuration file keepalived. conf.
Master server configuration file
Global_defs {
Router_id NodeA
}
Vrrp_script check_run {
Script "/etc/keepalived/check_nginx.sh" # customize the nginx check script
Interval 2
Weight 2
}
Vrrp_instance VI_1 {
State MASTER # set as MASTER server
Interface eth0 # Monitoring Network interface
Virtual_router_id 51 # Master and backup must be the same
Priority 100 # (the master and slave servers have different priorities. The host value is large and the backup server value is small. The larger the value, the higher the priority)
Advert_int 1 # VRRP Multicast broadcast period seconds
Authentication {
Auth_type PASS # VRRP authentication method, Master/backup must be consistent
Auth_pass 1111 # (password)
}
Track_script {
Check_run
}
Virtual_ipaddress {
Virtual IP Address/mask # vrrp ha virtual IP Address
}
}
Backup Server Configuration File
Global_defs {
Router_id NodeB
}
Vrrp_script check_run {
Script "/etc/keepalived/check_nginx.sh"
Interval 2
Weight 2
}
Vrrp_instance VI_1 {
State BACKUP # set as the master server
Interface eth0 # Monitoring Network interface
Virtual_router_id 51 # Master and backup must be the same
Priority 90 # (the master and slave servers have different priorities. The host value is large and the backup server value is small. The larger the value, the higher the priority)
Advert_int 1 # VRRP Multicast broadcast period seconds
Authentication {
Auth_type PASS # VRRP authentication method, Master/backup must be consistent
Auth_pass 1111 # (password)
}
Track_script {
Check_run
}
Virtual_ipaddress {
Virtual IP Address/mask # vrrp ha virtual IP Address
}
}
3. The master and slave servers start the keepalived and nginx services.
/Etc/init. d/keepalived start
/Etc/init. d/nginx start
Check whether the virtual IP address of the master server exists
Ip addr
Disable the keepalived Service of the master server and test whether the virtual IP address is switched to the backup server.
HAProxy + Keepalived dual-host high availability solution in Linux
Haproxy + Keepalived build Weblogic high-availability server Load balancer Cluster
Keepalived + HAProxy configure high-availability Load Balancing
Haproxy + Keepalived + Apache configuration notes in CentOS 6.3
Haproxy + KeepAlived WEB Cluster on CentOS 6
Haproxy + Keepalived build high-availability Load Balancing
This article permanently updates the link address: