- vmware workstation 16 pro: 16.2.1 build-18811642
- ubuntu: 20.04.3-live
- redis:6.2.6
- 依赖gcc编译器:9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
- 依赖tcl: 8.5
- 192.168.242.129 redis-master master:6379/Sentinel : 26379
- 192.168.242.130 slave:6379/Sentinel : 26379
- 192.168.242.131 slave:6379/Sentinel : 26379
部署过程中遇到的问题 redis安装问题扩展信息:
redis集群方式:
1、主从复制:
优点:读写分离;
缺点:不具备自动容错和恢复能力、主节点宕机数据不一致、在线扩容困难
2、哨兵模式:主从复制基础上增加哨兵
主从自动切换,可用性高
3、Cluster集群模式:分布式存储,每台机器保存的内容不一致
支持动态扩展,故障转移
缺点:1、集群模式只支持一个节点,单机默认16个
2、数据异步复制,不能保证强一致性
3、slave充当备份,不缓解读的压力
4、key事务支持有限,只支持多key在同一节点的事务 *** 作,多key分布不同节点时无法使用事务功能
5、集群节点最少配置6个节点,3主3从 主节点读写,从节点只做备份和故障转移
- 编译报错:
解决方式-安装依赖:sudo apt-get install pkg-config
zhaowd@zhaowd:~/redis/redis-stable$ make cd src && make all make[1]: Entering directory '/home/zhaowd/redis/redis-stable/src' /bin/sh: 1: pkg-config: not found CC Makefile.dep /bin/sh: 1: pkg-config: not found CC adlist.o In file included from adlist.c:34: zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory 50 | #include| ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. make[1]: *** [Makefile:374: adlist.o] Error 1 make[1]: Leaving directory '/home/zhaowd/redis/redis-stable/src' make: *** [Makefile:6: all] Error 2
- 编译报错
解决方式-清理后重新安装:make distclean && make
zhaowd@zhaowd:~/redis/redis-stable$ make cd src && make all make[1]: Entering directory '/home/zhaowd/redis/redis-stable/src' CC adlist.o In file included from adlist.c:34: zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory 50 | #include集群部署问题| ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. make[1]: *** [Makefile:374: adlist.o] Error 1 make[1]: Leaving directory '/home/zhaowd/redis/redis-stable/src' make: *** [Makefile:6: all] Error 2
- 模拟master宕机后,不自动选举master
我的问题是从节点未配置主节点验证密码(主节点设置了密码),需要在从节点sentinel.conf 哨兵配置文件中增加主节点的名字(redis-master 默认是myredis)及密码(zhaowd),增加内容如下:
sentinel auth-pass redis-master zhaowdredis部署 部署前提
1、关闭防火墙
2、每台机器安装好redis
- redis.conf文件增加如下内容( 所有从节点增加)
slaveof 192.168.242.129 6379 masterauth zhaowd #如果开启了密码,需要开启master的密码
- sentinel.conf配置( 所有节点增加)
# 修改内容 # redis启用守护进行方式启动 daemonize yes # 启动端口 port 26379 # 保护模式,关闭后外部可以直接访问,开启需要bind ip或设置密码 protected-mode no # 指定存储目录 dir "/home/zhaowd/redis/redis-stable/sentinel-tmp" # 主节点 sentinel monitor redis-master 192.168.242.129 6379 2 # 多长时间监听不到后哨兵认为主节点不可用 sentinel down-after-milliseconds redis-master 30000 # 失效转移 sentinel failover-timeout redis-master 180000 # 主备切换后,最多可以有多少从节点可以同时对新master同步数据 sentinel parallel-syncs redis-master 1 # 配置认证密码 sentinel auth-pass redis-master zhaowd
- 所有节点启动 src目录下执行
./redis-server ../redis.conf ./redis-sentinel ../sentinel.conf
- 查看集群状态:主节点下面两个从节点
redis> info replication
- 模拟master 宕机后 130 主机备选举为master
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)