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

本文介绍如何通过配置Redis实现主从复制模式,减轻单台服务器负载。主服务器负责写操作,从服务器则处理读请求。文章详细展示了如何配置从服务器,并提到了从服务器默认禁止写入操作的特点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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


配置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服务(杀死旧进程,启动新进程)


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

# 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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值