美文网首页
Docker部署Redis集群

Docker部署Redis集群

作者: Crud仔 | 来源:发表于2021-07-18 14:44 被阅读0次

1.创建redis自定义集群网卡及查看

[root@centos data]# docker network create redis --subnet 172.38.0.0/16
14e37cd6a2ef85ffb12c469af5b19b94ecf92bb1b257caf9b7676cd8c221a942
[root@centos data]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
333203a3f1b8   bridge    bridge    local
8aff6011c1e2   host      host      local
e47411ee61ec   none      null      local
14e37cd6a2ef   redis     bridge    local
[root@centos data]# docker network inspect redis
[
    {
        "Name": "redis",
        "Id": "14e37cd6a2ef85ffb12c469af5b19b94ecf92bb1b257caf9b7676cd8c221a942",
        "Created": "2021-07-18T14:21:24.787316197+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.38.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
[root@centos data]#

2.redis节点创建及设置

创建redis config脚本

for port in $(seq 1 6);
do
mkdir -p /data/redis/node-${port}/conf
touch /data/redis/node-${port}/conf/redis.conf
cat << EOF >/data/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 

创建节点脚本

for port in $(seq 1 6);
do
    docker run -p 637${port}:6379 -p 1637${port}:16379 --name redis-${port} \
 -v /data/redis/node-${port}/data:/data \
 -v /data/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf \
 -d --net redis --ip 172.38.0.1${port} redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
done

3.创建集群

# 以交互模式进入redis节点内
docker exec -it redis-1 /bin/sh
# 创建集群
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

出现如下结果成功

[root@centos data]# docker exec -it redis-1 /bin/sh
/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: 4684ecfa840473774ab4a511db81195339101af4 172.38.0.11:6379
   slots:[0-5460] (5461 slots) master
M: aac2e247f6060a876c3a7edbbc96fd779f9d9b62 172.38.0.12:6379
   slots:[5461-10922] (5462 slots) master
M: 72d6df90f1efed560579a51beeab56d514ceb04a 172.38.0.13:6379
   slots:[10923-16383] (5461 slots) master
S: 90ca4e2ead6b6404dae7ce6f9fca058109a5825f 172.38.0.14:6379
   replicates 72d6df90f1efed560579a51beeab56d514ceb04a
S: 4903bd202cc0fec5edbbd5c008779c62abae6788 172.38.0.15:6379
   replicates 4684ecfa840473774ab4a511db81195339101af4
S: 406aa8a62807b11ada9f807649cfff78fad85c27 172.38.0.16:6379
   replicates aac2e247f6060a876c3a7edbbc96fd779f9d9b62
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: 4684ecfa840473774ab4a511db81195339101af4 172.38.0.11:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 90ca4e2ead6b6404dae7ce6f9fca058109a5825f 172.38.0.14:6379
   slots: (0 slots) slave
   replicates 72d6df90f1efed560579a51beeab56d514ceb04a
S: 4903bd202cc0fec5edbbd5c008779c62abae6788 172.38.0.15:6379
   slots: (0 slots) slave
   replicates 4684ecfa840473774ab4a511db81195339101af4
M: 72d6df90f1efed560579a51beeab56d514ceb04a 172.38.0.13:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: aac2e247f6060a876c3a7edbbc96fd779f9d9b62 172.38.0.12:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 406aa8a62807b11ada9f807649cfff78fad85c27 172.38.0.16:6379
   slots: (0 slots) slave
   replicates aac2e247f6060a876c3a7edbbc96fd779f9d9b62
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
/data # 

相关文章

  • 单机(win10)使用Docker搭建Redis集群(Redis

    搭建过程参考:使用Docker搭建Redis集群(Redis Sentinel 集群部署) 概述 Redis 集群...

  • Docker环境搭建redis集群(主从模式)

    Docker环境搭建redis集群(主从模式) 序 本文将介绍如何在docker中部署redis集群(主从模式)。...

  • Centos7使用docker

    主要记录docker的使用,安装mysql集群,redis集群,以及前后端项目部署。 Centos安装Docker...

  • Docker搭建Redis Cluster

    为了体验Redis集群,并且为了便于部署所以直接使用docker部署了一个简单集群: 连接测试 通过set 命令测...

  • 10 Docker网络

    理解Docker0 参数--link 自定义网络 网络连通 实战:部署redis集群 理解Docker0 清空所有...

  • Redis集群部署-docker集群

    集群 1.Redis 集群的优势 自动分割数据到不同的节点上。整个集群的部分节点失败或者不可达的情况下能够继续处理...

  • Redis集群Docker部署

    因机器限制,用两台主机部署一个三主三从的redis集群架构(记为1,2) 1号机部署步骤 新建redis目录 编写...

  • Docker部署Redis集群

    搭建Docker 从docker库获取redis镜像 创建redis容器(run命令) 创建6个容器,3主3从。接...

  • Docker 部署 redis集群

  • Docker部署Redis集群

    1.创建redis自定义集群网卡及查看 2.redis节点创建及设置 创建redis config脚本 创建节点脚...

网友评论

      本文标题:Docker部署Redis集群

      本文链接:https://www.haomeiwen.com/subject/bhcapltx.html