• linux安装redis哨兵


    安装环境

    服务器一台:

    • 服务器IP:172.169.3.251
    • 主从端口:6379、6380、6381
    • 哨兵端口,26379、26380、26381
    • 安装目录:/usr/local/redis
    • 配置文件目录:/usr/loca/redis/conf

    redis安装

    1、下载redis

    wget https://download.redis.io/releases/redis-6.2.7.tar.gz
    
    • 1

    2、解压redis

    tar -zxvf redis-6.2.7.tar.gz
    mv redis-6.2.7 /usr/local/redis
    
    • 1
    • 2

    3、编译、安装

    cd /usr/local/redis
    make
    make install PREFIX=/usr/local/redis
    
    • 1
    • 2
    • 3

    配置主从、哨兵

    在目录 /usr/loca/redis/conf 下创建以下文件

    1. redis1.conf
    2. redis2.conf
    3. redis3.conf
    4. sentinel1.conf
    5. sentinel2.conf
    6. sentinel3.conf

    redis1.conf

    bind 0.0.0.0
    port 6379
    daemonize yes
    protected-mode no
    slave-read-only no
    masterauth 1234
    requirepass 1234
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    redis2.conf

    replicaof 改为 redis1的ip和端口

    bind 0.0.0.0
    port 6380
    daemonize yes
    protected-mode no
    slave-read-only no
    masterauth 1234
    requirepass 1234
    replicaof 172.169.3.251 6379
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    redis3.conf

    replicaof 改为 redis1的ip和端口

    bind 0.0.0.0
    port 6381
    daemonize yes
    protected-mode no
    slave-read-only no
    masterauth 1234
    requirepass 1234
    replicaof 172.169.3.251 6379
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    sentinel1.conf

    myaster 后面 ip和端口 改为redis1的ip和端口

    port 26379
    dir /tmp
    protected-mode no
    daemonize yes
    sentinel monitor mymaster 172.169.3.251 6379 2
    sentinel auth-pass mymaster 1234
    sentinel down-after-milliseconds mymaster 30000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 10000
    sentinel deny-scripts-reconfig yes
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    sentinel2.conf

    myaster 后面 ip和端口 改为redis1的ip和端口

    port 26380
    dir /tmp
    protected-mode no
    daemonize yes
    sentinel monitor mymaster 172.169.3.251 6379 2
    sentinel auth-pass mymaster 1234
    sentinel down-after-milliseconds mymaster 30000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 10000
    sentinel deny-scripts-reconfig yes
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    sentinel3.conf

    myaster 后面 ip和端口 改为redis1的ip和端口

    port 26381
    dir /tmp
    protected-mode no
    daemonize yes
    sentinel monitor mymaster 172.169.3.251 6379 2
    sentinel auth-pass mymaster 1234
    sentinel down-after-milliseconds mymaster 30000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 10000
    sentinel deny-scripts-reconfig yes
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    启动服务

    start_all.sh

    #bin/bash
    REDIS_HOME=/usr/local/redis
    CONFIG_HOME=/usr/loca/redis/conf
    $REDIS_HOME/bin/redis-server $CONFIG_HOME/conf/redis1.conf &
    sleep 1s
    $REDIS_HOME/bin/redis-server $CONFIG_HOME/conf/redis2.conf &
    sleep 1s
    $REDIS_HOME/bin/redis-server $CONFIG_HOME/conf/redis3.conf &
    sleep 1s
    $REDIS_HOME/bin/redis-server $CONFIG_HOME/conf/sentinel1.conf --sentinel &
    sleep 1s
    $REDIS_HOME/bin/redis-server $CONFIG_HOME/conf/sentinel2.conf --sentinel &
    sleep 1s
    $REDIS_HOME/bin/redis-server $CONFIG_HOME/conf/sentinel3.conf --sentinel &
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    chmod 777 start_all.sh
    ./start_all.sh 
    
    • 1
    • 2

    查看服务

    ps -ef|grep redis
    
    • 1

    在这里插入图片描述

    查看集群状态

    ./redis-cli -p 6379 -a 1234
    info replication
    
    • 1
    • 2

    在这里插入图片描述

    应用配置

    # 哨兵的IP和端口
    spring.redis.sentinel.nodes=172.169.3.186:26379,172.169.3.186:26380,172.169.3.186:26381
    # sentinel monitor mymaster 172.169.3.251 6379 2 与 这里的 mymaster 一致
    spring.redis.sentinel.master=mymaster
    # 哨兵是否需要密码,如果未配置,则不需要
    spring.redis.sentinel.password=
    # redis主从的密码,配置的为1234,故需要配置
    spring.redis.password=1234
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    Tutorial: Sending an Email using Python
    牛客小白月赛60-D-游戏购买!
    《流畅的python》阅读笔记 - 第一章:python数据模型
    天星金融消保课堂开讲,金融健康意识再提升
    风控(策略)岗中的模型知识须知
    jquery ajax跨域解决方法(json方式)
    水滴低代码搭建——6倍提效,新品首发素材审核系统实践之路
    03——go开发工具
    Python中print函数的八重境界
    PG14启动报错“max_stack_depth“ must not exceed 7680kB
  • 原文地址:https://blog.csdn.net/qq_17522211/article/details/128188389