传统运维 - Keepalive

2021-04-12

Master

global_defs {
	router_id nginx
	script_user root
	enable_script_security
}


vrrp_script chk_nginx {
	script	"/usr/bin/nmap 127.0.0.1 -p80 | grep open"
	timeout 1
	interval 1	# check every 1 second
	fall 2	# require 2 failures for KO
	rise 2	# require 2 successes for OK
}

vrrp_instance VI_1 {
	state MASTER
	interface ens192
	virtual_router_id 51
	priority 100
	advert_int 1
	track_script {
		chk_nginx
	}
	authentication {
		auth_type PASS
		auth_pass nginx-lb
	}
	virtual_ipaddress {
		192.168.150.19
	}
}

Backup

global_defs {
	router_id nginx
	script_user root
	enable_script_security
}


vrrp_script chk_nginx {
	script	"/usr/bin/nmap 127.0.0.1 -p80 | grep open"
	timeout 1
	interval 1	# check every 1 second
	fall 2	# require 2 failures for KO
	rise 2	# require 2 successes for OK
}

vrrp_instance VI_1 {
	state BACKUP
	interface ens192
	virtual_router_id 51
	priority 90
	advert_int 1
	track_script {
		chk_nginx
	}
	authentication {
		auth_type PASS
		auth_pass nginx-lb
	}
	virtual_ipaddress {
		192.168.150.19
	}
}