• redis安装及主从、哨兵配置


    redis安装

    1. 安装前提
      redis6版本要求gcc版本大于等于5.0,因此先查看当前的gcc版本
      gcc -v
      如果版本小于5.0,需要安装新版本的gcc, 参考《gcc升级到高版本》

    2. 解压源码包
      tar -zxvf /home/redis-6.0.8.tar.gz
      cd /home/redis-6.0.8
      make
      cd src
      make install PREFIX=/usr/local/redis

    3. 修改配置文件
      cd /usr/local/redis
      mkdir /usr/local/redis/etc
      mkdir /usr/local/redis/logs
      cp /home/redis-6.0.8/redis.conf /usr/local/redis/etc
      修改 /usr/local/redis/etc/redis.conf文件,

      bind 127.0.0.1改为bind 0.0.0.0
      daemonize no 改为daemonize yes,
      logfile “” 改为logfile “/usr/local/redis/logs/log_redis.log”
      requirepass foobared 前的#号去掉,改为requirepass 111111

    4. 配置从服务器slave1
      cd /usr/local/redis/etc
      cp redis.conf redis_slave1.conf
      修改rdis_slave1.conf文件:
      port 6389
      pidfile /var/run/redis_6389.pid
      logfile “/usr/local/redis/logs/log_redis_slaveof6389.log”
      masterauth 前的#号去掉,改为masterauth 111111
      文件尾增加一行,来设置主服务器的ip和端口
      replicaof 192.168.1.191 6379

    5. 配置从服务器slave2
      cd /usr/local/redis/etc
      cp redis.conf redis_slave2.conf
      修改rdis_slave2.conf文件:
      port 6399
      pidfile /var/run/redis_6399.pid
      logfile “/usr/local/redis/logs/log_redis_slaveof6399.log”
      masterauth 前的#号去掉,改为masterauth 111111
      文件尾增加一行,来设置主服务器的ip和端口
      replicaof 192.168.1.191 6379

    6. 配置主哨兵服务
      cp /home/redis-6.0.8/sentinel.conf /usr/local/redis/etc/
      修改sentinel.conf文件
      daemonize yes 后台启动
      logfile “/usr/local/redis/logs/log_sentinel.log”
      sentinel monitor mymaster 127.0.0.1 6379 2 改为 sentinel monitor mymaster 192.168.1.191 6379 2
      设置监控的主节点,2是一个阈值,代表有两台或两台以上哨兵判断主节点redis不通的话就认定这个节点有问题,实行故障转移。
      sentinel auth-pass mymaster 111111

    7. 配置另外两个哨兵服务
      cd /usr/local/redis/etc
      cp sentinel.conf sentinel26389.conf
      cp sentinel.conf sentinel26399.conf
      修改sentinel26389.conf文件,将port改为26389,logfile改为"/usr/local/redis/logs/redis_sentinel-26389.log"
      修改sentinel26399.conf文件,将port改为26399,logfile改为"/usr/local/redis/logs/redis_sentinel-26399.log"

    8. 启动redis主从服务与三个哨兵服务
      cd /usr/local/redis/bin
      ./redis-server …/etc/redis.conf
      ./redis-server …/etc/redis_slave1.conf
      ./redis-server …/etc/redis_slave2.conf
      ./redis-sentinel …/etc/sentinel.conf
      ./redis-sentinel …/etc/sentinel26389.conf
      ./redis-sentinel …/etc/sentinel26399.conf

    redis客户端常用操作

    1. 使用redis客户端登录
      cd /usr/local/redis/bin
      ./redis-cli -a 111111 -p 6379 #登录主服务
      或者
      ./redis-cli -p 6389 -a “111111” #登录从服务
      或者
      ./redis-cli -p 6399 -a “111111” #登录从服务

    2. 常用命令
      info replication # 查看主从关系 role:master则表明是主库
      flushdb # 清空数据
      keys * # 查看所有的key

    3. 退出
      quit

  • 相关阅读:
    R语言基础的代码语法解译笔记
    视频去水印怎么去?3个简单的去水印方法分享
    【初学者入门C语言】之二维数组(七)
    【达摩院OpenVI】开源体验AI云台,去视频抖动
    AI | 第5章 深度学习 TensorFlow2 神经网络与卷积神经网络
    【SQL解析】- SQL血缘分析实现篇01
    openresty定时任务
    基于Python实现的词汇相似度计算
    环境影响评价期末复习
    腾讯云入侵
  • 原文地址:https://blog.csdn.net/Zerore/article/details/125432717