Skip to content

Instantly share code, notes, and snippets.

@KyleGobel
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyleGobel/ff3bf796a8a4b08852cd to your computer and use it in GitHub Desktop.
Save KyleGobel/ff3bf796a8a4b08852cd to your computer and use it in GitHub Desktop.
Redis Setup

###Instructions

####Setup Sentinel

  1. Copy the sentinel.conf file to /etc/redis/sentinel.conf
  2. Copy the redis-sentinel.sh script to /etc/init.d/redis-sentinel
  3. Give the script execute permissions sudo chmod +x /etc/init.d/redis-sentinel
  4. Start script at boot time sudo update-rc.d redis-sentinel defaults
  5. Copy sentinel to /usr/local/bin/ if you haven't yet
  6. Start sentinel sudo /etc/init.d/redis-sentinel start

some other stuff

copy sentinel file to /etc/redis/sentinel.conf.orig, and then create a copy of that file at /etc/redis/sentinel.conf, sentinel will modify that file when it detects slaves and/or other sentinels, having your original file is handy as you can just replace the one that sentinel modified when you screw things up.

create a redis user and gorup useradd -G redis redis

give the redis user ownership to sentinel.conf (so it can edit it)

sudo chown redis:redis /etc/redis/sentinel.conf

create the log directory for sentinel

sudo mkdir /var/log/redis/ sudo chown redis:redis /var/log/redis/

#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-sentinel
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-sentinel - Persistent key-value db
# Description: redis-sentinel - Persistent key-value db
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/redis-sentinel
DAEMON_ARGS=/etc/redis/sentinel.conf
NAME=redis-sentinel
DESC=redis-sentinel
RUNDIR=/var/run/redis
PIDFILE=$RUNDIR/redis-sentinel.pid
test -x $DAEMON || exit 0
if [ -r /etc/default/$NAME ]
then
. /etc/default/$NAME
fi
. /lib/lsb/init-functions
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
mkdir -p $RUNDIR
touch $PIDFILE
chown redis:redis $RUNDIR $PIDFILE
chmod 755 $RUNDIR
if [ -n "$ULIMIT" ]
then
ulimit -n $ULIMIT
fi
if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS
then
echo "$NAME."
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DESC: "
if start-stop-daemon --stop --retry forever/TERM/1 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
then
echo "$NAME."
else
echo "failed"
fi
rm -f $PIDFILE
sleep 1
;;
restart|force-reload)
${0} stop
${0} start
;;
status)
echo -n "$DESC is "
if start-stop-daemon --stop --quiet --signal 0 --name ${NAME} --pidfile ${PIDFILE}
then
echo "running"
else
echo "not running"
exit 1
fi
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
## /etc/redis/sentinel.conf
## Sentinel needs a majority vote to promote a slave to master (at least 2)
## installed on each of the redis nodes (2 currently)
## if the master node goes completely offline (that node's sentinel also offline)
## there isn't 2 sentinels left to promote the online one to master, so we have another
## instance in the cluster running just sentinel (3 total)
port 26379
daemonize yes
pidfile /var/run/redis/redis-sentinel.pid
loglevel notice
logfile /var/log/redis/redis-sentinel.log
#master setup
##
sentinel monitor redis01 10.81.6.18 6379 2
sentinel down-after-milliseconds redis01 5000
sentinel failover-timeout redis01 900000
sentinel parallel-syncs redis01 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment