当前位置:网站首页>docker部署redis集群
docker部署redis集群
2022-06-27 02:09:00 【运维@小兵】
一、创建redis_cluster网桥
docker network create redis_cluster --subnet=172.38.1.0/24 -o com.docker.network.bridge.name=redis_cluster
ifconfig redis_cluster
二、启动六个容器
两个容器为一组,一个master,一个slave,master挂掉,slave会成为master
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 #redis节点宕机被发现的时间 cluster-announce-ip 172.38.1.1${port} #集群节点的汇报ip,防止nat,此处为docker容器IP cluster-announce-port 6379 #集群节点的汇报port,防止nat cluster-announce-bus-port 16379 #集群节点的汇报bus-port,防止nat appendonly yes #开启aof持久化 EOF
# 通过脚本一次启动6个redis容器
docker run -p 637${port}:6379 -p 1637${port}:16379 --name redis-${port} \
-v /mydata/redis/node-${port}/data:/data \
-v /mydata/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis_cluster --ip 172.38.1.1${port} redis:6.0 redis-server /etc/redis/redis.conf
done
三、创建集群
docker exec -it redis-1 bash
redis-cli --cluster create 172.38.1.11:6379 172.38.1.12:6379 172.38.1.13:6379 172.38.1.14:6379 172.38.1.15:6379 172.38.1.16:6379 --cluster-replicas 1
redis-cli -c #进入集群
cluster info #查看集群信息
cluster nodes
四、卸载集群
for port in $(seq 1 6); do docker rm -f redis-${port}; done
rm -rf /mydata/redis
五、参考文章
边栏推荐
猜你喜欢
速看!2022年6月编程语言排行榜出炉!第一名太牛啦
Some exception handling for idea plug-in development
dat. gui. JS star circle track animation JS special effect
Detailed explanation of ThreadLocal
使用命令行安装达梦数据库
lottie. JS creative switch button animal head
Press key to control LED status reversal
“所有专业都在劝退”,对大学生最友好的竟然是它?
宁愿去996也不要待业在家啦!24岁,失业7个月,比上班更惨的,是没班可上
Sample development of WiFi IOT Hongmeng development kit
随机推荐
memcached基础10
Oracle/PLSQL: Replace Function
达梦数据库安装
Oracle/PLSQL: From_Tz function
TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
Why divide the training set and the test set before normalization?
Oracle/PLSQL: Lower Function
Hibernate generates SQL based on Dialect
Memcached Foundation 12
Cookie, sessionstorage, localstorage differences
Sample development of WiFi IOT Hongmeng development kit
Oracle/PLSQL: CharToRowid Function
Flink学习3:数据处理模式(流批处理)
Learn the most basic operation of discodiffusion
canvas粒子篇之鼠标跟随js特效
我靠副业一个月挣了3W块:你看不起的行业,真的很挣钱!
谷歌开始卷自己,AI架构Pathways加持,推出200亿生成模型
热议:月薪1.8万却毫无意义的工作,你干吗?
Oracle/PLSQL: From_ Tz function
“所有专业都在劝退”,对大学生最友好的竟然是它?