#拉去镜像(注:我这里拉取过了,和你们显示的有出入)
[root@centos-linux ~]# docker pull redis
[root@centos-linux ~]# docker images
#创建集群目录
[root@centos-linux ~]# mkdir redis-cluster-d
[root@centos-linux ~]# cd redis-cluster-d/
#创建执行文件
[root@centos-linux redis-cluster-d]# vi redis-cluster.tmpl
文件内容
port ${PORT}
masterauth 123456
requirepass 123456
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 127.0.0.1
cluster-announce-port ${PORT}
cluster-announce-bus-port 1${PORT}
appendonly yes
#使用命令:在 redis-cluster下生成conf和data目标,并生成配置信息
[root@centos-linux redis-cluster-d]# for port in `seq 7001 7006`; do > mkdir -p ./${port}/conf > && PORT=${port} envsubst < ./redis-cluster.tmpl > ./${port}/conf/redis.conf > && mkdir -p ./${port}/data; > done
#后会生成一下目录
#创建六个redis容器
[root@centos-linux redis-cluster-d]# for port in `seq 7001 7006`; do
> docker run -d --net=host -v /root/redis-cluster-d/${port}/conf/redis.conf:/etc/redis/redis.conf -v /root/redis-cluster-d/${port}/data:/data --restart always --name=redis-${port} redis redis-server /etc/redis/redis.conf;
> done
#进入容器
[root@centos-linux redis-cluster-d]# docker exec -it redis-7001 bash
root@centos-linux:/data# redis-cli -a 123456 --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
#成功案例,您可以往下执行这个操作
root@centos-linux:/data# redis-cli -c -a 123456 -h 127.0.0.1 -p 7001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:7001> CLUSTER NODES
d18b5b8bc8d2774278d02ca5ecfa7c025fa9f7ac 127.0.0.1:7002@17002 master - 0 1599118838500 2 connected 5461-10922
3c3bbdce11728349eb90dfca026e41f00766aff9 127.0.0.1:7006@17006 slave 98ce25ac939261ce8df525644c91370b453a172d 0 1599118839003 1 connected
85a963da313fe027aab61447aa57f615a2588735 127.0.0.1:7003@17003 master - 0 1599118837000 3 connected 10923-16383
98ce25ac939261ce8df525644c91370b453a172d 127.0.0.1:7001@17001 myself,master - 0 1599118837000 1 connected 0-5460
5c286fe58f43e19e8d2f8e749b4b93bc8a169b49 127.0.0.1:7005@17005 slave 85a963da313fe027aab61447aa57f615a2588735 0 1599118837997 3 connected
a8a07776bb87eca78c56fe80e48dfafbd4d49390 127.0.0.1:7004@17004 slave d18b5b8bc8d2774278d02ca5ecfa7c025fa9f7ac 0 1599118837494 2 connected
127.0.0.1:7001>
#######****************插播一个错误*****************###########
#下面标记红的waiting一直停不下来,说明创建集群的ip和redis.conf的ip对不上
去往学习的路上,请多多指教。。。。