三主机模式

10.1.2.40

10.1.2.41

10.1.2.42

创建配置文件三台主机相同

创建6380端口配置文件

[root@localhost ~]# mkdir -p /home/redis/6380 && cd $_
[root@localhost 6380]# vim redis.conf
port 6380

protected-mode no

pidfile /var/run/redis_6380.pid

appendonly yes

cluster-enabled yes

cluster-config-file nodes-6380.conf

cluster-node-timeout 15000

masterauth password

requirepass password

创建6381端口配置文件

[root@localhost ~]#  mkdir -p /home/redis/6381 && cd $_
[root@localhost 6381]#  vim redis.conf
port 6381

protected-mode no

pidfile /var/run/redis_6381.pid

appendonly yes

cluster-enabled yes

cluster-config-file nodes-6381.conf

cluster-node-timeout 15000

masterauth password

requirepass password

三台主机分别启动容器

[root@localhost ~]# docker run -v /home/redis/6380/:/data --privileged=true --net host --name redis-6380 -d redis:latest redis-server /data/redis.conf

[root@localhost ~]# docker run -v /home/redis/6381:/data --privileged=true --net host --name redis-6381 -d redis:latest redis-server /data/redis.conf

建立集群关系

[root@localhost ~]# docker exec -it redis-6380 redis-cli --cluster create 10.2.1.40:6380 10.2.1.40:6381 10.2.1.41:6380 10.2.1.41:6381 10.2.1.42:6380 10.2.1.42:6381 --cluster-replicas 1

登录任意一个redis,查看集群关系

[root@localhost ~]# docker exec -it redis-6380 /bin/bash redis-cli  -h 10.2.1.40 -p 6380 -a password
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.2.1.40:6380> 
10.2.1.40:6380> info replication
# Replication
role:slave
master_host:10.2.1.41
master_port:6381
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_read_repl_offset:1082411
slave_repl_offset:1082411
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:377c2e409981d652cf0d41835cf272f75ec43654
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1082411
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:121854
repl_backlog_histlen:960558
10.2.1.40:6380> 

从上面可以看出10.2.1.40以6380启动的redis是slave,他的master是10.2.1.41的6381实例

哔哔(0)
暂无评论,快来抢沙发