redis 主从+哨兵

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_45754572/article/details/102569830

什么是哨兵
Redis-Sentinel是用于管理Redis集群,该系统执行以下三个任务:
1监控(Monitoring):
Sentinel会不断地检查你的主服务器和从服务器是否运作正常;
2 提醒(Notification):
当被监控的某个Redis服务器出现问题时,Sentinel可以通过API向管理员或者其他应用程序发送通知;
3 自动故障迁移(Automatic failover):
当一个主服务器不能正常工作时,Sentinel 会开始一次自动故障迁移操作,它会将其中一个从服务器升级为新的主服务器,当客户端试图连接失效的主服务器时,集群也会向客户端返回新主服务器的地址
————————————————
1 下载redis5.0
wget http://download.redis.io/releases/redis-5.0.2.tar.gz
cd /usr/local/
mkdir redis
tar -zxvf?redis-5.0.2.tar.gz
2 安装redis5.0
cd redis-5.0.2/
yum –y install gcc
make && make install
报错处理:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
make MALLOC=libc
make install
3 搭建redis主从复制集群
cd /usr/local/
sentinel用来放哨兵的集群的配置,msredis用来放redis主从服务器的配置
[root@localhost local]# mkdir sentinel msredis
[root@localhost local]# mkdir -p msredis/{7000,7001,7002}
redis 主服务器配置
[root@localhost 7000]# pwd
/usr/local/msredis/7000
[root@localhost 7000]# cat redis_7000.conf
#master
port 7000
daemonize yes
appendonly yes #开启持久化
masterauth “123456”
bind 0.0.0.0
requirepass “123456”
protected-mode no
redis 从服务器配置
[root@localhost msredis]# cat 7001/redis_7001.conf
port 7001
slaveof 127.0.0.1 7000
daemonize yes
appendonly yes
masterauth “123456”
bind 0.0.0.0
requirepass “123456”
#(将权重降为90)
slave-priority 90
protected-mode no
4 搭建哨兵集群
[root@localhost sentinel]# pwd
/usr/local/sentinel
[root@localhost sentinel]# mkdir s1 s2 s3
[root@localhost s1]# cat sentinel_6000.conf
#sentinel monitor
sentinel monitor mymaster 127.0.0.1 7000 2
#这个配置项指定了需要多少失效时间,一个master才会被这个sentinel主观地认为是不可用的。?单位是毫秒,默认为30秒
sentinel down-after-milliseconds mymaster 6000
#这个配置项指定了在发生failover主备切换时最多可以有多少个slave同时对新的master进行 同步,这个数字越小,完成failover所需的时间就越长,但是如果这个数字越大,就意味着越 多的slave因为replication而不可用。可以通过将这个值设为 1 来保证每次只有一个slave 处于不能处理命令请求的状态。
sentinel parallel-syncs mymaster 1
daemonize yes
#端口
port 6000
dir “/usr/local/sentinel/s1”
其他sentinel_6001.conf和sentinel_6002.conf只需要修改port 6001?port 6002即可
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
re

猜你喜欢

转载自blog.csdn.net/weixin_45754572/article/details/102569830