单机版 Redis存在读写瓶颈的问题↓
所以用下面的主从架构来解决问题↓
上面的主从架构读写分离,有一个问题,如果主服务器挂了就无法写了↓
而哨兵可以帮助我们解决主从架构中的单点故障问题↓
哨兵扩展:
详解,Redis 哨兵(Sentinel)工作原理,实现及哨兵运维【附源码】_已注销_51CTO博客
Redis 哨兵机制以及底层原理深入解析,这次终于搞清楚了 - 知乎
REDIS sentinel-old -- Redis中国用户组(CRUG)
创建docker_redis_master_slave文件夹,里面编辑指定yml文件内容,修改了以下docker-compose.yml,增加哨兵配置文件的目录挂载↓
version: "3.1" services: redis1: image: daocloud.io/library/redis:5.0.7 restart: always container_name: redis1 environment: - TZ=Asia/Shanghai ports: - 7001:6379 volumes: - ./conf/redis1.conf:/usr/local/redis/redis.conf - ./conf/sentinel1.conf:/data/sentinel.conf command: ["redis-server","/usr/local/redis/redis.conf"] redis2: image: daocloud.io/library/redis:5.0.7 restart: always container_name: redis2 environment: - TZ=Asia/Shanghai ports: - 7002:6379 volumes: - ./conf/redis2.conf:/usr/local/redis/redis.conf - ./conf/sentinel2.conf:/data/sentinel.conf links: - redis1:master command: ["redis-server","/usr/local/redis/redis.conf"] redis3: image: daocloud.io/library/redis:5.0.7 restart: always container_name: redis3 environment: - TZ=Asia/Shanghai ports: - 7003:6379 volumes: - ./conf/redis3.conf:/usr/local/redis/redis.conf - ./conf/sentinel3.conf:/data/sentinel.conf links: - redis1:master command: ["redis-server","/usr/local/redis/redis.conf"]
哨兵配置文件汇总↓
主节点哨兵配置文件↓
daemonize yes sentinel monitor master localhost 6379 2 sentinel down-after-milliseconds master 10000
从节点哨兵配置文件↓
daemonize yes sentinel monitor master master 6379 2 sentinel down-after-milliseconds master 10000
在Redis容器内部所在的/data目录启动哨兵sentinel即可,最后stop停止主节点,然后测试查看,是否有从变主↓
[root@localhost docker_redis_master_slave]# docker-compose down [root@localhost docker_redis_master_slave]# docker-compose up -d #分别进入三个容器内部所在的/data目录启动,启动三个哨兵配置↓ [root@localhost docker_redis_master_slave]# docker ps [root@localhost docker_redis_master_slave]# docker exec -it 容器id bash root@6088e8b630a2:/data# redis-sentinel sentinel.conf #最后stop停止主节点,然后测试查看,是否有从变主↓ [root@localhost docker_redis_master_slave]# docker ps [root@localhost docker_redis_master_slave]# docker stop 开始的主节点容器id
另外哨兵配置忘了,这个参考redis服务器软件里面下面的sentinel.conf哨兵配置文件↓
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)