首页 > 数据库 >Docker 部署 redis 网络集群

Docker 部署 redis 网络集群

时间:2023-09-23 12:37:33浏览次数:47  
标签:-- redis 6379 172.38 集群 conf Docker slots

Docker 部署 redis 网络集群

## 1. 创建网卡
docker network create redis --subnet 172.38.0.0/16
 
# 2. 通过脚本创建六个redis配置
for port in $(seq 1 6); \
do \
mkdir -p /mydata/redis/node-${port}/conf
touch /mydata/redis/node-${port}/conf/redis.conf
cat << EOF >/mydata/redis/node-${port}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.38.0.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
# 3.0 创建结点1
docker run -p 6371:6379 -p 16371:16379 --name redis-1 \
-v /mydata/redis/node-1/data:/data \
-v /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.11 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
 
# 3.1 创建结点2
docker run -p 6372:6379 -p 16372:16379 --name redis-2 \
-v /mydata/redis/node-2/data:/data \
-v /mydata/redis/node-2/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.12 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
# 3.2 创建结点3
docker run -p 6373:6379 -p 16373:16379 --name redis-3 \
-v /mydata/redis/node-3/data:/data \
-v /mydata/redis/node-3/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.13 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
# 3.3 创建结点4
docker run -p 6374:6379 -p 16374:16379 --name redis-4 \
-v /mydata/redis/node-4/data:/data \
-v /mydata/redis/node-4/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.14 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
# 3.4 创建结点5
docker run -p 6375:6379 -p 16375:16379 --name redis-5 \
-v /mydata/redis/node-5/data:/data \
-v /mydata/redis/node-5/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.15 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
# 3.5创建结点6
docker run -p 6376:6379 -p 16376:16379 --name redis-6 \
-v /mydata/redis/node-6/data:/data \
-v /mydata/redis/node-6/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.16 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
 
# 4. 创建集群
[root@ ~]# docker exec -it redis-1 /bin/sh
/data # ls
appendonly.aof  nodes.conf
/data # redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 172.38.0.15:6379 to 172.38.0.11:6379
Adding replica 172.38.0.16:6379 to 172.38.0.12:6379
Adding replica 172.38.0.14:6379 to 172.38.0.13:6379
M: 541b7d237b641ac2ffc94d17c6ab96b18b26a638 172.38.0.11:6379
   slots:[0-5460] (5461 slots) master
M: a89c1f1245b264e4a402a3cf99766bcb6138dbca 172.38.0.12:6379
   slots:[5461-10922] (5462 slots) master
M: 259e804d6df74e67a72e4206d7db691a300c775e 172.38.0.13:6379
   slots:[10923-16383] (5461 slots) master
S: 9b19170eea3ea1b92c58ad18c0b5522633a9e271 172.38.0.14:6379
   replicates 259e804d6df74e67a72e4206d7db691a300c775e
S: 061a9d38f22910aaf0ba1dbd21bf1d8f57bcb7d5 172.38.0.15:6379
   replicates 541b7d237b641ac2ffc94d17c6ab96b18b26a638
S: 7a16b9bbb0615ec95fc978fa62fc054df60536f0 172.38.0.16:6379
   replicates a89c1f1245b264e4a402a3cf99766bcb6138dbca
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
...
>>> Performing Cluster Check (using node 172.38.0.11:6379)
M: 541b7d237b641ac2ffc94d17c6ab96b18b26a638 172.38.0.11:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: a89c1f1245b264e4a402a3cf99766bcb6138dbca 172.38.0.12:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 7a16b9bbb0615ec95fc978fa62fc054df60536f0 172.38.0.16:6379
   slots: (0 slots) slave
   replicates a89c1f1245b264e4a402a3cf99766bcb6138dbca
S: 061a9d38f22910aaf0ba1dbd21bf1d8f57bcb7d5 172.38.0.15:6379
   slots: (0 slots) slave
   replicates 541b7d237b641ac2ffc94d17c6ab96b18b26a638
M: 259e804d6df74e67a72e4206d7db691a300c775e 172.38.0.13:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 9b19170eea3ea1b92c58ad18c0b5522633a9e271 172.38.0.14:6379
   slots: (0 slots) slave
   replicates 259e804d6df74e67a72e4206d7db691a300c775e
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
 
 

标签:--,redis,6379,172.38,集群,conf,Docker,slots
From: https://www.cnblogs.com/liuzonglin/p/17724178.html

相关文章

  • Dockerfile
    Dockerfile基础知识:每个保留关键字(指令)都是必须大写字母(约定俗成)执行从上到下顺序执行"#"表示注释每个指令都会创建提交一个新的镜像层,并提交!Dockerfile中引用的所有文件一定要和Dockerfile文件在同一级父目录下,可以为Dockerfile父目录的子目录Dockerfile中相对路径......
  • Docker 容器数据卷
    Docker容器数据卷1.方式一:直接使用命令来挂载-v#dockerrun-it-v主机目录:容器目录[root@home]#dockerrun-it-v/home/ceshi:/homecentos/bin/bash总结:容器运行时,挂载目录数据一直同步#获取镜像[root@home]#dockerpullmysql:5.7#运行容器,需要做数据......
  • Ubuntu 22.04 安装 Docker
    安装基础工具sudoapt-getinstallca-certificatescurlgnupglsb-release安装官方的GPGkeysudomkdir-p/etc/apt/keyringscurl-fsSLhttps://download.docker.com/linux/ubuntu/gpg|sudogpg--dearmor-o/etc/apt/keyrings/docker.gpg将Docker的库添加到apt资源......
  • Ubuntu(Ubuntu 22.04 操作系统) 安装 Docker
    Ubuntu(Ubuntu22.04操作系统)安装Docker首先安装一些工具:sudoapt-getinstallca-certificatescurlgnupglsb-release不过在Ubuntu22.04已经默认安装好了。接着安装官方的GPGkey:sudomkdir-p/etc/apt/keyringscurl-fsSLhttps://download.docker.com/linux/ubun......
  • redis消息队列——发布订阅
    一、相关依赖<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><grou......
  • docker跨平台构建镜像
    我们在开发环境构建的镜像在生产环境大多不可用,我们在开发中一般使用Windows或者MAC系统,部署多半是linux环境。那么这篇文章能帮到你。首先首先你需要有一个Dockerfile文件。举例:这里以一个python项目举例FROMpython:3.10-slimWORKDIR/appCOPYrequirements.tx......
  • Docker概念及操作
    1.镜像相关命令:查看本地镜像:dockerimages搜索镜像仓库:dockersearch<名称关键字>下载镜像:dockerpull<镜像名:tag版本>上传镜像:dockerpush <镜像名:tag版本>删除镜像:dockerrmi <镜像名:tag版本>打包本地镜像文件:dockersave-o<输出文件路径>导入本地......
  • Docker Swarm 与高可用性
    什么是DockerSwarm?DockerSwarm是Docker官方提供的容器编排工具,它可以将多个Docker节点组成一个集群,实现容器的自动化部署和管理。DockerSwarm采用了Raft算法来保证集群的一致性,同时支持多种调度策略,如随机调度、最少使用调度、节点标签调度等。DockerSwarm的高可用......
  • Docker缓存占有太大的磁盘空间
    Docker在不重建容器的情况下,日志文件默认会一直追加,时间一长会逐渐占满服务器的硬盘的空间,内存消耗也会一直增加。查出占用磁盘较大的文件Docker的日志文件存在/var/lib/docker/containers目录中,通过下面的命令可以将日志文件夹根据升序的方式罗列出来。sudodu-d1-h/var......
  • docker-compose简介
    1.docker-compose简介  实现docker容器集群的快速编排。管理分成三层:工程(project)、服务(service)、容器(container)  没有解决负载均衡的问题,因此需要借助其它工具实现服务发现及负载均衡,比如Consul  工程配置文件默认文件docker-compose.yml,也可自定义(通过环境变量COMP......