wget http://download.redis.io/releases/redis-3.2.10.tar.gz
redis_dir=`echo $1 |cut -d . -f 1-3`
cd ${redis_dir}
make PREFIX=/usr/local/redis3210 install
#创建数据目录
mkdir /usr/local/redis3210/data
cat >> /usr/local/redis3210/redis.conf << EOF
#basic
protected-mode no
port 6000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6000.pid
dbfilename dump.rdb
dir /usr/local/redis3210/data/
loglevel notice
logfile "/tmp/redis3210_6000.log"
databases 16
#save ""
save 900 100
save 300 1000
save 60 1000000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
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
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
no-appendfsync-on-rewrite no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
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
aof-rewrite-incremental-fsync yes
EOF
cat >> /etc/init.d/redis << EOF
#!/bin/bash
#
# SysV Init Information
# chkconfig: - 58 74
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
EXEC=/usr/local/redis3210/bin/redis-server
CLIEXEC=/usr/local/redis3210/bin/redis-cli
PIDFILE=/var/run/redis6000.pid
CONF="/usr/local/redis3210/redis.conf"
REDISPORT=6000
status()
{
Ping=`$CLIEXEC -p $REDISPORT ping`
if [[ $Ping == "PONG" ]]
then code="99"
else code="00"
fi
return ${code}
}
start()
{
status;
if [[ $? == "99" ]]
then echo "already started...."
exit;
fi
echo $stats
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
echo $$ > $PIDFILE
sleep 1;
status;
if [[ $? == "99" ]]
then echo "started......"
else echo "redis is not start !!!!"
fi
fi
}
stop()
{
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT save > /dev/null
$CLIEXEC -p $REDISPORT shutdown
rm ${PIDFILE} -rf
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
}
case "$1" in
start)
start;
status;
;;
stop)
stop;
;;
status)
status;
if [[ $? == "99" ]]
then echo "started......"
else echo "redis is not start !!!!"
fi
;;
save_aof)
$CLIEXEC -p $REDISPORT BGREWRITEAOF
;;
restart)
$0 stop
$0 start
;;
*)
echo "USAGE: (start, stop, restart save_aof)"
;;
esac
EOF
#开机自启
chkconfig redis on
chmod +x /etc/init.d/redis
/etc/init.d/redis start