redis 6.2.5一主两从3哨兵配置

一、下载redis

## download
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
tar -xzvf  redis-6.2.5.tar.gz  -C /usr/local cd /usr/local 
mv redis-4.0.11 redis 
cd redis 
make
make PREFIX=/usr/local/redis installenv path 
在/etc/profile文件尾部增加redis环境变量,并执行 export REDIS_HOME=/usr/local/redis export PATH=$PATH:$REDIS_HOME/src 最后执行source /etc/profile使之生效

 

  

二、配置

master.conf 主库

masterauth mypwd
requirepass mypwd
protected-mode yes
bind 192.168.5.116 #局域网ip或者外网ip
daemonize yes
logfile /codeyuguo/redis/redis.log
appendonly yes
dir /codeyuguo/redis

 

sentinel.conf 哨兵配置

sentinel monitor mymaster 192.168.5.116 6379 1
sentinel auth-pass mymaster mypwd
sentinel down-after-milliseconds mymaster 15000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 80000
bind 192.168.5.116
protected-mode yes
daemonize yes
logfile /codeyuguo/redis/sentinel.log
appendonly yes
dir /codeyuguo/redis

 

slave.conf 从库配置

masterauth mypwd
requirepass mypwd
protected-mode yes
bind 192.168.6.49
slaveof 192.168.5.116 6379
daemonize yes
logfile /codeyuguo/redis/redis.log

 



三、注意事项

  1. 在创建目录/codeyuguo/redis/conf,并在conf文件夹下创建上述maser.conf/slave.conf/sentinel.conf三个配置文件
  2. 总共3台节点,一个节点上配置主库和哨兵,其他两个节点上配置从库和哨兵
    1. 配置主库 执行 redis-server /codeyuguo/redis/conf/master.conf
    2. 配置从库执行 redis-server /codeyuguo/redis/conf/slave.conf
    3. 配置哨兵 执行 redis-sentinel /codeyuguo/redis/conf/sentinel.conf

四、附录

4. 1 redis启动脚本

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
source /etc/init.d/functions
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
 
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/alidata/redis-6.2.5/redis.conf"
AUTH="Jh****"             
BIND_IP='192.168.5.116'
 
start(){
     
    if [ -f $PIDFILE ]
    then
        echo "$PIDFILE exists, process is already running or crashed"
    else
        echo "Starting Redis server..."
        $EXEC $CONF
    fi
    if [ "$?"="0" ]  
    then  
        echo "Redis is running..." 
    fi  
 
 
}
 
stop(){
 
    if [ ! -f $PIDFILE ]
    then
        echo "$PIDFILE does not exist, process is not running"
    else
        PID=$(cat $PIDFILE)
        echo "Stopping ..."
        $CLIEXEC -h $BIND_IP -a $AUTH -p $REDISPORT  SHUTDOWN 2>/dev/null
        sleep 1
        while [ -x /proc/${PID} ]
        do
            echo "Waiting for Redis to shutdown ..."
            sleep 1
        done
            echo "Redis stopped"
    fi
}
 
restart(){
    stop
    start
 
}
status(){
 
    ps -ef|grep redis-server|grep -v grep >/dev/null 2>&1
 
    if [ $? -eq 0 ];then
 
        echo "redis server is running"
 
    else
        echo "redis server is stopped"
 
    fi
     
 
}
 
 
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
         
    restart)
        restart
        ;;
         
    status)
        status
        ;;     
    *)
     
     echo "Usage: /etc/init.d/redis {start|stop|status|start}" >&2 
     exit 1 
esac

  

 

posted @ 2021-08-27 15:06  雪竹子  阅读(448)  评论(0编辑  收藏  举报