docker部署Redis-5.0主从版
1、创建Redis集群使用的网络
docker network create --subnet=172.21.10.0/16 RedisCluster
2、创建存储数据的文件目录
mkdir -p /data/redis_600{1..6}
3、启动脚本
#!/bin/bash docker run -d --name redis_1 --net RedisCluster --privileged=true -v /data/redis_6001:/data/ -v /data/redis_6001/redis.conf:/usr/local/etc/redis/redis.conf -p 6000:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file redis-6001.conf docker run -d --name redis_2 --net RedisCluster --privileged=true -v /data/redis_6002:/data/ -v /data/redis_6002/redis.conf:/usr/local/etc/redis/redis.conf -p 6001:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file redis-6002.conf docker run -d --name redis_3 --net RedisCluster --privileged=true -v /data/redis_6003:/data/ -v /data/redis_6003/redis.conf:/usr/local/etc/redis/redis.conf -p 6002:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file redis-6003.conf docker run -d --name redis_4 --net RedisCluster --privileged=true -v /data/redis_6004:/data/ -v /data/redis_6004/redis.conf:/usr/local/etc/redis/redis.conf -p 6003:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file redis-6004.conf docker run -d --name redis_5 --net RedisCluster --privileged=true -v /data/redis_6005:/data/ -v /data/redis_6005/redis.conf:/usr/local/etc/redis/redis.conf -p 6004:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file redis-6005.conf docker run -d --name redis_6 --net RedisCluster --privileged=true -v /data/redis_6006:/data/ -v /data/redis_6006/redis.conf:/usr/local/etc/redis/redis.conf -p 6005:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file redis-6006.conf docker ps -a | grep redis_ exit0
4、查看容器IP地址
docker inspect redis_1 | grep IPAddress | awk -F [:] 'NR==3{print $2}'| sed 's#"##g'| sed 's#,##g' && docker inspect redis_2 | grep IPAddress | awk -F [:] 'NR==3{print $2}'| sed 's#"##g'| sed 's#,##g' && docker inspect redis_3 | grep IPAddress | awk -F [:] 'NR==3{print $2}'| sed 's#"##g'| sed 's#,##g' && docker inspect redis_4 | grep IPAddress | awk -F [:] 'NR==3{print $2}'| sed 's#"##g'| sed 's#,##g' && docker inspect redis_5 | grep IPAddress | awk -F [:] 'NR==3{print $2}'| sed 's#"##g'| sed 's#,##g' && docker inspect redis_6 | grep IPAddress | awk -F [:] 'NR==3{print $2}'| sed 's#"##g'| sed 's#,##g'
5、获取到容器内部IP地址,添加节点到集群,查看集群信息
docker exec -it redis_1 /bin/bash redis-cli --cluster create 172.21.0.2:6379 172.21.0.3:6379 172.21.0.4:6379 172.21.0.5:6379 172.21.0.6:6379 172.21.0.7:6379 --cluster-replicas 1 cluster nodes cluster info
验证
验证数据写入
使劲折腾才会有更好的结果!!!!
如有不对请不吝赐教,感谢!
转载请注明出处!