1, the installation is used by Yum
Nginx is the official latest source
[Nginx]
Name=nginx Repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
Gpgcheck=0
Enabled=1
Yum Install Nginx keepalived-y
2,keepalived configuration file.
Master: Configuration file contents
[Email protected] opt]# cat/etc/keepalived/keepalived.conf
! Configuration File for Keepalived
Vrrp_script Chk_http_port {
Script "/opt/nginx_pid.sh"
Interval 2
Weight-5
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 81
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Chk_http_port
}
virtual_ipaddress {
172.16.226.100
}
notify_master/tmp/keep.sh
notify_backup/tmp/keep.sh
notify_fault/tmp/keep.sh
notify_stop/tmp/keep.sh
}
From: Configuration file contents.
[Email protected] ~]# cat/etc/keepalived/keepalived.conf
! Configuration File for Keepalived
Vrrp_script Chk_http_port {
Script "/opt/nginx_pid.sh"
Interval 2
Weight-5
}
Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 81
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Chk_http_port
}
virtual_ipaddress {
172.16.226.100
}
notify_master/tmp/keep_master.sh
notify_backup/tmp/keep_backup.sh
notify_fault/tmp/keep_fault.sh
notify_stop/tmp/keep_stop.sh
}
Nginx Related script:
[Email protected] ~]# cat/opt/nginx_pid.sh
#!/bin/bash
A= ' ps-c nginx--no-header|wc-l '
If [$A-eq 0];then
/usr/sbin/nginx-c/etc/nginx/nginx.conf
Sleep 3
If [' Ps-c nginx--no-header|wc-l '-eq 0];then
Killall keepalived
Fi
Fi
Test Two servers VIP switch is smooth, nginx related script execution is normal, it should be noted that the script to have execute permissions.
Keepalived+nginx Nginx High Availability (personal simple not detailed record)