Skip to content

Instantly share code, notes, and snippets.

@hex108
Created November 27, 2014 03:46
Show Gist options
  • Save hex108/9fdabe1f10faff8bccde to your computer and use it in GitHub Desktop.
Save hex108/9fdabe1f10faff8bccde to your computer and use it in GitHub Desktop.
Config redis automatically. The configure method is from http://redis.io/topics/quickstart.
#!/bin/bash
set -u
set -e
if [ $# -ne 2 ]; then
echo "Usage : $0 redis_src_directory port"
echo " e.g. $0 /home/test/redis-stable 6379"
exit -1
fi
REDIS_SRC=$1
PORT=$2
echo "Config redis now."
echo "Redis src is : $REDIS_SRC , port : $PORT"
mkdir /etc/redis
mkdir /var/redis
cp $REDIS_SRC/utils/redis_init_script /etc/init.d/redis_$PORT
sed -i "s/REDISPORT=6379/REDISPORT=$PORT/" /etc/init.d/redis_$PORT
CONF=/etc/redis/$PORT.conf
cp $REDIS_SRC/redis.conf $CONF
mkdir /var/redis/$PORT
# modify configuration
sed -i "s/daemonize no/daemonize yes/" $CONF
sed -i "s/pidfile \/var\/run\/redis.pid/pidfile \/var\/run\/redis_$PORT.pid/" $CONF
sed -i "s/port 6379/port $PORT/" $CONF
sed -i "s/logfile \"\"/logfile \/var\/log\/redis_$PORT.log/" $CONF
sed -i "s/dir \.\//dir \/var\/redis\/$PORT/" $CONF
echo "Done. Successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment