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

  • 相关阅读:
    网络基础知识-TCP/IP协议各层详解
    MySQL及其图形界面navicat的安装
    Python 浅谈编程规范和软件开发目录规范的重要性
    python 浅析模块,包及其相关用法
    spring batch中MyBatisPagingItemReader分页使用介绍
    eclipse中git插件使用
    oracle中查找某用户执行某张表的操作操作记录
    redis集群主流架构方案分析
    消息队列常见的 5 个应用场景
    Kafka vs RocketMQ——单机系统可靠性
  • 原文地址:https://www.cnblogs.com/lizzie-xhu/p/5486570.html
Copyright © 2011-2022 走看看