Redis的Replication(主从复制)和sentinel机制

Replication

特点:
一个Master可以有多个slave主机,支持链式复制;
Master以非阻塞方式同步数据至slave主机;

配置参数:

配置slave节点:
slaveof 主机ip 主机port
设置当本机为slav服务时,设置master服务的IP地址及端口,在Redis启 动时,它会自动从master进行数据同步;
masterauth 主机password
当master服务设置了密码保护时,slav服务连接master的密码
实验:环境:centos7.3
准备两个节点master :192.168.23.148
slave: 192.168.23.149
配置slave节点:

[root@cento7 ~]# vim /etc/redis.conf 

# 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 lookback 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 127.0.0.1
bind 192.168.23.149 #为了方便看清自己的ip 又绑定一个ip
# slaveof <masterip> <masterport> #指定主机的IP地址
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth <master-password> # 如果主机ip有密码的话  指定主机的iP密码
#当然也可以在客户端设置
[root@cento7 ~]# redis-cli -h 192.168.23.149
192.168.23.149:6379> slaveof 192.168.23.148 6379
OK
192.168.23.149:6379> config set masterauth magedu
OK

从节点查看info信息记日志:

192.168.23.149:6379> info replication #INFO信息
# Replication
role:slave
master_host:192.168.23.148
master_port:6379
master_link_status:up
master_last_io_seconds_ago:7
master_sync_in_progress:0
slave_repl_offset:841
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
[root@cento7 ~]# tail /var/log/redis/redis.log #日志信息
1916:S 16 Sep 15:38:52.335 * Connecting to MASTER 192.168.23.148:6379
1916:S 16 Sep 15:38:52.335 * MASTER <-> SLAVE sync started
1916:S 16 Sep 15:38:52.336 * Non blocking connect for SYNC fired the event.
1916:S 16 Sep 15:38:52.336 * Master replied to PING, replication can continue...
1916:S 16 Sep 15:38:52.337 * Partial resynchronization not possible (no cached master)
1916:S 16 Sep 15:38:52.339 * Full resync from master: 9efb89fac553574f70e5151a4f419750e47768bc:631
1916:S 16 Sep 15:38:52.438 * MASTER <-> SLAVE sync: receiving 259 bytes from master
1916:S 16 Sep 15:38:52.438 * MASTER <-> SLAVE sync: Flushing old data
1916:S 16 Sep 15:38:52.439 * MASTER <-> SLAVE sync: Loading DB in memory
1916:S 16 Sep 15:38:52.439 * MASTER <-> SLAVE sync: Finished with success

主节点的info信息记日志:

192.168.23.148:6379> INFO replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.23.14
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值