• 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,从机立刻能获得主机同步过来的数据,这样实现了主从的数据同步.

  • 相关阅读:
    用java实现输出英文小说飘中出现次数最多的前N个单词(附:使用文件读写)
    程序员修炼之道第一章读后感
    c++实现线性表中的顺序表(数据结构课程作业)
    java第二次课件课后动手动脑习题整理总结(2019年9月23号)
    课堂练习判断字符串是否为回文序列
    大二上学期九月周总结报告三
    以java实现的一个简单登录界面(带验证码)
    关于二进制的原码 、反码、补码的简要解释说明
    几种方式使用
    spring配置数据源的6种方式
  • 原文地址:https://www.cnblogs.com/lizzie-xhu/p/5486570.html
Copyright © 2020-2023  润新知