1. 程式人生 > 其它 >redis 6.2.5一主兩從3哨兵配置

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

  

喜歡請讚賞一下啦^_^

微信讚賞

支付寶讚賞