阿里云服务器搭建redis主从遇到的坑

如题,在两台服务器之间搭建主从redis:

  1. 登录阿里云控制台把redis的端口开放。
  2. 如果是宝塔面板在安全栏目里放行redis的端口。
  3. 主服务器的redis.conf
    bind 127.0.0.1 //注释掉不用
    protected-mode no //关闭保护模式

     

  4. 从服务器的redis.conf配置同上,redis的主从可以在配置文件中修改,具体位置如下
    ################################# REPLICATION #################################
    
    # Master-Replica replication. Use replicaof to make a Redis instance a copy of
    # another Redis server. A few things to understand ASAP about Redis replication.
    #
    #   +------------------+      +---------------+
    #   |      Master      | ---> |    Replica    |
    #   | (receive writes) |      |  (exact copy) |
    #   +------------------+      +---------------+
    #
    # 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 replicas.
    # 2) Redis replicas 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 replicas automatically try to reconnect to masters
    #    and resynchronize with them.
    #
    # replicaof <masterip> <masterport> 
    #在这里写入主服务器的ip 端口 例如
    replicaof 192.168.1.103 6379
    
    //如果redis有密码 密码是123456
    masterauth 123456 
    
    //登录账户 user
    masteruser user

     

网上的视频教程里都是同一服务器开三个不同端口的redis,在同一服务器搭建主从没有什么问题,但是当真正在两台服务器之间搭建的时候就会出现问题,输入info replication 会出现master_link_status:down。主服务器查看从服务器的连接数也是0。connected_slaves:0;

另外,我的服务器系统:CentOS 7.6.1810,装的宝塔面板,然后首次安装redis的时候会报错,原因是gcc的版本过低,网上查找原因提示 升级gcc,命令如下

yum -y install centos-release-scl
 
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
 
scl enable devtoolset-9 bash
 
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
 
gcc -v

 

上一篇:Mysql8.0.22主备GTID Replication中的那些坑


下一篇:mysql双主双从