-
-
Save shinyzhu/ae867cda5ed75141434c63daa847bffc to your computer and use it in GitHub Desktop.
Use redis-cli to create a Redis Cluster on Docker (with Redis 5.0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------ bootstrap the cluster nodes -------------------- | |
redis_image='redis:5' | |
network_name='host' # must be in host mode | |
#---------- create the cluster ------------------------ | |
for port in `seq 6379 6384`; do \ | |
start_cmd="redis-server --port $port --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes" | |
docker run -d --name "redis-"$port -p $port:6379 --net $network_name $redis_image $start_cmd; | |
echo "created redis cluster node redis-"$port | |
done | |
cluster_hosts='' | |
for port in `seq 6379 6384`; do \ | |
hostip='192.168.1.100' # Should be your host's public ip | |
echo "IP for cluster node redis-"$port "is" $hostip | |
cluster_hosts="$cluster_hosts$hostip:$port "; | |
done | |
echo "cluster hosts "$cluster_hosts | |
echo "creating cluster...." | |
echo 'yes' | docker run -i --rm --net $network_name $redis_image redis-cli --cluster create $cluster_hosts --cluster-replicas 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the output is: