1.关闭防火墙+启动docker后台服务
systemctl start docker
2.新建6个docker容器redis实例
docker run -d --name redis-node-1 --net host --privileged=true -v /home/redis/share/redis-node-1:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6381
docker run -d --name redis-node-2 --net host --privileged=true -v /home/redis/share/redis-node-2:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6382
docker run -d --name redis-node-3 --net host --privileged=true -v /home/redis/share/redis-node-3:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6383
docker run -d --name redis-node-4 --net host --privileged=true -v /home/redis/share/redis-node-4:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6384
docker run -d --name redis-node-5 --net host --privileged=true -v /home/redis/share/redis-node-5:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6385
docker run -d --name redis-node-6 --net host --privileged=true -v /home/redis/share/redis-node-6:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6386
命令分步解释
docker run 创建并运行docker容器实例
--name redis-node-6 容器名字
--net host 使用宿主机的IP和端口,默认
--privileged=true 获取宿主机root用户权限
-v /data/redis/share/redis-node-6:/data 容器卷,宿主机地址:docker内部地址
redis:6.0.8 redis镜像和版本号
--cluster-enabled yes 开启redis集群
--appendonly yes 开启持久化
--port 6386 redis端口号
运行结果
[root@localhost home]# docker run -d --name redis-node-1 --net host --privileged=true -v /home/redis/share/redis-node-1:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6381
bed3ef4d9f9c828a3f1788066b4adfbbc44ef84e9e606695efde81842982fd74
[root@localhost home]#
[root@localhost home]# docker run -d --name redis-node-2 --net host --privileged=true -v /home/redis/share/redis-node-2:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6382
a8c03a8ccd2718df67be1993b0cceb318fb7176bbeab8a3bc40cff006d8a9be0
[root@localhost home]#
[root@localhost home]# docker run -d --name redis-node-3 --net host --privileged=true -v /home/redis/share/redis-node-3:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6383
40dc2219ea746fa32e6193086a2f9fe8119766c6c63168732cd05f2132a5a926
[root@localhost home]#
[root@localhost home]# docker run -d --name redis-node-4 --net host --privileged=true -v /home/redis/share/redis-node-4:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6384
798bffb2a259a1804e8fb80cdd0703b67d95048af0f28c28f2fd18442b5cd415
[root@localhost home]#
[root@localhost home]# docker run -d --name redis-node-5 --net host --privileged=true -v /home/redis/share/redis-node-5:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6385
8a16b360409bedf4830d29dd1d4d8e4f64052678abb7c64326a02ebb33cae0a6
[root@localhost home]#
[root@localhost home]# docker run -d --name redis-node-6 --net host --privileged=true -v /home/redis/share/redis-node-6:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6386
26fd5996d93d81cf37997e17379723b9a9b63073e31ed981af5ab3bdc8d417d8