当前位置:网站首页>Docker 搭建 Redis Cluster集群
Docker 搭建 Redis Cluster集群
2022-07-25 20:08:00 【InfoQ】
共勉一、环境
- 阿里云服务器 CentOS 8
- docker版本为20.10.7
- redis 镜像 (拉取为默认最新镜像)


- 下载Redis镜像
- 编写Redis配置文件
- 启动Redis 容器
- 创建Redis Cluster 集群。
- 进行实际测试
二、前期准备
2.1、搜索、拉取redis镜像
docker search redis
docker pull redis


2.2、Docker 容器网络
- 创建虚拟网卡
- 创建虚拟网卡,主要是用于redis-cluster能于外界进行网络通信,一般常用桥接模式。
docker network create myredis
- 查看Docker 网卡信息
docker network ls

docker network inspect myredis

docker network rm myredis #删除网卡命令 多个中间 空格隔开
docker network --help #显示可带参数等
2.3、编写配置文件
shllefor port in $(seq 6379 6384);
do
mkdir -p /home/redis/node-${port}/conf
touch /home/redis/node-${port}/conf/redis.conf
cat << EOF > /home/redis/node-${port}/conf/redis.conf
port ${port}
requirepass 1234
bind 0.0.0.0
protected-mode no
daemonize no
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 服务器就填公网ip,或者内部对应容器的ip
cluster-announce-port ${port}
cluster-announce-bus-port 1${port}
EOF
done
port:节点端口;
requirepass:设置密码,访问时需要验证
protected-mode:保护模式,默认值 yes,即开启。开启保护模式以后,需配置bind ip或者设置访问密码;关闭保护模式,外部网络可以直接访问;
daemonize:是否以守护线程的方式启动(后台启动),默认 no;
appendonly:是否开启 AOF 持久化模式,默认 no;
cluster-enabled:是否开启集群模式,默认 no;
cluster-config-file:集群节点信息文件;
cluster-node-timeout:集群节点连接超时时间;
cluster-announce-ip:集群节点 IP
注意:如果你想要你的redis集群可以供外网访问,这里直接填 服务器的IP 地址即可
- 如若为了安全,只是在服务器内部进行访问,这里还需要做一些修改。
cluster-announce-port:集群节点映射端口;
cluster-announce-bus-port:集群节点总线端口。


treeyum install -y tree
三、启动容器
3.1、启动redis容器
for port in $(seq 6379 6384); \
do \
docker run -it -d -p ${port}:${port} -p 1${port}:1${port} \
--privileged=true -v /home/redis/node-${port}/conf/redis.conf:/usr/local/etc/redis/redis.conf \
--privileged=true -v /home/redis/node-${port}/data:/data \
--restart always --name redis-${port} --net myredis \
--sysctl net.core.somaxconn=1024 redis redis-server /usr/local/etc/redis/redis.conf
done
- -it:交互
- -d:后台运行,容器启动完成后打印容器
- --privileged:是否让docker 应用容器 获取宿主机root权限(特殊权限-)
- -p :端口映射
- -v:文件挂载
- --sysctl参数来设置系统参数,通过这些参数来调整系统性能
- --restart always:在容器退出时总是重启容器
- --name :给容器取名
- --net myredis :使用我们创建的虚拟网卡 (想详细了解,可以去看看Docker 网络方面知识)

docker ps -a
3.2、创建Redis Cluster集群
1、进入redis-6379 容器
docker exec -it redis-6379 /bin/bash

2、创建集群
redis-cli -a 之前设置的密码 --cluster create 配置文件中的IP地址:6379 IP地址:6380 IP地址:6381 IP地址:6382 IP地址:6383 IP地址:6384 --cluster-replicas 1


3、查看节点相关信息
redis-cli -c -a 1234
cluster info
cluster nodes
四、测试
4.1、本机测试


4.2、外网测试



4.3、出错可能会用到的命令
for port in $(seq 6379 6384);
do
docker stop redis-${port}
done
for port in $(seq 6379 6384);
do
docker rm redis-${port}
done
4.4、可能会出的错
注五、博主自言
边栏推荐
- How to get started quickly in software testing
- 网络爬虫原理解析「建议收藏」
- RF、GBDT、XGboost特征选择方法「建议收藏」
- Google pixel 6A off screen fingerprint scanner has major security vulnerabilities
- Log in to Baidu online disk with cookies (websites use cookies)
- Ml programming skills:
- Share 25 useful JS single line codes
- Can you tell me whether mindspore supports torchvision Model directly uses the pre trained network, such as vgg16
- Web crawler principle analysis "suggestions collection"
- Proxy implements MySQL read / write separation
猜你喜欢

Recommended system topic | Minet: cross domain CTR prediction

A high efficiency 0-delay 0-copy QT player scheme based on Hisilicon 3559

Binarysearch basic binary search

wallys//IPQ5018/IPQ6010/PD-60 802.3AT Input Output 10/100/1000M

10. < tag dynamic programming and subsequence, subarray> lt.53. maximum subarray and + lt.392. Judge subsequence DBC
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET

4everland storage node portal network design

PyTorch 模型 onnx 文件的导出和调用

Connecting to the database warning establishing SSL connection without server's identity verification is not recommended
Detailed evaluation of current popular redis visual management tools
随机推荐
Split very long line of words into separate lines of max length
Rainbow plug-in extension: monitor MySQL based on MySQL exporter
tga文件格式(波形声音文件格式)
qml 结合 QSqlTableModel 动态加载数据 MVC「建议收藏」
String of sword finger offer question bank summary (II) (C language version)
Proxy implements MySQL read / write separation
securecrt乱码解决方法[通俗易懂]
Formatdatetime explanation [easy to understand]
Stock software development
谷歌Pixel 6a屏下指纹扫描仪存在重大安全漏洞
Arrow 之 Parquet
What is the method to load the torch pre trained model for the mindspore model finetune?
JVM(二十三) -- JVM运行时参数
The use of new promise, async and await in the project, and the practical application of promise.all in the project
Socket error Event: 32 Error: 10053. Connection closing...Socket close
[cloud native | learn kubernetes from scratch] VIII. Namespace resource quotas and labels
Connecting to the database warning establishing SSL connection without server's identity verification is not recommended
10. < tag dynamic programming and subsequence, subarray> lt.53. maximum subarray and + lt.392. Judge subsequence DBC
How to ensure the quality of customized slip rings
【高等数学】【6】多元函数微分学