配置keepalived+ssdb高可用

  1. 云栖社区>
  2. 博客>
  3. 正文

配置keepalived+ssdb高可用

javalxs 2017-02-03 16:56:48 浏览1982
展开阅读全文

在前两篇已完成keepalived的安装及service配置,ssdb在此处不再说明,可以参考ssdb官网说明:http://ssdb.io/zh_cn


以下介绍一下如何结合keepalived+ssdb搭建ssdb高可用环境。


1.配置ssdb的监控命令及脚本

由于ssdb可以兼容redis,所以这里使用redis-cli工具来监控ssdb server。

(1)下载redis server source code

(2)在redis code目录下make

(3)将make好的redis-cli复制到/usr/local/redis_tools目录下

2.配置监控脚本,内容如下:

#!/bin/bash
LOGFILE="/var/log/keepalived-ssdb-check.log"
if [ "`/usr/local/redis_tools/redis-cli -h $1 -p $2 PING`" == "PONG" ]; then :
   exit 0
else
   sleep 1
   if [ "`/usr/local/redis_tools/redis-cli -h $1 -p $2 PING`" == "PONG" ]; then :
      exit 0
   else
      date >> $LOGFILE
      echo "Failed:redis-cli -h $1 -p $2 PING" >> $LOGFILE 2>&1
      service keepalived stop
      exit 1
   fi
fi

3.配置keepalived vrrp 内容如下:

keepalived 实例1:Master节点

global_defs {
    notification_email {
        tt@lxs.com.cn
    }
    notification_email_from alert@lxs.com.cn
    smtp_server smtp.exmail.lxs.com
    smtp_connect_timeout 30
    enable_traps
    router_id SSDBKVM01
}

vrrp_script chk_ssdb {
    script "/etc/keepalived/check_ssdb.sh 127.0.0.1 8888"
    interval 2
    weight -2
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    mcast_src_ip 192.168.124.64
    virtual_router_id 101
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    track_script {
        chk_ssdb
    }
    virtual_ipaddress {
        192.168.124.101/24
    }
}

keepalived 实例2:Backup节点

global_defs {
    notification_email {
        tt@lxs.com.cn
    }
    notification_email_from alert@lxs.com.cn
    smtp_server smtp.exmail.lxs.com
    smtp_connect_timeout 30
    enable_traps
    router_id SSDBKVM01
}

vrrp_script chk_ssdb {
    script "/etc/keepalived/check_ssdb.sh 127.0.0.1 8888"
    interval 2
    weight -2
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    mcast_src_ip 192.168.124.65
    virtual_router_id 101
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    track_script {
        chk_ssdb
    }
    virtual_ipaddress {
        192.168.124.101/24
    }
}


其中,virtual_router_id 取值在0-255之间,用来区分多个instance的VRRP组播。在同一网段内virtual_router_id值不能重复,否则会报错:ip address associated with VRID not present in received packet


保存上面的内容,重新加载配置文件。

service keepalived reload


网友评论

登录后评论
0/500
评论
javalxs
+ 关注