<< 安装配置keepalived 使nginx高可用 | 首页 | 使用 GNU profiler 来提高代码运行速度 >>

keepalived手册中未更新的功能挖掘及使用介绍_李小红_新浪博客

vrrp_script chk_sshd {
 script "killall -0 sshd"    # cheaper than pidof
 interval 2         # check every 2 seconds
 weight -4        # default prio: -4 if KO
}

vrrp_script chk_haproxy {
 script "killall -0 haproxy"    # cheaper than pidof
 interval 2        # check every 2 seconds
}

vrrp_script chk_http_port {
 script "/tcp/127.0.0.1/80"    # connects and exits
 interval 1        # check every second
 weight -2        # default prio: -2 if connect fails
}

vrrp_script chk_https_port {
 script "/tcp/127.0.0.1/443"
 interval 1
 weight -2
}

vrrp_script chk_smtp_port {
 script "/tcp/127.0.0.1/25"
 interval 1
 weight -2
}

vrrp_instance VI_1 {
 interface eth0  state MASTER  virtual_router_id 51  priority 100   virtual_ipaddress {
  192.168.200.18/25
 }

 track_interface {
  eth1 weight 2      # prio = +2 if UP
  eth2 weight -2      # prio = -2 if DOWN
  eth3        # no weight, fault if down
 }

 track_script {
  chk_sshd       # use default weight from the script
  chk_haproxy weight 2    # +2 if process is present
  chk_http_port
  chk_https_port
  chk_smtp_port
 }
}

vrrp_instance VI_2 {
 interface eth1  state MASTER  virtual_router_id 52  priority 100   virtual_ipaddress {
  192.168.201.18/26
 }

 track_interface {
  eth0 weight 2      # prio = +2 if UP
  eth2 weight -2      # prio = -2 if DOWN
  eth3        # no weight, fault if down
 }

 track_script {
  chk_haproxy weight 2
  chk_http_port
  chk_https_port
  chk_smtp_port
 }
}
1、vrrp_script和track_script
track_script指定检查脚本,定期运行它们来改变优先级,并最终引发主备切换。如果配过交换机的vrrp/hsrp部分的话,应该对这个功能比较熟悉
2、notify_stop
keepalived停止运行前运行notify_stop指定的脚本

下面是我这边应用上面两个功能介绍:
1、两台双master台数据库,用keepalivd的vrrp模式给客户端提供一个HA的虚拟IP
这个要求检查mysql数据库的状态,如果mysql出现问题,就降低优先级,这样虽然机器正常,也会引发新一轮的master选举,以保证mysql服务的高可用性

先定义两个检查脚本
vrrp_script chk_mysqld {
   script "/usr/bin/mysqladmin -u ganglia extended-status -pganglia_status | grep -q Slave_running"
   interval 10  # check every 10 seconds
   weight -40   # if failed, decrease 40 of the priority
   fall   3     # require 2 failures for failures
   rise   1     # require 1 sucesses for ok
}

vrrp_script chk_schedown {
   script "if [ -f /var/run/down ]; then exit 1; else exit 0; fi"
   interval 10  # check every 10 seconds
   weight -40   # if failed, decrease 40 of the priority
   fall   1     # require 2 failures for failures
   rise   1     # require 1 sucesses for ok
}
上面的chk_schedown脚本,给管理员提供一个切换的地方,如果管理员在master上手工touch /var/run/down,这样,流量会比这台机器上切走了。

阅读全文……

标签 : ,



发表评论 发送引用通报