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

docker 搭建伪分布模式redis机器

1、创建网络

创建:docker network create redis-net

查看:docker network inspect redis-net

Subnet": "172.19.0.0/16

Containers中无分配的ip

2、redis配置文件模板

#bind 172.38.0.1${NUMBER}
port ${PORT}
cluster-enabled yes
cluster-config-file nodes_${PORT}.conf
cluster-node-timeout 5000
#cluster-announce-ip 172.18.0.1${NUMBER}
#cluster-announce-ip 172.18.0.11
#cluster-announce-port ${PORT}
#cluster-announce-bus-port 1${PORT}
appendonly yes

3、根据模板创建目录和文件

#!/bin/bash
number=1
for port in $(seq 8010 8015); \
do \
  rm -rf ./${port} && \
  mkdir -p ./${port}/conf  \
  && PORT=${port} NUMBER=${number} envsubst < ./redis-cluster.tmpl > ./${port}/conf/redis.conf \
  && mkdir -p ./${port}/data; \
  number=$(($number+1))
done

4、创建和启动节点

#!/bin/bash
number=1
for port in $(seq 8010 8015); \
do \
   docker run -it -d -p ${port}:${port} -p 1${port}:1${port} \
  --privileged=true -v /Users/上面3创建目录/redis-cluster/${port}/conf/redis.conf:/usr/local/etc/redis/redis.conf \
  -v /Users/上面3创建目录/redis-cluster/${port}/data:/data \
  --restart always --name redis-${port} --net redis-net  \
  --sysctl net.core.somaxconn=1024 redis redis-server /usr/local/etc/redis/redis.conf; \
  number=$(($number+1))
done

5、进入单个接口创建集群(ip为Containers中无分配的ip分配的ip)

 docker exec -it redis-8010 /bin/bash

redis-cli --cluster create 172.19.0.2:8010 172.19.0.3:8011 172.19.0.4:8012 172.19.0.5:8013 172.19.0.6:8014 172.19.0.7:8015 --cluster-replicas 1

完成创建后显示

Adding replica 172.19.0.6:8014 to 172.19.0.2:8010
Adding replica 172.19.0.7:8015 to 172.19.0.3:8011
Adding replica 172.19.0.5:8013 to 172.19.0.4:8012
M: 5306c90636a4b7c2df5108caba6b6800cc859e3d 172.19.0.2:8010
   slots:[0-5460] (5461 slots) master
M: d6a28c87d83b39e11e9adad459a0cfcda4848199 172.19.0.3:8011
   slots:[5461-10922] (5462 slots) master
M: 2e4992b4a36168d63e48d8766fa85d37f0b70a93 172.19.0.4:8012
   slots:[10923-16383] (5461 slots) master
S: 9c3614c66ac64f8cec8c80a2d15979cfbc3f1f22 172.19.0.5:8013
   replicates 2e4992b4a36168d63e48d8766fa85d37f0b70a93
S: 0d362844457c8a7e4c54b8ee99d957a17877d815 172.19.0.6:8014
   replicates 5306c90636a4b7c2df5108caba6b6800cc859e3d
S: bb1f5ed102cdf157821946ee238148b83bd19716 172.19.0.7:8015
   replicates d6a28c87d83b39e11e9adad459a0cfcda4848199
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.19.0.2:8010)
M: 5306c90636a4b7c2df5108caba6b6800cc859e3d 172.19.0.2:8010
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: d6a28c87d83b39e11e9adad459a0cfcda4848199 172.19.0.3:8011
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 0d362844457c8a7e4c54b8ee99d957a17877d815 172.19.0.6:8014
   slots: (0 slots) slave
   replicates 5306c90636a4b7c2df5108caba6b6800cc859e3d
S: bb1f5ed102cdf157821946ee238148b83bd19716 172.19.0.7:8015
   slots: (0 slots) slave
   replicates d6a28c87d83b39e11e9adad459a0cfcda4848199
S: 9c3614c66ac64f8cec8c80a2d15979cfbc3f1f22 172.19.0.5:8013
   slots: (0 slots) slave
   replicates 2e4992b4a36168d63e48d8766fa85d37f0b70a93
M: 2e4992b4a36168d63e48d8766fa85d37f0b70a93 172.19.0.4:8012
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

6、连接集群

redis-cli -c -p 8010

相关文章:

  • 做网站是什么时候分页/1688黄页大全进口
  • wordpress时区设置/服务外包公司
  • 做展示型网站多少钱/软文什么意思
  • 番禺网站优化平台/电子商务
  • 广东网站建设服务/百度广告怎么推广
  • 澳门网站维护骗局/百度风云搜索榜
  • 网络安全日益严峻下计算机主机加固的意义
  • 为什么很少拿神经网络来直接做滤波器呢?
  • 右键万能格式转换工具
  • Linux 查看日志总结
  • hadoop3.x源码编译及cmake的问题解决:CMake failed with error code 1
  • 【自学Docker 】Docker管理命令大全(上)
  • Python【4】:eval() exec()
  • 数据结构与算法基础(王卓)(8):线性表的应用(并集和有序表合并)
  • 【java】java多线程及线程池面试题
  • SAP MM 物料分类账的启用配置
  • 搭建wordpress
  • CSDN网站勋章获取介绍