创建配置文件

vim /etc/redis/6381.conf

port 6381
pidfile "/var/run/redis/6381.pid"
logfile "/opt/log/redis_6381.log"
dir "/opt/lib/redis/6381"

masterauth "mypassword"
requirepass "mypassword"

bind 0.0.0.0
protected-mode yes
tcp-backlog 511
timeout 3600
tcp-keepalive 300
daemonize yes
supervised no
loglevel notice
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
# maxclients 10000
# maxmemory <bytes>
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10

创建必要目录

mkdir -p /opt/lib/redis/6381
chown redis:redis /opt/lib/redis/6381

创建 init.d 文件

#!/bin/sh
#Configurations injected by install_server below....

EXEC=/opt/redis/bin/redis-server
CLIEXEC=/opt/redis/bin/redis-cli
PIDFILE=/var/run/redis/6381.pid
CONF="/etc/redis/6381.conf"
REDISPORT="6381"
PASSWORD="mypassword"
###############
# SysV Init Information
# chkconfig: - 58 74
# description: redis_6381 is the redis daemon.
### BEGIN INIT INFO
# Provides: redis_6381
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: start and stop redis_6381
# Description: Redis daemon
### END INIT INFO


case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
            echo "$PIDFILE exists, process is already running or crashed"
        else
            echo "Starting Redis server..."
            su -s /bin/bash -c "$EXEC $CONF" redis
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
            echo "$PIDFILE does not exist, process is not running"
        else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $CLIEXEC -a $PASSWORD -p $REDISPORT shutdown
            while [ -x /proc/${PID} ]
            do
                echo "Waiting for Redis to shutdown ..."
                sleep 1
            done
            echo "Redis stopped"
        fi
        ;;
    status)
        PID=$(cat $PIDFILE)
        if [ ! -x /proc/${PID} ]
        then
            echo 'Redis is not running'
        else
            echo "Redis is running ($PID)"
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Please use start, stop, restart or status as first argument"
        ;;
esac

修复权限。

chmod +x /etc/init.d/redis_6381

配置 sentinel

每个 sentinel 的配置文件中都需要添加。

sentinel monitor redis6381 10.0.78.78 6381 2
sentinel down-after-milliseconds redis6381 10000
sentinel failover-timeout redis6381 60000
sentinel auth-pass redis6381 mypassword
sentinel config-epoch redis6381 0
sentinel leader-epoch redis6381 0
sentinel known-slave redis6381 10.0.78.79 6381
sentinel known-slave redis6381 10.0.78.77 6381