安装 redis 集群
172.13.3.160 为宿主机IP
redis1.conf 同样的配置只需要改prot
port 7001
protected-mode no
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.13.3.160
cluster-announce-port 7001
cluster-announce-bus-port 17001
appendonly yes
pidfile /var/run/redis_7001.pid
redis2.conf 同样的配置只需要改prot
port 7002
protected-mode no
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.13.3.160
cluster-announce-port 7002
cluster-announce-bus-port 17002
appendonly yes
pidfile /var/run/redis_7002.pid
生成6份
docker-compose.yml
version: '3.7'
x-image:
&redis-image
redis:5.0.7
services:
redis1:
image: *redis-image
container_name: redis1
command:
["redis-server", "/home/redis/cluster/redis.conf"]
volumes:
- ./redis1.conf:/home/redis/cluster/redis.conf
- ./7001/data:/data
ports:
- 7001:7001
- 17001:17001
redis2:
image: *redis-image
container_name: redis2
command:
["redis-server", "/home/redis/cluster/redis.conf"]
volumes:
- ./redis2.conf:/home/redis/cluster/redis.conf
- ./7002/data:/data
ports:
- 7002:7002
- 17002:17002
redis3:
image: *redis-image
container_name: redis3
command:
["redis-server", "/home/redis/cluster/redis.conf"]
volumes:
- ./redis3.conf:/home/redis/cluster/redis.conf
- ./7003/data:/data
ports:
- 7003:7003
- 17003:17003
redis4:
image: *redis-image
container_name: redis4
command:
["redis-server", "/home/redis/cluster/redis.conf"]
volumes:
- ./redis4.conf:/home/redis/cluster/redis.conf
- ./7004/data:/data
ports:
- 7004:7004
- 17004:17004
redis5:
image: *redis-image
container_name: redis5
command:
["redis-server", "/home/redis/cluster/redis.conf"]
volumes:
- ./redis5.conf:/home/redis/cluster/redis.conf
- ./7005/data:/data
ports:
- 7005:7005
- 17005:17005
redis6:
image: *redis-image
container_name: redis6
command:
["redis-server", "/home/redis/cluster/redis.conf"]
volumes:
- ./redis6.conf:/home/redis/cluster/redis.conf
- ./7006/data:/data
ports:
- 7006:7006
- 17006:17006
执行命令
#关闭防火墙
firewall-cmd --state
systemctl stop firewalld.service
systemctl disable firewalld.service
docker-compose up -d 编译并运行
docker-compose down 杀死并删除
docker-compose start
docker-compose stop
docker exec -it redis1 /bin/bash
redis-cli --cluster create 172.13.3.160:7001 172.13.3.160:7002 172.13.3.160:7003 172.13.3.160:7004 172.13.3.160:7005 172.13.3.160:7006 --cluster-replicas 1
redis-cli -c -p 7001