• redis主从切换


    转自:http://blog.csdn.net/zfl092005/article/details/17523945

    环境描述:
    主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 

    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

  • 相关阅读:
    http://ftp.netfilter.org/pub/iptables/
    安装iptables layer 7 模块
    在Debian etch上 为内核添加netfilterlayer7v2 ,ipp2p0.8.2模块
    解决虚拟机安装 Linux 移植到别处网卡起不来的问题
    在Debian 4.0rc3上编译内核2.6.24时加入Layer7模块笔记[防火墙中在TCP/IP第七层Layer7应用层阻挡QQ,MSN等软件的应用]
    Debian 4
    實作 Layer 7 封包過濾
    DevExpress cxSpreadSheet 自动换行时中文乱码问题的解决【转】
    ABC控件在Delphi7中的安装方法【转】
    取出SQL SERVER字段中的数字
  • 原文地址:https://www.cnblogs.com/half-two-feet/p/7574044.html
Copyright © 2020-2023  润新知