keepalive+redis 增量和全部同步

 

 

1 安装keepalived

wget http://www.keepalived.org/software/keepalived-1.2.24.tar.gz -P /export1/soft/
cd /export1/soft/
tar zxvf keepalived-1.2.24.tar.gz
cd keepalived-1.2.24
yum install ipvsadm kernel-devel popt-devel openssl-* -y
ln -s /usr/src/kernels/2.6.32-696.13.2.el6.x86_64/ /usr/src/linux
yum update glib* -y
./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir -pv /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/
chmod 755 /etc/init.d/keepalived
mkdir /etc/keepalived/scripts/
service keepalived start
service keepalived stop
>/etc/keepalived/keepalived.conf

###########################################################################

2 主上边:10.5.2.10 vim /etc/keepalived/keepalived.conf

global_defs {
router_id redis1101
}
vrrp_script chk_redis {
script "/etc/keepalived/scripts/redis_check.sh"
interval 1
}
vrrp_instance v_r1 {
state MASTER
interface eth0
#garp_master_delay 10
virtual_router_id 18
priority 100
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.5.2.18
}
track_script {
chk_redis
}
notify_master /etc/keepalived/scripts/redis_master.sh
notify_backup /etc/keepalived/scripts/redis_slave.sh
notify_fault /etc/keepalived/scripts/redis_fault.sh
notify_stop /etc/keepalived/scripts/redis_stop.sh
}

###########################################################

vim  /etc/keepalived/scripts/redis_check.sh

#!/bin/bash

ALIVE=`/usr/local/bin/redis-cli -h 10.5.2.10 PING`

if [ "$ALIVE" == "PONG" ]; then

echo $ALIVE

exit 0

else

echo $ALIVE

exit 1

fi

###########################################################################

vim  /etc/keepalived/scripts/redis_fault.sh 

#!/bin/bash
LOGFILE=/var/log/keepalived-redis-state.log
echo "[fault]" >> $LOGFILE
date >> $LOGFILE

##########################################################

vim  /etc/keepalived/scripts/redis_stop.sh 

#!/bin/bash
LOGFILE=/var/log/keepalived-redis-state.log
echo "[stop]" >> $LOGFILE
date >> $LOGFILE

#############################################################

vim /etc/keepalived/scripts/redis_master.sh

#!/bin/bash
REDISCLI=/usr/local/bin/redis-cli
LOGFILE=/var/log/keepalived-redis-state.log
LOCALIP="10.5.2.10"
REMOTEIP="10.5.2.11"
PORT="6379"
echo "[master]" >> $LOGFILE
date >> $LOGFILE
echo "Beging master..." >> $LOGFILE 2>&1
echo "Run SLAVEOF cmd ..." >> $LOGFILE
$REDISCLI -h $LOCALIP -p 6379 SLAVEOF $REMOTEIP 6379 >> $LOGFILE 2>&1
sleep 10
echo "Run SLAVEOF NO ONE cmd..." >> $LOGFILE
$REDISCLI -h $LOCALIP -p 6379 SLAVEOF NO ONE >> $LOGFILE 2>&1

######################################################################

vim /etc/keepalived/scripts/redis_slave.sh

#!/bin/bash
REDISCLI="/usr/local/bin/redis-cli"
LOGFILE="/var/log/keepalived-redis-state.log"
LOCALIP="10.5.2.10"
REMOTEIP="10.5.2.11"
PORT="6379"
echo "[backup]" >> $LOGFILE
date >> $LOGFILE
echo "Begingslave..." >> $LOGFILE 2>&1
sleep15
echo "Run SLAVEOF cmd...">> $LOGFILE
$REDISCLI -h $LOCALIP -p 6379 SLAVEOF $REMOTEIP 6379 >> $LOGFILE 2>&1

################################################################################

 

 

 

 

 #######################################################################################################

切换状态

 

 

转载于:https://www.cnblogs.com/qtxdy/p/7754757.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值