redis主从配置

1.修改主服务器的配置文件

#把bind改为当前主机ip

#bind 127.0.0.1

bind 192.168.96.128

然后启动redis服务,/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf

2.修改从服务器的配置文件

#把bind改为当前主机ip

#bind 127.0.0.1

bind 192.168.96.129

#修改本机为从服务器角色

slaveof 192.168.96.128 6379

启动从服务器redis, /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf

3.查看是否配置正确

/usr/local/redis/bin/redis-cli -h 192.168.96.128 -p 6379

192.168.96.128:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.96.129,port=6379,state=online,offset=1294,lag=0
slave1:ip=192.168.96.130,port=6379,state=online,offset=1294,lag=0
master_replid:32e719d332e8b4542573e678e20ab2a93d26310a
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1294
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1294
192.168.96.128:6379>

你可能感兴趣的:(redis)