Redis 学习之主从复制
该文使用centos6.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和端口
Masterauth jalja #主机密码

################################# 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>
masterauth jalja

启动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:
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set name jalja
OK
127.0.0.1:6379>
slave:
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set name jalja
OK
127.0.0.1:6379>
配置时遇到错误:master_link_status:down
1、确定master与slave的redis端口是开放的,未被防火墙拦截
2、修改 master redis.cnf 文件中bind 为bind 0.0.0.0
Redis 学习之主从复制的更多相关文章
- redis学习之——主从复制(replication)
准备:拥有linux环境,并安装redis mater:主机,进行写操作 slave:从机,进行读操作 一.配置 继续前边的学习.我们是拷贝redis.conf,文件到了/root /redis 下. ...
- Redis学习手册(主从复制)
一.Redis的Replication: 这里首先需要说明的是,在Redis中配置Master-Slave模式真是太简单了.相信在阅读完这篇Blog之后你也可以轻松做到.这里我们还是先列出一些理 ...
- Redis学习手册(主从复制)(转)
一.Redis的Replication: 这里首先需要说明的是,在Redis中配置Master-Slave模式真是太简单了.相信在阅读完这篇Blog之后你也可以轻松做到.这里我们还是先列出一些理论性的 ...
- Redis学习手册(目录)
为什么自己当初要选择Redis作为数据存储解决方案中的一员呢?现在能想到的原因主要有三.其一,Redis不仅性能高效,而且完全免费.其二,是基于C/C++开发的服务器,这里应该有一定的感情因素吧.最后 ...
- Redis学习手册——转载
转载出处:http://www.cnblogs.com/stephen-liu74/archive/2012/04/16/2370212.html 为什么自己当初要选择Redis作为数据存储解决方案中 ...
- Redis学习手册
为什么自己当初要选择Redis作为数据存储解决方案中的一员呢?现在能想到的原因主要有三.其一,Redis不仅性能高效,而且完全免费.其二,是基于C/C++开发的服务器,这里应该有一定的感情因素吧.最后 ...
- Redis学习-主从复制、哨兵
主从复制 官方文档:https://redis.io/topics/replication Redis中的主从复制,也就是Master-Slave模型,有以下特点 Master可以拥有多个slave ...
- redis学习(七)redis主从复制
redis主从复制 1.redis主从复制的作用 redis的定位是一个高可用的数据服务器,可是在实际生产环境下,单机的redis服务器是无法满足真正意义上的高可用性的. 第一,单机的redis服务器 ...
- Redis学习笔记之Redis单机,伪集群,Sentinel主从复制的安装和配置
0x00 Redis简介 Redis是一款开源的.高性能的键-值存储(key-value store).它常被称作是一款数据结构服务器(data structure server). Redis的键值 ...
随机推荐
- Address already in use: JVM_Bind,tomcat启动异常
严重: StandardServer.await: create[8050]: java.net.BindException: Address already in use: JVM_Bind tom ...
- ECMAScript 5 compatibility shims for legacy JavaScript engines
ECMAScript 5 compatibility shims for legacy JavaScript engines https://github.com/es-shims/es5-shim
- 【commons】字符串工具类——commons-lang3之StringUtils
类似工具见Hutool-StrUtil 一.起步 引入maven依赖 <!-- https://mvnrepository.com/artifact/org.apache.commons/com ...
- 成都优步uber司机第四组奖励政策
万能的优步成都团队放出了优步司机第四组,一二三组奖励已经骤降,在月末放出第四组车主档,这是要让一切归于平静的节奏么!!! 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如 ...
- [Python3.X]python 实现斐波那契数列
斐波那契数列(Fibonacci sequence),又称黄金分割数列.因数学家列昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖为例子而引入,故又称为“兔子数列”,指的是这样一 ...
- 腾讯云API弹性公网IP踩坑
由于自己管理的云服务器数量比较多,时不时需要更换IP,在管理台上一下下点击,实在浪费时间,于是就想到了通过API调用的方式,将更换IP一系列动作,全部集成到Python代码里面,实现一行命令,完成IP ...
- mysql 各种存储引擎的特点
- 41. Maximum Subarray
Description Given an array of integers, find a contiguous subarray which has the largest sum. The su ...
- redis 在java中的使用
1.首先下载jar包放到你的工程中 2.练习 package com.jianyuan.redisTest; import java.util.Iterator;import java.util.Li ...
- 深入理解eos账户体系 active和action
在eos中,账户是一个非常重要的概念. 账户分为两部分组成 一种是active 一种是action. 智能合约本质上来讲就是一个action加上一个回馈脚本程序.任何智能合约都有这俩个部分组成. 那么 ...