利用 docker 搭建 redis主从复制环境,哨兵模式

我做了一个导航站(域名是挂路灯的全拼gualudeng.com),里面精选了各种影视,动漫,黑科技,实用工具,搞笑有趣的站点,动动大家可爱的小手,点进来看看吧,良心站点。

1.1.创建docker-compose.yml 文件。注意在yml文件中,image冒号后要有空格。(文件格式问题)。为了安全 不必为 redis 进行端口映射。

version: "3"
services:
  redis1:
    image: redis
    volumes: 
      - /vagrant_data/redis_cluster:/usr/local/etc/redis
    command: bash -c "redis-server /usr/local/etc/redis/redis1.conf"
  redis2:
    image: redis
    volumes: 
      - /vagrant_data/redis_cluster:/usr/local/etc/redis
    command: bash -c "redis-server /usr/local/etc/redis/redis2.conf"
  redis3:
    image: redis
    volumes: 
      - /vagrant_data/redis_cluster:/usr/local/etc/redis
    command: bash -c "redis-server /usr/local/etc/redis/redis3.conf"
  redis4:
    image: redis
    volumes: 
      - /vagrant_data/redis_cluster:/usr/local/etc/redis
    command: bash -c "redis-server /usr/local/etc/redis/redis4.conf"

1.2.修改各个redis配置文件

对于master节点
修改 bind 0.0.0.0 保证各个节点之间能互相通信
修改 protected_mode 为 no
设置密码 requirepass 123456
对于从节点还要添加
replicaof master 6379
masterauth 123456  组节点密码,自己不需要配置密码
设置密码 requirepass 123456 (从节点也可以设置密码,但是主节点需要设置masterauth 123456)

1.3.常用操作命令

进入redis-cli 后 查看节点信息 info replication
手动配置从节点 slaveof master 6379  
docker logs container 查看docker 日志信息

2.1 redis主从复制的哨兵模式

version: "3"
services:
  redis1:
    image: redis
    volumes: 
      - /vagrant_data/redis_cluster:/usr/local/etc/redis
    command: 
      - sh 
      - -c
      - |
        redis-server /usr/local/etc/redis/redis1.conf &
        redis-sentinel /usr/local/etc/redis/sential.conf
  redis2:
    image: redis
    volumes: 
      - /vagrant_data/redis_cluster:/usr/local/etc/redis
    command: 
    command: 
      - sh 
      - -c
      - |
        redis-server /usr/local/etc/redis/redis2.conf &
        redis-sentinel /usr/local/etc/redis/sential.conf
  redis3:
    image: redis
    volumes: 
      - /vagrant_data/redis_cluster:/usr/local/etc/redis
    command: 
      - sh 
      - -c
      - |
        redis-server /usr/local/etc/redis/redis3.conf &
        redis-sentinel /usr/local/etc/redis/sential.conf
  redis4:
    image: redis
    volumes: 
      - /vagrant_data/redis_cluster:/usr/local/etc/redis
    command: 
      - sh 
      - -c
      - |
        redis-server /usr/local/etc/redis/redis4.conf &
        redis-sentinel /usr/local/etc/redis/sential.conf

2.2 sential.conf 配置文件

port 26379
sentinel monitor mymaster redis1 6379 1
#sentinel auth-pass mymaster 123456   (配置密码可能会出现宕机后从机连不上新主机)
protected-mode no

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值