环境准备
master: 1992.168.1.1
slave: 192.168.1.2
slave: 192.168.1.3
修改配置
- 192.168.1.1
bind 192.168.1.1
daemonize yes #允许后台启动
logfile "/usr/local/redis/redis.log" #日志路径
dir /data/redis #数据备份文件存放目录
masterauth 123456 #slave链接master密码, master可省略
requirepass 123456 #设置master链接密码
appendonly yes #在/data/redis/目录下生成appendonly.aof文件
- 192.168.1.2
bind 192.168.1.2
daemonize yes #允许后台启动
logfile "/usr/local/redis/redis.log" #日志路径
dir /data/redis #数据备份文件存放目录
replicaof 192.168.1.1 6379
masterauth 123456 #slave链接master密码, master可省略
requirepass 123456 #设置master链接密码
appendonly yes #在/data/redis/目录下生成appendonly.aof文件
- 192.168.1.3
bind 192.168.1.3
daemonize yes #允许后台启动
logfile "/usr/local/redis/redis.log" #日志路径
dir /data/redis #数据备份文件存放目录
replicaof 192.168.1.1 6379
masterauth 123456 #slave链接master密码, master可省略
requirepass 123456 #设置master链接密码
appendonly yes #在/data/redis/目录下生成appendonly.aof文件
查看状态
192.168.1.1:6379> info replication
role:master
connected_slaves:2
slave0:ip=192.168.1.2,port=6379,state=online,offset=168,lag=1
slave1:ip=192.168.1.3,port=6379,state=online,offset=168,lag=1
master_replid:fb4941e02d5032ad74c6e2383211fc58963dbe90
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:168
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:168