赞
踩
redis 三主六从高可用dockerswarm高级版(不固定ip)
由于数据量过大,单个Master复制集难以承担,因此需要对多个复制集进行集群,形成水平扩展每个复制集只负责存储整个数据集的一部分,这就是Redis的集群,其作用是提供在多个Redis节点间共享数据的程序集。
官网介绍地址
安装文件下载链接(或者按照下面的步骤自己创建)
链接:https://pan.baidu.com/s/1tLgLYWkawTvU17yvU1M_5A?pwd=xp9p
主机 | IP |
---|---|
node1 | 192.168.56.100 |
node2 | 192.168.56.101 |
node3 | 192.168.56.102 |
在node1 开放防火墙:
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.56.101" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.56.102" accept"
firewall-cmd --reload
firewall-cmd --list-all
在node2 开放防火墙:
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.56.100" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.56.102" accept"
firewall-cmd --reload
firewall-cmd --list-all
在node3 开放防火墙:
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.56.101" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.56.100" accept"
firewall-cmd --reload
firewall-cmd --list-all
mkdir -p /home/redis && cd /home/redis
3台机器分别将redis.zip拷贝到 /home/redis
在node1上执行:
docker swarm init --advertise-addr 192.168.56.100
docker swarm join-token manager
返回类似以下内容:
docker swarm join --token SWMTKN-1-614xi9dvksycykobgifxb4pgopc1wwgczwqct5wqkq8zao6tmx-0ds4jj3ozclrr2wukcaoakxso 192.168.56.100:2377
docker swarm join --token SWMTKN-1-2c2xopn2rld8oltcof24sue370681ijhbo3bwcqarjlhq9lkea-2g53o5qn2anre4j9puv4hecrn 192.168.0.101:2377
在node1上执行以下命令:
docker network create --subnet=10.0.1.0/24 -d overlay --attachable pxc_swarm
├─node1 │ ├─conf │ ├─redis1 │ │ └─data │ └─redis2 │ └─data ├─node2 │ ├─conf │ ├─redis1 │ │ └─data │ └─redis2 │ └─data └─node3 ├─conf ├─redis1 │ └─data └─redis2 └─data
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
version: '3' networks: pxc_swarm: external: true services: redis1: image: redis:6.0-alpine hostname: redis1 container_name: redis1 volumes: - "/home/redis/redis1/data:/data" - "/home/redis/conf/redis.conf:/etc/redis.conf" command: redis-server /etc/redis.conf restart: always privileged: true networks: pxc_swarm: ipv4_address: 10.0.1.10 redis2: image: redis:6.0-alpine hostname: redis2 container_name: redis2 volumes: - "/home/redis/redis2/data:/data" - "/home/redis/conf/redis.conf:/etc/redis.conf" command: redis-server /etc/redis.conf restart: always privileged: true networks: pxc_swarm: ipv4_address: 10.0.1.11
version: '3' networks: pxc_swarm: external: true services: redis1: image: redis:6.0-alpine hostname: redis1 container_name: redis1 volumes: - "/home/redis/redis1/data:/data" - "/home/redis/conf/redis.conf:/etc/redis.conf" command: redis-server /etc/redis.conf restart: always privileged: true networks: pxc_swarm: ipv4_address: 10.0.1.20 redis2: image: redis:6.0-alpine hostname: redis2 container_name: redis2 volumes: - "/home/redis/redis2/data:/data" - "/home/redis/conf/redis.conf:/etc/redis.conf" command: redis-server /etc/redis.conf command: redis-server /etc/redis.conf restart: always privileged: true networks: pxc_swarm: ipv4_address: 10.0.1.21
version: '3' networks: pxc_swarm: external: true services: redis1: image: redis:6.0-alpine hostname: redis1 container_name: redis1 volumes: - "/home/redis/redis1/data:/data" - "/home/redis/conf/redis.conf:/etc/redis.conf" command: redis-server /etc/redis.conf restart: always privileged: true networks: pxc_swarm: ipv4_address: 10.0.1.30 redis2: image: redis:6.0-alpine hostname: redis2 container_name: redis2 volumes: - "/home/redis/redis2/data:/data" - "/home/redis/conf/redis.conf:/etc/redis.conf" command: redis-server /etc/redis.conf command: redis-server /etc/redis.conf restart: always privileged: true networks: pxc_swarm: ipv4_address: 10.0.1.31
rm -rf /home/redis/node2
rm -rf /home/redis/node3
cd /home/redis/node1 && docker-compose up -d
rm -rf /home/redis/node1
rm -rf /home/redis/node3
docker run --rm redis:6.0-alpine redis-cli -v
cd /home/redis/node2 && docker-compose up -d
rm -rf /home/redis/node1
rm -rf /home/redis/node2
docker run --rm redis:6.0-alpine redis-cli -v
cd /home/redis/node3 && docker-compose up -d
docker exec -it redis1 /bin/sh
redis-cli --cluster create 10.0.1.10:6379 10.0.1.20:6379 10.0.1.11:6379 10.0.1.30:6379 10.0.1.21:6379 10.0.1.31:6379 --cluster-replicas 1
M: 1ff0c227fff72b893e8c7514a7d8f49183f0a397 10.0.1.10:6379 slots:[0-5460] (5461 slots) master M: 5242fb87c0c7f0179d32727b6043cc546ec1a731 10.0.1.20:6379 slots:[5461-10922] (5462 slots) master M: 7daa8da3450adc53ac88eda3a3c1a8f2c1976c02 10.0.1.11:6379 slots:[10923-16383] (5461 slots) master S: 962e2b4516cb7186f407d6ffc3a91b62603e0a09 10.0.1.30:6379 replicates 7daa8da3450adc53ac88eda3a3c1a8f2c1976c02 S: 04fff0c1488896bef11aa508edbbf5ac6c29815b 10.0.1.21:6379 replicates 1ff0c227fff72b893e8c7514a7d8f49183f0a397 S: 2e43a4d7b46b20e60220b4f495d8370b07c717bd 10.0.1.31:6379 replicates 5242fb87c0c7f0179d32727b6043cc546ec1a731 10 21 20 31 11 30
所有主从不允许在同一台机器上
# 查看节点
cluster nodes
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。