keepalived.conf之vrrp instance部分解读

下面是对这个配置的解释

	state MASTER|BACKUP
02	#如果不指定Master或者BACKUP,那priority最高的就是master
03	
04	interface eth0
05	#监听的实际网口
06	
07	virtual_router_id 51
08	#组播ID,通过224.0.0.18可以监听到现在已经存在的VRRP ID,最好不要跟现有ID冲突
09	
10	priority 100
11	#权重为100,权重数字越大就越高
12	
13	advert_int 1
14	#发送组播包的间隔时间,默认为1秒
15	
16	smtp_alert
17	#发送邮件报警
18	
19	authentication {
20	auth_type PASS
21	auth_pass hdtv
22	}
23	#这个是验证类型为PASS(明文),密码为hdtv。验证类型也可以选择IPSEC,但是官方是不推荐的
24	
25	virtual_ipaddress {
26	10.1.41.141
27	}
28	#虚拟IP为10.1.41.141
29	
30	#############下面这些是文档中存在,但是在上面没有用到的#############################
31	
32	dont_track_primary
33	#忽略网卡错误
34	
35	track_interface {
36	eth0
37	eth1
38	}
39	#监控eth0和eth1这2块网卡的状态
40	
41	mcast_src_ip
42	#使用这个地址作为多播包的源IP,而不是使用interface eth0上的IP
43	
44	lvs_sync_daemon_interface eth1
45	#绑定eth1作为lvs同步的
46	
47	garp_master_delay 2
48	#master和slave漂移时间改为2秒,默认位5秒,怪不得我昨天发现每次都是5秒才转移
49	
50	virtual_ipaddress {
51	/ brd dev scope label 192.168.200.17/24 dev eth1
52	192.168.200.18/24 dev eth2 label eth2:1
53	}
54	#vip可以写成整个网段和某块网卡上的所有IP
55	
56	virtual_ipaddress_excluded {
57	/ brd dev scope / brd dev scope ...
58	}
59	#排除哪些IP
60	
61	virtual_routes {
62	src 192.168.100.1 to 192.168.109.0/24 via 192.168.200.254 dev eth1 192.168.110.0/24 via192.168.200.254 dev eth1 192.168.111.0/24 dev eth2 192.168.112.0/24 via 192.168.100.254
63	}
64	#当状态切换的时候会增加和删除路由,格式如src [to] / via|gw dev scope tab
65	
66	nopreempt
67	#这个参数是用来,当master当掉,slave接替原来的master作为master后,这个时候当master重新起来后,有了这个参数后原来的slave就不会自动再自动切换为slave,而是继续作为master
68	
69	preempt_delay 300
70	#接上面那个参数,这个表示,只有在老的master重新正常300秒后,老的master才会切换为master,这个参数范围是0-1000,默认为0
71	
72	notify_master | notify_backup
73	| notify_fault | notify |
74	smtp_alert
75	#各种报警方式,可以定义具体的内容来达到不同的报警信息。

上面这些是官方的配置文件,下面这些是放狗搜索出来的其它配置,主要是为了做服务状态的检测,不然keepalived只能看网口有没有down掉再进行迁移,那样就要另外写其它的监控脚本来达到当服务挂掉后就把网口down掉。
下面这个是从邮件列表中抄袭而来,但是没有测试过,明日会找时间进行测试。下面这个是在1.1.13版本之后就实现了。

01	! Configuration File for keepalived
02	vrrp_script chk_sshd {
03	script "killall -0 sshd" # cheaper than pidof
04	interval 2 # check every 2 seconds weight -4 # default prio: -4 if KO }
05	vrrp_script chk_haproxy {
06	script "killall -0 haproxy" # cheaper than pidof
07	interval 2 # check every 2 seconds }
08	vrrp_script chk_http_port {
09	script "/tcp/127.0.0.1/80" # connects and exits
10	interval 1 # check every second
11	weight -2 # default prio: -2 if connect fails
12	}
13	vrrp_script chk_https_port {
14	script "/tcp/127.0.0.1/443"
15	interval 1
16	weight -2
17	}
18	vrrp_script chk_smtp_port {
19	script "/tcp/127.0.0.1/25"
20	interval 1
21	weight -2
22	}
23	vrrp_instance VI_1 {
24	interface eth0
25	state MASTER
26	virtual_router_id 51
27	priority 100
28	virtual_ipaddress {
29	192.168.200.18/25
30	}
31	track_interface {
32	eth1 weight 2 # prio = +2 if UP
33	eth2 weight -2 # prio = -2 if DOWN
34	eth3 # no weight, fault if down
35	}
36	track_script {
37	chk_sshd # use default weight from the script chk_haproxy weight 2 # +2 if process is present
38	chk_http_port
39	chk_https_port
40	chk_smtp_port
41	}
42	}
43	vrrp_instance VI_2 {
44	interface eth1
45	state MASTER
46	virtual_router_id 52
47	priority 100
48	virtual_ipaddress {
49	192.168.201.18/26
50	}
51	track_interface {
52	eth0 weight 2 # prio = +2 if UP
53	eth2 weight -2 # prio = -2 if DOWN
54	eth3 # no weight, fault if down
55	}
56	track_script {
57	chk_haproxy weight 2
58	chk_http_port
59	chk_https_port
60	chk_smtp_port
61	}
62	}

转自:http://www.360doc.com/content/12/0907/18/834950_234870743.shtml

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值