zoukankan      html  css  js  c++  java
  • redis主从+哨兵 安装配置二

    实验环境:

      192.168.2.201 centos7 master sentinel

      192.168.2.202 centos7 slave   sentinel

      192.168.2.203 centos7 slave   sentinel

      版本:redis5.0.3

    1. 下载:

      https://redis.io/download

    2. 准备:

      yum install gcc gcc-c++ -y

    3. 解压安装:

      mkdir -p /home/data/redis/  (数据、日志目录)
      tar -zxvf redis-5.0.3.tar.gz -C /usr/local
      cd /usr/local/redis-5.0.3
      make MALLOC=libc
      make
      make install

    4. 配置 redis.conf 文件

      bind 0.0.0.0
    
      daemonize yes
    
      logfile "/home/data/redis/redis.log"
    
      dir "/home/data/redis"
    
      replicaof 192.168.2.201 6379   注:replicaof就是原来的 slaveof ,这一句只需要配置在slave节点的redis.conf里面。
      
      为了安全,aof也建议打开。

    5. 启动redis 

    依次在三个节点执行:
    [root@Node201 redis-5.0.3]# src/redis-server redis.conf

    6. 查看

    进入
    [root@Node201 redis-5.0.3]# src/redis-cli
    
    查看
    127.0.0.1:6379> info replication

     可以看到Node201为master,Node202,Node203为slave。

    7.验证数据同步

    1. 在master节点:
    127.0.0.1:6379> get test
    (nil)
    127.0.0.1:6379> set test hello
    OK
    
    2. 在slave节点查看:
    127.0.0.1:6379> get test
    "hello"

    注意:slave节点为了安全是只读不写的。

      127.0.0.1:6379> set test hi
      (error) READONLY You can't write against a read only replica.
      127.0.0.1:6379>

     8. 验证高可用

    关闭Node201的redis
    127.0.0.1:6379> shutdown

    此时Node202被选为master:

    此时再次启动Node201,Node201只能为slave了。

    9.开机启动redis

     

    1. 编辑服务文件
    vim /etc/systemd/system/redis-server.service
    
    [Unit]
    Description=The redis-server Process Manager
    After=syslog.target network.target
    
    [Service]
    Type=simple
    PIDFile=/var/run/redis_6379.pid
    ExecStart=/usr/local/redis-5.0.3/redis-server /usr/local/redis-5.0.3/redis.conf         
    ExecReload=/bin/kill -USR2 $MAINPID
    ExecStop=/bin/kill -SIGINT $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    
    2. 重新加载
    
    systemctl daemon-reloads
    systemctl start redis-server.services
    systemctl enable redis-server.service
    
    3. 创建软连接
    ln -s /usr/local/redis/redis-cli /usr/bin/redis
    

      

  • 相关阅读:
    pip install uwsgi 报错 AttributeError: module 'os' has no attribute 'uname'
    npm安装vue
    Node.js安装及环境配置之Windows篇
    Centos7 安装nodejs
    Centos7 Jenkins 插件下载速度慢、安装失败
    Centos7 使用docker 安装redis
    Centos7 安装jdk
    supervisor配置文件详解
    MySQL5.7 group by新特性,报错1055
    配置python虚拟环境Virtualenv及pyenv
  • 原文地址:https://www.cnblogs.com/ZHUJIBlogs/p/10375790.html
Copyright © 2011-2022 走看看