CentOS 6.5 64位下Redis主从复制配置

树叶云

该文使用CentOS 6.5 64位  Redis3.2.8   

主从复制

Redis的复制功能是支持多个数据库之间的数据同步。一类是主数据库(master)一类是从数据库(slave),主数据库可以进行读写操作,当发生写操作的时候自动将数据同步到从数据库,而从数据库一般是只读的,并接收主数据库同步过来的数据,一个主数据库可以有多个从数据库,而一个从数据库只能有一个主数据库。通过redis的复制功能可以很好的实现数据库的读写分离,提高服务器的负载能力。主数据库主要进行写操作,而从数据库负责读操作。

Redis主从复制:主从复制可以允许多个slave server 拥有和master server相同的数据库副本

1、Redis主从复制的特点:

a、  master 可以有多个slave

b、  多个slave 可以链接同一个master外,还可以链接其他slave

c、  主从复制不会阻塞master,在数据同步的时候,master可以继续处理client请求

d、  提高系统的伸缩性

2、Redis主从复制的过程:

a、  slave与master建立链接,发送sync同步请求。

b、  master会启动一个后台进程,将数据库快照保存到文件中,同时master主进程会开始收集新的写命令并缓存。

c、  后台完成保存后,就将此文件发送给slave

d、  Slave将此文件保存到硬盘上。

3、Redis 主从复制操作步骤

环境:

Redis主从结构支持一主多从(所有从节点的配置都一样)

master:192.168.6.190

slave:192.168.6.191

配置:

配置slave服务器,在slave服务器的配置文件中加入一下代码

slaveof 192.168.222.1 6379 #指定master的ip和端口

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

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 1) Redis replication is asynchronous, but you can configure a master to
#    stop accepting writes if it appears to be not connected with at least
#    a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
#    network partition slaves automatically try to reconnect to masters
#    and resynchronize with them.
#
# slaveof <masterip> <masterport>
slaveof 192.168.6.190 6379
# 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>

启动master服务器:

[root@localhost bin]# ./redis-server /usr/local/redis/etc/redis.conf

查看master配置信息:127.0.0.1:6379> info

# Replication
role:master
connected_slaves:1
slave0:ip=192.168.6.191,port=6379,state=online,offset=141,lag=0
master_repl_offset:141
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:140

启动slave服务器:

[root@localhost bin]# ./redis-server /usr/local/redis/etc/redis.conf

查看slave配置信息:127.0.0.1:6379> info

# Replication
role:slave
master_host:192.168.6.190
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:99
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

测试:

master:

slave:

配置时遇到错误:master_link_status:down

1、确定master与slave的redis端口是开放的,未被防火墙拦截

2、修改 master redis.cnf 文件中bind 为bind 0.0.0.0

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/204288.html<

(0)
运维的头像运维
上一篇2025-04-07 02:17
下一篇 2025-04-07 02:18

相关推荐

  • win2003 3389手工修改方法

    下面,我们来看看如何通过修改默认端口,防范黑客入侵。   众所周知,远程终端服务基于端口3389。入侵者一般先扫描主机开放端口,一旦发现其开放了3389端口,就会进行下一步的入侵,…

  • Ubuntu 20.04及其所有官方版本Beta已开放下载

    在发布新版本的Ubuntu之后,Canonical就开始着手开发下一个版本。他们可能需要一周的时间,但是很快就会启动所谓的“每日构建”,它是每日映像,其中包括前一天引入的所有更改。…

  • Linux下扩展XfS具体方法

    XfS文件系统是SGI开发的高级日志文件系统,XFS极具伸缩性,非常健壮。所幸的是SGI将其移植到了Linux系统中。在linux环境下。目前版本可用的最新XFS文件系统的为1.2…

  • Centos设置GRUB2引导程序背景

    在默认情况下Centos/RedHat系列的Linux操作系统都没有配置grub背景,当做服务器使用的话可能会无所谓,如果自己使用的话,总是想着让它看起来美丽一些,在本篇文章中在g…

  • Linux系统中安装MariaDB具体方法

    MariaDB数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MyS…

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注