1.redis.conf
a.daemonize yes
b.pidfile /var/run/xxx.pid
2./etc/init.d/redis
//加了下面三个注释部分,才支持设置开机自启动
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
###########################
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server //redis-server所在目录
REDIS_CLI=/usr/local/bin/redis-cli //redis-cli所在目录
PIDFILE=/var/run/redis_6379.pid //redis.conf中间定义的pidfile
CONF="/software/redis-stable/redis.conf" //redis.conf所在目录
case "$1" in
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 ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
##############################
下载
- wget http://redis.googlecode.com/files/redis-2.2.13.tar.gz
- tar -zxf redis-2.2.13.tar.gz
- cd redis-2.2.13
- make
- sudo make install
- cp redis.conf /etc
新建用户。数据和日志文件夹
- sudo useradd redis
- sudo mkdir -p /var/lib/redis
- sudo mkdir -p /var/log/redis
- sudo chown redis.redis /var/lib/redis #db文件放在这里,要修改redis.conf
- sudo chown redis.redis /var/log/redis
脚本设置
见上面
设置权限
chmod +x /etc/init.d/redis
设置自动启动:
- sudo chkconfig redis on
启动或者关闭服务
- service redis start #或者 /etc/init.d/redis start
- service redis stop #或者 /etc/init.d/redis stop
测试是否成功
1。reboot
2. redis-cli
3.get xxxx