Redis部署集群主从、哨兵模式

1 首先安装redis
1.1、Redis-Sentinel高可用模式的介绍可参考Sentinel 提供了监控、通知、并为client提供配置的作用。
1.2、下载:wget http://download.redis.io/releases/redis-3.2.8.tar.gz
2 安装Redis
解压redis-3.2.8安装包,进入src文件夹
安装命令:make && make install
详细请参考:http://www.runoob.com/redis/redis-install.html
错误解决:
(1)现象——出现jemalloc/jemalloc.h: No such file or directory的报错。
原因——jemalloc是默认的分配器,如果 没有jemalloc而只有libc, 就会make出错。
解决方案——make MALLOC=libc
(2)现象——出现sh: ./mkreleasehdr.sh: Permission denied的报错。
原因——权限不够,需要增加对mkreleasehdr.sh的权限。
解决方案——chmod +x mkreleasehdr.sh
3 最重要进行配置conf
在同一台服务器部署时,通过配置不同的端口号,开启redis、sentinel不同的线程。
将redis.conf和sentinel.conf文件,copy至另一个文件夹下。如果部署2个节点,那么分别修改为redis_1.conf, redis_2.conf, sentinel_1.conf, sentinel_2.conf
3.1 首先redis_1.conf

bind 0.0.0.0
protected-mode yes
port 6379
daemonize yes
slaveof 服务器ip 6380
masterauth 124     
requirepass "124" 

注意:其他不要动
3.2 其次配置redis_2.conf

bind 0.0.0.0
protected-mode yes
port 6380
daemonize yes
masterauth "124"

注意:其他不要动
3.2 然后配置sentinel_1.conf

protected-mode no
port 16379
sentinel monitor mymaster 服务器ip 6380 1
sentinel auth-pass mymaster 124
daemonize yes

注意:其他不要动
3.2 然后配置sentinel_2.conf

protected-mode no
port 16380
sentinel monitor mymaster 服务器ip 6380 1
sentinel auth-pass mymaster 124

注意:其他不要动
4 启动redis和sentinel

启动redis: redis-server redis_1.conf
 redis-server redis_2.conf
启动sentinel: redis-sentinel sentinel_1.conf
redis-sentinel sentinel_2.conf
检测是否启动:redis-cli -p 16380 -a 124 info   
master0状态ok, 表明master正常运行

5 验证
启动:

[root@localhost redis]# ./redis-cli  (这里是本机连接,如果是连接网络机器 :./redis-cli  IP  端口号)

验证主从redishttps://www.cnblogs.com/think-in-java/p/5123884.html

猜你喜欢

转载自blog.csdn.net/qq_32447301/article/details/81068025