• Centos7安装Redis6.2.7-sentinel高可用步骤


    Redis-sentinel高可用安装步骤

    1、前置准备

    1、服务器

    需要准备三台Centos7的服务器

    三台服务器都已经配置好静态IP。

    没有配的可以参考:https://blog.csdn.net/qq_37481017/article/details/118732932

    主机名IPRedis版本主从节点
    server1192.168.3.1916.2.7master
    server2192.168.3.1926.2.7slave
    server3192.168.3.1936.2.7slave

    2、环境准备

    以下所有操作需要在所有机器上执行、操作用户是root

    1、下载依赖

    Redis6.x以上需要gcc版本大于5.3以上

    yum -y install centos-release-scl devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable devtoolset-9 bash
    # 设置长期使用gcc9
    echo -e "\nsource /opt/rh/devtoolset-9/enable" >>/etc/profile
    
    • 1
    • 2
    • 3

    2、关闭防火墙

    # 查看防火墙状态
    firewall-cmd --state
    # 临时停止防火墙
    systemctl stop firewalld.service
    # 禁止防火墙开机启动
    systemctl disable firewalld.service
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    3、创建安装包目录

    mkdir -p /app/software 
    
    • 1

    2、安装Redis

    以下操作需要在所有机器上执行

    1、解压安装包

    tar -zxvf redis-6.2.7.tar.gz
    
    • 1

    2、安装

    cd redis-6.2.7
    
    make && make test
    # 安装到/app/redis-6.2.7
    make install PREFIX=/app/redis-6.2.7
    
    mkdir /app/redis-6.2.7/conf && mkdir /app/redis-6.2.7/logs && cp /app/software/redis-6.2.7/redis.conf /app/redis-6.2.7/conf/ && mkdir /app/redis-6.2.7/data
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    3、修改配置文件

    vim /app/redis-6.2.7/conf/redis.conf
    
    # 修改以下配置
    bind 192.168.3.191
    daemonize yes
    pidfile /app/redis-6.2.7/redis_6379.pid
    logfile "/app/redis-6.2.7/logs/redis.log"
    dir /app/redis-6.2.7/data/
    requirepass 123456
    masterauth 123456
    
    # 只需要在两台slave机器最后面加上以下配置
    replicaof 192.168.3.191 6379
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    3、配置Sentinel

    以下操作需要在所有机器上执行

    1、复制配置文件

    cp /app/software/redis-6.2.7/sentinel.conf /app/redis-6.2.7/conf/
    
    • 1

    2、修改配置文件

    vim /app/redis-6.2.7/conf/sentinel.conf
    
    # 修改以下配置
    daemonize yes
    pidfile /app/redis-6.2.7/redis-sentinel.pid
    logfile "/app/redis-6.2.7/logs/sentinel.log"
    dir /app/redis-6.2.7/data/
    sentinel monitor mymaster 192.168.3.191 6379 2
    sentinel down-after-milliseconds mymaster 30000
    sentinel failover-timeout mymaster 180000
    sentinel auth-pass mymaster 123456
    requirepass "123456"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    3、配置自定义服务

    vim /usr/lib/systemd/system/redis.service
    
    # Redis的Systemd自定义服务配置
    [Unit]
    Description=Redis
    After=syslog.target network.target
    
    [Service]
    Type=forking
    User=root
    Group=root
    PIDFile=/app/redis-6.2.7/redis_6379.pid
    ExecStart=/app/redis-6.2.7/bin/redis-server /app/redis-6.2.7/conf/redis.conf
    
    [Install]
    WantedBy=multi-user.target
    
    
    vim /usr/lib/systemd/system/redis-sentinel.service
    
    # Redis-sentinel的Systemd自定义服务配置
    [Unit]
    Description=Redis-Sentinel
    After=syslog.target network.target redis.service
    
    [Service]
    Type=forking
    User=root
    Group=root
    PIDFile=/app/redis-6.2.7/redis-sentinel.pid
    ExecStart=/app/redis-6.2.7/bin/redis-sentinel /app/redis-6.2.7/conf/sentinel.conf
    
    [Install]
    WantedBy=multi-user.target
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    4、启动

    # 启动redis服务
    systemctl start redis
    # 设置开机自启
    systemctl enable redis
    # 启动redis-sentinel服务
    systemctl start redis-sentinel
    systemctl enable redis-sentinel
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  • 相关阅读:
    Linux安装Jenkins详细步骤
    Haproxy搭建 Web 群集实现负载均衡
    过滤器---普通过滤器使用、串联过滤器、局部与全局过滤器
    【每日一题】最短无序连续子数组
    python项目上线
    设计模式(二)创建模式
    差分隐私(Differential Privacy)定义及其理解
    全链路压测效能10倍提升的压测工具实践笔记【开源】【原创】
    5 个适用于 Windows 10 和 11 的最佳 PDF 转 Word 转换器
    基于FPGA的分形编码器verilog设计——详细版
  • 原文地址:https://blog.csdn.net/qq_37481017/article/details/125559290