else
exit $RESULT
fi
redis-start.sh
getent hosts xxx
查看主机中/etc/hosts
域名映射的IP
cd /redis-start/
bash wait-for-it.sh redis-node1:6379 --timeout=0
bash wait-for-it.sh redis-node2:6379 --timeout=0
bash wait-for-it.sh redis-node3:6379 --timeout=0
bash wait-for-it.sh redis-node4:6379 --timeout=0
bash wait-for-it.sh redis-node5:6379 --timeout=0
bash wait-for-it.sh redis-node6:6379 --timeout=0
echo 'redis-cluster begin'
echo 'yes' | redis-cli --cluster create --cluster-replicas 1 \
`getent hosts redis-node1 | awk '{ print $1 ":6379" }'` \
`getent hosts redis-node2 | awk '{ print $1 ":6379" }'` \
`getent hosts redis-node3 | awk '{ print $1 ":6379" }'` \
`getent hosts redis-node4 | awk '{ print $1 ":6379" }'` \
`getent hosts redis-node5 | awk '{ print $1 ":6379" }'` \
`getent hosts redis-node6 | awk '{ print $1 ":6379" }'`
echo 'redis-cluster end'
启动
目录结构
├── docker-compose.yml
└── start
├── redis-start.sh
└── wait-for-it.sh
swarm管理节点执行
cd /root/redis-swarm
docker stack deploy -c docker-compose.yml redis_cluster
查看redis-start服务日志,如下即为启动成功
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: waiting for redis-node1:6379 without a timeout
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: redis-node1:6379 is available after 18 seconds
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: waiting for redis-node2:6379 without a timeout
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: redis-node2:6379 is available after 13 seconds
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: waiting for redis-node3:6379 without a timeout
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: redis-node3:6379 is available after 0 seconds
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: waiting for redis-node4:6379 without a timeout
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: redis-node4:6379 is available after 0 seconds
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: waiting for redis-node5:6379 without a timeout
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: redis-node5:6379 is available after 0 seconds
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: waiting for redis-node6:6379 without a timeout
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | wait-for-it.sh: redis-node6:6379 is available after 0 seconds
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | redis-cluster begin
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | >>> Performing hash slots allocation on 12 nodes...
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | Master[0] -> Slots 0 - 2730
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | Master[1] -> Slots 2731 - 5460
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | Master[2] -> Slots 5461 - 8191
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | Master[3] -> Slots 8192 - 10922
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | Master[4] -> Slots 10923 - 13652
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | Master[5] -> Slots 13653 - 16383
redis-swarm_redis-start.1.6xawjqf5shfw@hyx-test3 | Adding replica 10.0.5.6:6379 to 10.0.5.17