redis哨兵+主从

什么是哨兵
Redis-Sentinel是用于管理Redis集群,该系统执行以下三个任务:
1监控(Monitoring):
Sentinel会不断地检查你的主服务器和从服务器是否运作正常;
2提醒(Notification):
当被监控的某个Redis服务器出现问题时,Sentinel可以通过API向管理员或者其他应
用程序发送通知;
3自动故障迁移(Automaticfailover):
当一个主服务器不能正常工作时,Sentinel会开始一次自动故障迁移操作,它会将其中一
个从服务器升级为新的主服务器,当客户端试图连接失效的主服务器时,集群也会向客户
端返回新主服务器的地址
————————————————
1下载redis5.0
wgethttp://download.redis.io/releases/redis-5.0.2.tar.gz
cd/usr/local/
mkdirredis
tar-zxvfredis-5.0.2.tar.gz
2安装redis5.0
cdredis-5.0.2/
yum–yinstallgcc
make&&makeinstall
报错处理:
zmalloc.h:50:31:致命错误:jemalloc/jemalloc.h:没有那个文件或目录
makeMALLOC=libc
makeinstall
3搭建redis主从复制集群
cd/usr/local/
sentinel用来放哨兵的集群的配置,msredis用来放redis主从服务器的配置
[root@localhostlocal]#mkdirsentinelmsredis
[root@localhostlocal]#mkdir-pmsredis/{7000,7001,7002}
redis主服务器配置
[root@localhost7000]#pwd
/usr/local/msredis/7000
[root@localhost7000]#catredis_7000.conf
#master
port7000
daemonizeyes
appendonlyyes#开启持久化
masterauth"123456"
bind0.0.0.0
requirepass"123456"
protected-modeno
redis从服务器配置
[root@localhostmsredis]#cat7001/redis_7001.conf
port7001
slaveof127.0.0.17000
daemonizeyes
appendonlyyes
masterauth"123456"
bind0.0.0.0
requirepass"123456"
#(将权重降为90)
slave-priority90
protected-modeno
4搭建哨兵集群
[root@localhostsentinel]#pwd
/usr/local/sentinel
[root@localhostsentinel]#mkdirs1s2s3
[root@localhosts1]#catsentinel_6000.conf
#sentinelmonitor<master-name><ip><redis-port><quorum>
sentinelmonitormymaster127.0.0.170002
#这个配置项指定了需要多少失效时间,一个master才会被这个sentinel主观地认
为是不可用的。单位是毫秒,默认为30秒
sentineldown-after-millisecondsmymaster6000
#这个配置项指定了在发生failover主备切换时最多可以有多少个slave同时对新的
master进行同步,这个数字越小,完成failover所需的时间就越长,但是如果这个数
字越大,就意味着越多的slave因为replication而不可用。可以通过将这个值设为1
来保证每次只有一个slave处于不能处理命令请求的状态。
sentinelparallel-syncsmymaster1
daemonizeyes
#端口
port6000
dir"/usr/local/sentinel/s1"
其他sentinel_6001.conf和sentinel_6002.conf只需要修改port6001port6002即
可
5启动redis和sentinel
redis-server/usr/local/msredis/7000/redis_7000.conf
redis-server/usr/local/msredis/7001/redis_7001.conf
redis-server/usr/local/msredis/7002/redis_7002.conf
启动sentinel
redis-sentinel/usr/local/sentinel/s1/sentinel_6000.conf
redis-sentinel/usr/local/sentinel/s2/sentinel_6001.conf
redis-sentinel/usr/local/sentinel/s3/sentinel_6002.conf
登录:
redis-cli-p7000-a123456
127.0.0.1:7000>setwgxxoo
OK
127.0.0.1:7000>getwg
"xxoo"
127.0.0.1:7000>
6验证主从复制
[root@localhostredis-5.0.2]#redis-cli-p7001-a123456
Warning:Usingapasswordwith'-a'or'-u'optiononthecommandlineinterface
maynotbesafe.
127.0.0.1:7001>getwg
"xxoo"
127.0.0.1:7001>
7故障转移模拟

  

原文地址:https://www.cnblogs.com/luyuheng/p/11690539.html