zoukankan      html  css  js  c++  java
  • Redis主从环境配置

    1.Redis主从同步原理

    redis主服务器会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,然后将数据文件同步给从服务器,从服务器加载记录文件,在内存库中更新新数据.

    2.VMWare配置2台服务器

    在已安装好redis服务的虚拟机,重命名为Redis-Master(主机),另外克隆一个虚拟机,重命名Redis-Slave(从机)

    查看IP:192.168.74.128;

    查看IP跟主机同一网段192.168.74.129;

    打开PuTTY(session1),连接主机,(session2),连接从机.

    session1启动主机的Redis服务,我们可以看到现在库里没有任何key;

    主机不用怎么设置,session2从机打开redis.conf文件设置如下:

    # 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.74.128 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 123456
    

    启动session2启动从机Redis服务,并用客户端连接,同样数据库为空.

    此时,session1中主机增加一个key,切换到session2,从机立刻能获得主机同步过来的数据,这样实现了主从的数据同步.

  • 相关阅读:
    二叉树进阶之寻找一棵二叉树中的最大二叉搜索子树
    二叉树进阶之求一棵二叉树中结点间最大距离
    软件工程各阶段的UML图
    软件工程各阶段的开发文档
    二叉树应用进阶之折纸(二叉树的右根左遍历)
    二叉树进阶应用之查找结点的后继结点
    二叉树进阶之满二叉树和完全二叉树
    二叉树进阶之搜索二叉树的判断与找出搜索二叉树中出错的结点
    二叉树进阶之平衡二叉树的判断
    二叉树基础之序列化和反序列化二叉树
  • 原文地址:https://www.cnblogs.com/lizzie-xhu/p/5486570.html
Copyright © 2011-2022 走看看