redis主从配置及主从切换 转自 http://blog.sina.com.cn/s/blog_67196ddc0101h8v0.html

(2014-04-28 17:48:47)

  分类: java

环境描述:

主redis:192.168.10.1 6379

从redis:192.168.10.2 6380

一、主从配置

1、将主从redis配置文件redis.conf中的aemonize no 改为 yes

2、修改从redis配置文件redis.conf中的port 6379 改为 6380,添加slaveof 192.168.10.1 6379

如果主redis有密码 masterauth password

3、启动主从服务

主redis:

[root@localhost redis-2.8.3]# src/redis-server /soft/redis-2.8.3-master/redis-2.8.3/redis.conf

从redis:

[root@localhost redis-2.8.3]# src/redis-server /soft/redis-2.8.3-slave/redis-2.8.3/redis.conf

4、测试数据同步

主redis:

[root@localhost redis-2.8.3]# src/redis-cli -p 6379

127.0.0.1:6379> set name abc

OK

127.0.0.1:6379> get name

"abc"

127.0.0.1:6379>

从redis:

[root@localhost redis-2.8.3]# src/redis-cli -p 6380

127.0.0.1:6380> get name

"abc"

127.0.0.1:6380>

5、默认是读写分离的

在从redis:

[root@localhost redis-2.8.3]# src/redis-cli -p 6380

127.0.0.1:6380> set name 123

(error) READONLY You can't write against a read only slave.

二、主从切换

1、停止主redis

[root@localhost redis-2.8.3]# src/redis-cli -n 6379 shutdown

[root@localhost redis-2.8.3]# src/redis-cli -p 6379

Could not connect to Redis at 127.0.0.1:6379: Connection refused

not connected>

2、将从redis设成主redis

[root@localhost redis-2.8.3]# src/redis-cli -p 6380 slaveof NO ONE

OK

3、测试从redis是否切换从主redis

[root@localhost redis-2.8.3]# src/redis-cli -p 6380

127.0.0.1:6380> set name 123

OK

127.0.0.1:6380> get name

"123"

127.0.0.1:6380>

4、原来的主redis恢复正常了,要重新切换回去

1)将现在的主redis的数据进行保存

[root@localhost redis-2.8.3]# src/redis-cli -p 6380

127.0.0.1:6380> get name

"abc"

127.0.0.1:6380> set name 123

OK

127.0.0.1:6380> get name

"123"

127.0.0.1:6380> save

OK

127.0.0.1:6380> get name

"123"

127.0.0.1:6380>

2)将现在的主redis根目录下dump.rdb文件拷贝覆盖到原来主redis的根目录

3)启动原来的主redis

[root@localhost redis-2.8.3]# src/redis-server /soft/redis-2.8.3-master/redis-2.8.3/redis.conf

4)在现在的主redis中切换

[root@localhost redis-2.8.3]# src/redis-cli -p 6380 slaveof 192.168.10.1 6379

OK

redis主从配置及主从切换 转的更多相关文章

  1. redis主从配置及主从切换

    环境描述: 主redis:192.168.10.1 6379从redis:192.168.10.2 6380 一.主从配置 1.将主从redis配置文件redis.conf中的aemonize no ...

  2. [转]redis主从配置及主从切换

    http://blog.csdn.net/zfl092005/article/details/17523945 环境描述: 主Redis:192.168.10.1 6379 从redis:192.16 ...

  3. mysql传统主从配置与主从监控

    主从简介 在现代企业中,数据显得尤为重要,而存储数据的数据库选择又五花八门,但无论是何种数据库,均存在着一种隐患. 当数据规模非常大,读写量也很高时,一台数据库已经无法负担全部读写任务,就需要多台数据 ...

  4. redis 主从配置,主从切换

    只需修改从配置文件 # slaveof <masterip> <masterport> slaveof 127.0.0.1 6379 # masterauth <mast ...

  5. Nginx+Keepalived主从配置(双机主从热备)+Tomcat集群

    拓扑环境 以下表格是这次測试须要的拓扑环境,几台server.每台server上安装什么,都有介绍. server名称 系统版本号 预装软件 IP地址/VIP Nginx主server CentOS ...

  6. Redis学习总结(四)--Redis主从配置

    在分布式系统架构设计中高可用是必须考虑的因素之一.高可用通常是指,通过设计减少系统不能提供服务的时间.而单点是系统高可用的最大的败笔,如果单点出现问题的话,那么整个服务就不能使用了,所以应该尽量在系统 ...

  7. Redis 主从配置密码以及哨兵

    目录: Redis 主从介绍 哨兵机制 Redis 主从配置 环境 安装 启动服务 检查主从状态 测试数据同步 默认是读写分离的 Redis Sentinel 配置 主Redis宕机测试 配置多个哨兵 ...

  8. linux中MySQL主从配置(Django实现主从读写分离)

    一 linux中MySQL主从配置原理(主从分离,主从同步) mysql主从配置的流程大体如图: 1)master会将变动记录到二进制日志里面: 2)master有一个I/O线程将二进制日志发送到sl ...

  9. redis 非集群的主从配置及切换

    单纯的master-slave不能称之为集群,只能叫做读写分离.此案例只针对master为单点服务,且程序端写死master为可写,slave为只读.若master宕机则不可用,若主从未开启持久化,不 ...

随机推荐

  1. js实现图片预显示

    html页面代码 <div id="localImag" style="display:none"><img  id="previe ...

  2. mysql主从同步mysql slave_io_running:no的解决方案

    在主从同步的时候出现slave_io_running:no 问题,于是查看mysqld.log日志,发现时1042错误 解决方案: 编辑/etc/my.cnf,在:[mysqld]内添加一行:skip ...

  3. HDU 4848

    http://acm.hdu.edu.cn/showproblem.php?pid=4848 题意:求遍历所有点的最小值(这个答案是加i点到起始点的距离,不是当前点到i的距离),必须在ti[i]前到达 ...

  4. wcf之OperationContextScope

    作用:使用消息头向服务发送额外的信息. 1.客户端代码如下: namespace Client { class Program { static void Main(string[] args) { ...

  5. M1: 创建UWP空项目

    本小节介绍如何在Visual Studio中创建一个UWP项目,Visual Studio中提供了快速创建各种项目的类型模板.在Visual Studio 2015中,同样提供了UWP项目模板. 学完 ...

  6. @Html.DropDownListFor 绑定列表项

    MVC中为 DropDownListFor 绑定列表项, 一种方案从后台加载列表内容,通过ViewData传递到前台页面. View: <div class="editor-label ...

  7. 批量kill相关所有进程

    首先,用ps查看进程,方法如下: $ ps -ef …… smx       1822     1  0 11:38 ?        00:00:49 gnome-terminal smx      ...

  8. php部分---人员表和民族表的显示、修改、删除

    1.连接数据库 进行网页的显示 <table width="100%" border="1" cellpadding="0" cell ...

  9. LB负载均衡集群及NAT模式配置

    一.LB(load balance)负载均衡集群 负载均衡集群常用的有: 1.软件实现的 nginx(工作在OSI第七层应用层) lvs+keepalived(工作在OSI第四层传输层) 2.硬件实现 ...

  10. Codeforces Round #117 (Div. 2)

    Codeforces Round #117 (Div. 2) 代码 Codeforces Round #117 (Div. 2) A. Battlefield any trench in meters ...