redis主从复制

一、主从复制

1、是什么?

主机数据更新后根据配置和策略,自动同步到备机的 master / slave 机制,Master以写为主,Slave以读为主。

2、能干嘛?

  • 读写分离
  • 容灾恢复

3、怎么用?

1)配置从库不配主库

2)从库配置:slaveof、主库IP、主库端口

每次与master断开后,都要重新连接,除非你配置进redis.conf文件

info reputation:查案当前机器处于怎样的状态。


4、配置机器成为另一台机器的从机

slaveof IP 端口号

注意: 主机的端口要对从机开放,阿里云/腾讯云 安全组设置开放端口,bind开放以及关闭保护模式 

#注意: 主机的端口要对从机开放,阿里云/腾讯云 安全组设置开放端口,bind开放以及关闭保护模式

# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0 #对外网开放

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no #关闭安全模式

5、主从复制的特点 

  • 主机支持读写,从机只支持读
  • 一台机器变成从机则会全部复制主机数据
  • 主机宕机重新恢复还是主机,从机宕机恢复还是从机

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值