第一章:Redis+twemproxy+keepalive+ sentinel实现完整的redis集群方案实验

Redis集群

1.  背景描述

Redis+twemproxy+keepalive+ sentinel实现完整的redis集群方案

 

Redis:缓存服务器

Twemproxy:redis的负载均衡代理服务器,主要对redis的多主从复制集群进行负载均衡

Keepalive:主要作用是对twemproxy进行容灾,实现twemproxy的高可用

Sentinel:主要作用于redis的主从复制集群的master故障后从新选举新的master

2.  环境

主从集群

服务器(redis)

146

147

148

149

Master(一)

 

 

 

-        Slave1(6479)

 

 

 

-        Slave2(6378)

 

 

 

Master(二)

 

 

 

-        Slave1(6379)

 

 

 

-        Slave2(6378)

 

 

 

Twemproxy

 

 

Keepalive

 

 

 

3.  安装redis

1.     安装

2.     缺少gcc编译器


3.     依赖软件

yum install wget make gcc gcc-c++

yum -y install tcl

 

4.     Make 编译包不对

5.     安装完测试

 

//安装完成后,会/usr/local/redis/bin/目录下生成5个可执行文件,

. ls /usr/local/redis/bin/

– redis-benchmark redis-check-aof redis-check-dump redis-cliredis-server

– redis-server:Redis服务器的daemon启动程序

– redis-cli:Redis命令行操作工具。

– redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性

– redis-benchmark -h 10.6.2.245 -p 6379 -q -d 500

– redis-check-dump: 检查file.rdb 文件

– redis-check-aof:检查file.aof 文件

. http://blog.chinaunix.net/uid-790245-id-3766268.html

 

--安装完成后

上面的执行文件,可能直接在redis/src下

 

6.     四台服务器全部安装

 

4.  安装twemproxy

1.     下载安装包

git clonehttps://github.com/twitter/twemproxy.git

cd twemproxy/

CFLAGS="-ggdb3 -O0" autoreconf-fvi && ./configure --prefix=/usr/local/twemproxy  --enable-debug=log

 

2.     编译的时候报错

autoreconf: Entering directory `.'

autoreconf: configure.ac: not using Gettext

autoreconf: running: aclocal --force -I m4

configure.ac:8: error: Autoconf version2.64 or higher is required

configure.ac:8: the top level

autom4te: /usr/bin/m4 failed with exitstatus: 63

aclocal: autom4te failed with exit status:63

autoreconf: aclocal failed with exitstatus: 63

 

原因是autoconf版本过低 http://www.aiuxian.com/article/p-879159.html

 

 

3.     升级之后再次编译安装成功

# make & make test & make install

 

# /usr/local/twemproxy/sbin/nutcracker -t

nutcracker: configuration file'conf/nutcracker.yml' syntax is ok

 

cp conf/nutcracker.yml/usr/local/twemproxy/

 

4.     启动命令

调试启动

/usr/local/twemproxy/sbin/nutcracker -c /usr/local/twemproxy/nutcracker.yml

 

以守护进程启动

/usr/local/twemproxy/sbin/nutcracker -d -c/usr/local/twemproxy/nutcracker.yml

 

5.     编辑/usr/local/twemproxy/nutcracker.yml


5.  安装keepalive

1.     yum -y installkeepalived ipvsadm

2.     配置/etc/keepalived/keepalived.conf文件

! Configuration File for keepalived

global_defs {

  notification_email {

   root@yeah.net

   }

  notification_email_from Alexandre.Cassen@firewall.loc

  smtp_server smtp.yeah.net

  smtp_connect_timeout 30

  router_id redis_twemproxy

}

vrrp_instance VIP_1 {

   interface eth3

   state MASTER #文档上说如果都改为BACKUP可以避免抢ip的问题

   virtual_router_id 55

   priority 100 #优先级设置为不同

   virtual_ipaddress {

     192.168.118.100/24 dev eth3 label eth3:1

    }

}

virtual_server 192.168.118.100 6379 {

   delay_loop 3

   lb_algo wrr

   lb_kind DR

   protocol TCP

   sorry_server 127.0.0.1 22121

   real_server 192.168.118.148 22121 {

     TCP_CHECK {

       connect_timeout 3

       nb_get_retry 3

       delay_before_retry 3

     }

    }

   real_server 192.168.118.149 22121 {

     TCP_CHECK {

       connect_timeout 3

       nb_get_retry 3

       delay_before_retry 3

     }

    }

}

 

3.     启动keepalived

/etc/init.d/keepalivedstart

 

4.      验证keepalived 


6.  配置主从集群

1.     所有redis启动后配置slave

#在一台slave服务器上执行,以那台服务器为master

slaveof 192.168.146 6379

#将一台slave服务器还原为master

SLAVEOF NO ONE

 

2.     配置

#工作目录

dir ./tmp

#配置主从服务集群的名字,并且配置master地址,1为slave数据copy的数量,越大master压力越大,但是同步的效果越差

sentinel monitor mymaster 192.168.118.1466379 1 

#master超时时间,则进行master选举

sentinel down-after-milliseconds mymaster5000 

sentinel parallel-syncs mymaster 1 

#选举时间

sentinel failover-timeout mymaster15000 

 

3.     参考文件

http://blog.csdn.net/kelong_xhu/article/details/41846355

 

4.     启动命令

nohup redis-sentinel ../sentinel.conf >outputlog.txt 2>&1 &

5.     查看信息

Redis实例上查看

– Info Replication

redis-cli -h 192.168.33.111 -p 26379

– info sentinel

– sentinel slaves mymaster(组名)

 


 

6.     参考文档

http://www.aiuxian.com/article/p-879159.html

http://www.aiuxian.com/article/p-879158.html

http://www.cnblogs.com/haoxinyue/p/redis.html

http://www.iyunv.com/thread-39985-1-1.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值