Redis的主从模式-Redis学习笔记五

为了降低每个redis服务器的负载,可以多设置几个,并做主从模式。一个服务器负载“写”(添加、修改、删除)数据,其他服务器负载“读”数据

主服务器数据会“自动”同步给从服务器

Redis的主从模式-Redis学习笔记五_第1张图片

配置redis.conf文件,配置为192.168.39.159的从服务器:


################################# REPLICATION #################################

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#
# slaveof <masterip> <masterport>

 slaveof 192.168.1.3 6379

配置文件修改后,重启redis服务(杀死旧进程,启动新进程)

Redis的主从模式-Redis学习笔记五_第2张图片

从服务器默认禁止写入操作(可以修改如下图参数使得其可以写入数据)

# Note: read only slaves are not designed to be exposed to untrusted clients
# on the internet. It's just a protection layer against misuse of the instance.
# Still a read only slave exports by default all the administrative commands
# such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
# security of read only slaves using 'rename-command' to shadow all the
# administrative / dangerous commands.
slave-read-only yes


你可能感兴趣的:(Redis的主从模式-Redis学习笔记五)