当前位置: 首页 > news >正文

docker compose 下 Redis 主备配置

1、准备两台虚拟机或者物理机

       node1 IP:192.168.123.78

       node2 IP:192.168.123.82

2、安装docker和docker compose

3、安装node1,配置docker-compose.yml

version: '3'services:redis-rs1:container_name: 'redis_node1'image: 'redis:5.0.3'restart: alwaysvolumes:- ./redis/data:/data- ./redis/conf/redis.conf:/etc/redis/redis.confports:- 6379:6379sysctls:- net.core.somaxconn=1024command: redis-server /etc/redis/redis.conf --port 6379 --requirepass 123456 --appendonly yessentinel:container_name: 'sentinel'image: 'redis:5.0.3'restart: alwaysvolumes:- ./sentinel/conf/sentinel.conf:/etc/redis/sentinel.confports:- 26379:26379command: redis-sentinel /etc/redis/sentinel.conf

 获取配置文件 

    wget https://raw.githubusercontent.com/redis/redis/5.0/redis.conf

 修改node1下的redis.conf

    注释掉 bind
    添加或修改 masterauth 123456

4、安装node2,配置docker-compose.yml

version: '3'services:redis-rs2:container_name: 'redis_node2'image: 'redis:5.0.3'restart: alwaysvolumes:- ./redis/data:/data- ./redis/conf/redis.conf:/etc/redis/redis.confports:- 6379:6379sysctls:- net.core.somaxconn=1024command: redis-server /etc/redis/redis.conf --port 6379 --requirepass 123456 --appendonly yes --slaveof 192.168.3.53 6379 --masterauth 123456sentinel:container_name: 'sentinel'image: 'redis:5.0.3'restart: alwaysvolumes:- ./sentinel/conf/sentinel.conf:/etc/redis/sentinel.confports:- 26379:26379command: redis-sentinel /etc/redis/sentinel.conf

 获取配置文件 

    wget https://raw.githubusercontent.com/redis/redis/5.0/redis.conf

 修改node1下的redis.conf

    注释掉 bind
    添加或修改 masterauth 123456

5、配置node1下的sentinel.conf

port 26379
#daemonize yes
#pidfile /var/run/redis-sentinel.pid
logfile "sentinel.log"
sentinel myid 02ba5344dfb96dc699bcefc2e1d105190c0e85e3
sentinel deny-scripts-reconfig yes
sentinel monitor master001 192.168.123.82 6379 1
sentinel down-after-milliseconds master001 10000
sentinel auth-pass master001 123456sentinel config-epoch master001 13
sentinel leader-epoch master001 13sentinel known-replica master001 192.168.123.78 6379
# Generated by CONFIG REWRITE
dir "/data"
sentinel known-sentinel master001 192.168.123.78 26379 02ba5344dfb96dc699bcefc2e1d105190c0e85e3
sentinel known-sentinel master001 192.168.123.82 26379 f5e14a1e2d376544dcc2ce88a37a710d5c8a65a4
sentinel current-epoch 13
sentinel announce-ip "192.168.123.78"
sentinel announce-port 26379
masterauth "123456"

6、配置node2下的sentinel.conf 

port 26379
#daemonize yes
#pidfile /var/run/redis-sentinel.pid
logfile "sentinel.log"
sentinel myid f5e14a1e2d376544dcc2ce88a37a710d5c8a65a4
sentinel deny-scripts-reconfig yes
sentinel monitor master001 192.168.123.82 6379 1
sentinel down-after-milliseconds master001 10000
sentinel auth-pass master001 123456sentinel config-epoch master001 13
sentinel leader-epoch master001 13sentinel known-replica master001 192.168.123.78 6379
# Generated by CONFIG REWRITE
dir "/data"
sentinel known-sentinel master001 192.168.123.78 26379 02ba5344dfb96dc699bcefc2e1d105190c0e85e3
sentinel current-epoch 13
sentinel announce-ip "192.168.123.82"
sentinel announce-port 26379

7、关闭防火墙

firewall-cmd --permanent --add-port=6379/tcp
firewall-cmd --permanent --add-port=26379/tcp
firewall-cmd --reload

8、测试验证

进入到node1或者node2的redis容器中

docker exec -it 5942a4c958ce /bin/bash

9、查看redis的模式

root@5942a4c958ce:/data# redis-cli -h 127.0.0.1 -p 6379 -a "123456"
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.168.123.82
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:36973
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:08a5a246af256bcf10d1d3618805527fb1fe7544
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:36973
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:31055
repl_backlog_histlen:5919

http://www.lryc.cn/news/91851.html

相关文章:

  • Tomcat ServletConfig和ServletContext接口概述
  • linux内核open文件流程
  • 遗传算法讲解
  • PostgreSQL修炼之道之高可用性方案设计(十六)
  • Bybit面经
  • GORM---创建
  • 高级查询 — 分组汇总
  • 【多线程】阻塞队列
  • python2升级python3
  • Apache Hudi初探(八)(与spark的结合)--非bulk_insert模式
  • Java之旅(九)
  • 6年测试经验之谈,为什么要做自动化测试?
  • 二分法的边界条件 2517. 礼盒的最大甜蜜度
  • java设计模式(十六)命令模式
  • [运维] iptables限制指定ip访问指定端口和只允许指定ip访问指定端口
  • JS学习笔记(3. 流程控制)
  • 遥感云大数据在灾害、水体与湿地领域典型案例及GPT模型教程
  • 什么是文件描述符以及重定向的本质和软硬链接(Linux)
  • LVM逻辑卷元数据丢失恢复案例 —— 筑梦之路
  • Java技术规范概览
  • 【OpenMMLab AI实战营第二期】二十分钟入门OpenMMLab笔记
  • docker-compose单机容器集群编排
  • CentOS7 安装Gitlab
  • Mysql InnoDB的Buffer Pool
  • SMTP简单邮件传输协议(C/C++ 发送电子邮件)
  • uploads靶场通关(1-11关)
  • 6.1黄金探底回升是否到顶,今日多空如何布局
  • 自定义ViewGroup实现流式布局
  • Git版本控制
  • 若依之权限处理