ibaobei 发表于 2018-12-29 07:14:38

keepalived 多实例

  8.13和8.14的keepalived配置文件

  8.13上的如下:
  $ pwd
  /etc/keepalived
  $ ls
  keepalived.confscripts
  $ cd scripts/
  $ ls
  chk_haproxy.shnotify.sh
  $ cat chk_haproxy.sh
  #!/bin/bash
  pid=`ps -C haproxy --no-header |wc -l`
  if [ $pid -eq 0 ];then
  service haproxy start
  sleep 2
  if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
  service keepalived stop
  fi
  fi
  $ cat notify.sh
  #!/bin/bash
  Date=`date +%Y%m%d-%l:%M`
  echo $Date>>/var/log/sms.log
  echo "will send sms " >> /var/log/sms.log
  

  Content="haproxy $(hostname) into $1"
  Mobile="156********"
  wget --post-data="token=***&mobile=$Mobile&content=$Content" http://sms.service.domain.com/task/create -O /dev/null
  echo "send sms finish $Content $Mobile" >> /var/log/sms.log
  #echo "Mobile=$Mobile   Content=$Content"
  $
  $ cat keepalived.conf
  global_defs {
  notification_email {
  robin@qq.com
  }
  notification_email_from haproxy-support@qq.com
  

  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  

  router_id HAPROXY
  }
  vrrp_script chk_haproxy {
  script "/etc/keepalived/scripts/chk_haproxy.sh"
  interval 4
  #weight 2
  }
  

  vrrp_sync_group VG1 {
  group {
  VI1_GATEWAY
  }
  }
  vrrp_sync_group VG2 {
  group {
  VI2_GATEWAY
  }
  }
  

  

  vrrp_instance VI1_GATEWAY {
  state MASTER
  interface eth0
  lvs_sync_daemon_interface eth0
  

  virtual_router_id 56
  priority 51
  smtp_alert
  advert_int 1
  sorry_server 127.0.0.1 80
  

  authentication {
  auth_type PASS
  auth_pass hapass8
  }
  track_script {
  chk_haproxy
  }
  

  virtual_ipaddress {
  192.168.8.50
  192.168.8.51
  192.168.8.52
  192.168.8.53
  192.168.8.54
  192.168.8.55
  192.168.8.56
  192.168.8.57
  192.168.8.58
  192.168.8.59
  }
  notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
  notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
  }
  vrrp_instance VI2_GATEWAY {
  state MASTER
  interface eth0
  lvs_sync_daemon_interface eth0
  

  virtual_router_id 57
  priority 50
  smtp_alert
  advert_int 1
  sorry_server 127.0.0.1 80
  

  authentication {
  auth_type PASS
  auth_pass hapass8
  }
  track_script {
  chk_haproxy
  }
  

  virtual_ipaddress {
  192.168.8.60
  192.168.8.61
  192.168.8.62
  192.168.8.63
  192.168.8.64
  192.168.8.65
  }
  notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
  notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
  }
  

  #include conf.d/*.conf
  $
  

  8.14上如下:
  # pwd
  /etc/keepalived
  # ls
  keepalived.confscripts
  # cd scripts/
  # ls
  chk_haproxy.shnotify.sh
  # cat chk_haproxy.sh
  #!/bin/bash
  pid=`ps -C haproxy --no-header |wc -l`
  if [ $pid -eq 0 ];then
  service haproxy start
  sleep 2
  if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
  service keepalived stop
  fi
  fi
  # cat notify.sh
  #!/bin/bash
  Date=`date +%Y%m%d-%l:%M`
  echo $Date>>/var/log/sms.log
  echo "will send sms " >> /var/log/sms.log
  

  Content="haproxy $(hostname) into $1"
  Mobile="156********" #过个手机号,用逗号分隔
  wget --post-data="token=51********&mobile=$Mobile&content=$Content" http://sms.service.domain.com/task/create -O /dev/null
  echo "send sms finish $Content $Mobile" >> /var/log/sms.log
  #echo "Mobile=$Mobile   Content=$Content"
  #
  # cat keepalived.conf
  global_defs {
  notification_email {
  robin@qq.com
  }
  notification_email_from haproxy-support@qq.cn
  

  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  

  router_id HAPROXY
  }
  vrrp_script chk_haproxy {
  script "/etc/keepalived/scripts/chk_haproxy.sh"
  interval 4
  #weight 2
  }
  

  vrrp_sync_group VG1 {
  group {
  VI1_GATEWAY
  }
  }
  vrrp_sync_group VG2 {
  group {
  VI2_GATEWAY
  }
  }
  

  

  vrrp_instance VI1_GATEWAY {
  state MASTER
  interface eth0
  lvs_sync_daemon_interface eth0
  

  virtual_router_id 56
  priority 50
  smtp_alert
  advert_int 1
  sorry_server 127.0.0.1 80
  

  authentication {
  auth_type PASS
  auth_pass hapass8
  }
  track_script {
  chk_haproxy
  }
  

  virtual_ipaddress {
  192.168.8.50
  192.168.8.51
  192.168.8.52
  192.168.8.53
  192.168.8.54
  192.168.8.55
  192.168.8.56
  192.168.8.57
  192.168.8.58
  192.168.8.59
  }
  notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
  notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
  }
  vrrp_instance VI2_GATEWAY {
  state MASTER
  interface eth0
  lvs_sync_daemon_interface eth0
  

  virtual_router_id 57
  priority 51
  smtp_alert
  advert_int 1
  sorry_server 127.0.0.1 80
  

  authentication {
  auth_type PASS
  auth_pass hapass8
  }
  track_script {
  chk_haproxy
  }
  

  virtual_ipaddress {
  192.168.8.60
  192.168.8.61
  192.168.8.62
  192.168.8.63
  192.168.8.64
  192.168.8.65
  }
  notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
  notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
  }
  

  #include conf.d/*.conf
  #



页: [1]
查看完整版本: keepalived 多实例