首页 > 其他分享 >Docker部署Reids哨兵模式集群(sentinel)

Docker部署Reids哨兵模式集群(sentinel)

时间:2024-11-14 16:40:54浏览次数:1  
标签:mymaster container IP Reids redis conf sentinel Docker

一、下载redis镜像

二、redis主库配置 redis.conf

绑定的IP地址和端口

bind 0.0.0.0

必须使用6379,因为容器内默认是6379端口

port 6379

设置密码

requirepass 123456

启用持久化

appendonly yes

三、主库sentinel配置sentinel.conf
protected-mode no

配置端口号,各个节点不能相同

port 26379
daemonize no
pidfile /var/run/redis-sentinel.pid
loglevel notice

日志存放地址

logfile "/var/tmp/sentinel.log"
dir /tmp

外部IP访问地址,解决Docker-Net容器IP跨服务器无法访问问题

(sentinel的暴露端口)

sentinel announce-ip 主机IP

(sentinel的暴露端口)

sentinel announce-port 6380

设置Redis主节点信息

xxx.IP redis主库IP 主库端口(6370)

sentinel monitor mymaster xxx.IP 6370 2

(主库密码)

sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
acllog-max-len 128
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
SENTINEL resolve-hostnames no
SENTINEL announce-hostnames no
SENTINEL master-reboot-down-after-period mymaster 0

四、docker-compose.yml配置

services:
redis-master:
image: redis:7.2
container_name: redis-master
restart: always
networks:
- redis-net
ports:
- 6370:6379
environment:
TZ: "Asia/Shanghai"
REDIS_PASSWORD: 123456
volumes:
- /container/mnt/redis/master/conf/redis.conf:/usr/local/etc/redis/redis.conf
- /container/mnt/redis/master/data:/data
command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
logging:
driver: "json-file"
options:
max-size: "1024m"
max-file: "5"

redis-sentinel:
image: redis:7.2
container_name: redis-sentinel
command: redis-sentinel /etc/sentinel.conf
volumes:
- /container/mnt/redis/sentinel/conf/sentinel.conf:/etc/sentinel.conf
ports:
- 6380:26379
networks:
- redis-net
logging:
driver: "json-file"
options:
max-size: "1024m"
max-file: "5"

=========== 从库可以废弃

redis-slave:
image: redis:7.2
container_name: redis-slave
restart: always
networks:
- redis-net
ports:
- 6371:6379
environment:
TZ: "Asia/Shanghai"
REDIS_PASSWORD: 123456
volumes:
- /container/mnt/redis/slave/conf/redis.conf:/usr/local/etc/redis/redis.conf
- /container/mnt/redis/slave/data:/data
command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
logging:
driver: "json-file"
options:
max-size: "1024m"
max-file: "5"

networks:
redis-net:
driver: bridge

五、从节点slave1的redis.conf配置

绑定的IP地址和端口

bind 0.0.0.0

必须使用6379,因为容器内默认是6379端口

port 6379

设置密码

requirepass 123456
masterauth 123456

启用持久化

appendonly yes

xxx.IP是redis主库的的IP地址 ,6370是主库的端口

slaveof xxx.IP 6370

六、从库的sentinel配置sentinel.conf
protected-mode no

配置端口号,各个节点不能相同

port 26379
daemonize no
pidfile /var/run/redis-sentinel.pid
loglevel notice

日志存放地址

logfile "/var/tmp/sentinel.log"
dir /tmp

外部IP访问地址,解决Docker-Net容器IP跨服务器无法访问问题

从库 sentinel对外暴露的IP

sentinel announce-ip xxx.IP

从库 sentinel对外暴露的端口

sentinel announce-port 24080

设置Redis主节点信息, xxx.IP是redis主库的IP地址

sentinel monitor mymaster xxx.IP 6370 2

123456是主库的登录密码

sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
acllog-max-len 128
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
SENTINEL resolve-hostnames no
SENTINEL announce-hostnames no
SENTINEL master-reboot-down-after-period mymaster 0

七、从库的docker-compose.yml配置
services:
redis-slave-2:
image: redis:7.2
container_name: redis-slave-2
restart: always
networks:
- redis-net
ports:
- 24050:6379
environment:
TZ: "Asia/Shanghai"
REDIS_PASSWORD: 123455
volumes:
- /container/mnt/redis/slave/conf/redis.conf:/usr/local/etc/redis/redis.conf
- /container/mnt/redis/slave/data:/data
command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
logging:
driver: "json-file"
options:
max-size: "1024m"
max-file: "5"

redis-sentinel:
image: redis:7.2
container_name: redis-sentinel
command: redis-sentinel /etc/sentinel.conf
volumes:

/container/mnt/redis/sentinel/conf/sentinel.conf

  - /container/mnt/redis/sentinel/conf/sentinel.conf:/etc/sentinel.conf

ports:
  - 24080:26379
networks:
  - redis-net
logging:
  driver: "json-file"
  options:
    max-size: "1024m"
    max-file: "5"

networks:
redis-net:
driver: bridge

八、docker compose启动所有redis容器
docker compose up -d

标签:mymaster,container,IP,Reids,redis,conf,sentinel,Docker
From: https://www.cnblogs.com/velloLei/p/18546352

相关文章

  • Docker快速入门到项目实战部署
    1.*docker*1.1*什么是docker*docker是快速构建、运行、管理应用的工具,简单来就是来帮助部署项目以及部署项目需要的一些组件的工具。1.2*卸载旧版*首先如果系统中已经存在旧的docker,则先卸载:yumremovedockerdocker-clientdocker-client-latestdocker-commondock......
  • docker run指定gpu,后台拉镜像
     root@node37:/ollama#dockerrun-d--gpus'"device=2,3"'-v/ollama:/root/.ollama-p11434:11434--nameollamaollama/ollamac12c23004c3957a8cba38376dbb17904db9381932f9578b2dd5de87794f40a9droot@node37:/ollama#root@node37:/ollama#......
  • navicat连接远程服务器docker的mysql容器时连不上报错
    报错:1130-HostxxxisnotallowedtoconnecttothisMySQLserver1.原因是root账户没有远程访问权限,先进mysql容器dockerexec-it你的容器id/bin/bash2.连接数据库,输入你的密码mysql-uroot-p3.切换到mysql数据库usemysql;4.更新用户表:(其中%的意思是允许所有的......
  • linux下安装docker
    ****************docker****************docker是一个快速构建、运行、管理应用的工具。****************镜像和容器****************当我们利用docker安装应用时,docker会自动搜索并下载应用镜像(image)。镜像不仅包含应用本身,还包含应用运行所需要的环境、配置、系统函数库。do......
  • centos8 从安装docker到部署服务
    1.替换yum源为阿里镜像1.1备份cd/etc/yum.repos.dmkdirbaksmv./*.repo./baks1.2新建viCentos-Linux-BaseOS.repo填充内容[baseos]name=AlibabaCloudLinux$releasever-BaseOSbaseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/......
  • 云服务器搭建及Docker使用---清风
    声明!通过学习 泷羽sec的个人空间-泷羽sec个人主页-哔哩哔哩视频,做出的文章,如涉及侵权马上删除文章,笔记的只是方便各位师傅学习知识,以下网站只涉及学习内容,其他的都与本人无关,切莫逾越法律红线,否则后果自负.文章为个人学习笔记。想学习更多知识,请认准泷羽secdocker安装su......
  • CICD03 Jenkins对golang项目构建, 结合ansible, 构建通知, 自动化构建(定时,webhook),
    2.7.2基于Maven风格的任务构建基于WAR包运行Tomcat服务器JAVA项目maven配置繁琐,功能固定不灵活,不如自由风格好用,这里推荐用自由风格脚本实现更好目前最高依赖到tomcat9,更高版本的tomcat不支持2.7.2.2安装tomcat服务器和配置#在gitlab新建java项目(此项目使用JD......
  • [Docker#7] 容器 | OOM | 常用命令 | 交互模式 | 批量处理
    目录什么是容器生活案例为什么需要容器?容器的生命周期3种特殊情况3.1容器OOM3.2容器异常退出3.3容器暂停容器命令清单Docker容器常用命令dockercreatedockerrundockerpsdockerlogsdockerexecdockerstartdockerstopdockerrestartdockerkilld......
  • XXL JOB DockerCompose部署
    官网给的方式是Docker命令启动,但是用起来太麻烦了,所以用DockerCompose简化部署创建数据库,导入SQLSQL脚本位置为/xxl-job/doc/db/tables_xxl_job.sqlhttps://raw.githubusercontent.com/xuxueli/xxl-job/refs/heads/master/doc/db/tables_xxl_job.sql编写DockerComposev......
  • 用idea的docker插件生成镜像并推送到服务器
    准备这两个文件......