第一章:Redis+twemproxy+keepalive+ sentinel实现完整的redis集群方案实验
2015-11-13 14:21
836 查看
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 ipvsadm2. 配置/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. 参考文件
/article/10188400.html
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
相关文章推荐
- windows下安装redis
- 辛星浅析用redis存储session时的密码问题
- redis
- redis学习资源汇总
- Redis .net 客户端 分布式锁
- Java连接redis的使用示例
- Redis主从同步
- 初识redis之常用String与Hash命令
- 高性能文件缓存key-value存储—Redis
- redis集群+主从部署
- 高性能网站架构设计之缓存---redis集群搭建
- 夺命雷公狗---Redis---7-案例操作2(用户列表页,实现分页显示已经关注功能)完
- redis常用数据类型
- Redis未授权访问漏洞分析
- redis的一次持久化入侵
- Redis入门
- Mybatis缓存和Redis缓存服务器的案例分析
- Kafka+Spark Streaming+Redis实时计算整合实践
- 夺命雷公狗---Redis---6-案例操作1(注册-登录)
- Redis笔记