Redis安装配置以及开机启动

1.安装Redis
下载地址http://redis.io/download
wget http://download.redis.io/releases/redis-2.6.16.tar.gz

解压: tar xzf redis-2.6.16.tar.gz

cd redis-2.6.16

编译安装:make
make install

2、配置Redis

cp redis.conf /etc/redis.conf

vi /etc/redis.conf
修改如下内容:
daemonize yes#是否作为守护进程运行
logfile /dev/null #关闭日志
dir /var/lib/redis/

useradd redis

mkdir -p /var/lib/redis
chown redis.redis /var/lib/redis #db文件放在这里

编辑启动脚本
vi /etc/init.d/redis

内容:(从网上找的)

#!/bin/bash 
# 
# Init file for redis 
# 
# chkconfig: - 80 12 
# description: redis daemon 
# 
# processname: redis 
# config: /etc/redis.conf 
# pidfile: /var/run/redis.pid 
source /etc/init.d/functions 
#BIN="/usr/local/bin" 
BIN="/usr/local/bin" 
CONFIG="/etc/redis.conf" 
PIDFILE="/var/run/redis.pid" 
### Read configuration 
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG" 
RETVAL=0 
prog="redis-server" 
desc="Redis Server" 
start() { 
if [ -e $PIDFILE ];then 
echo "$desc already running...." 
exit 1 
fi 
echo -n $"Starting $desc: " 
daemon $BIN/$prog $CONFIG 
RETVAL=$? 
echo 
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog 
return $RETVAL 
} 
stop() { 
echo -n $"Stop $desc: " 
killproc $prog 
RETVAL=$? 
echo 
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE 
return $RETVAL 
} 
restart() { 
stop 
start 
} 
case "$1" in 
start) 
start 
;; 
stop) 
stop 
;; 
restart) 
restart 
;; 
condrestart) 
[ -e /var/lock/subsys/$prog ] && restart 
RETVAL=$? 
;; 
status) 
status $prog 
RETVAL=$? 
;; 
*) 
echo $"Usage: $0 {start|stop|restart|condrestart|status}" 
RETVAL=1 
esac 
exit $RETVAL
######

启动:/etc/init.d/redis start
检查是否启动:ps -ef|grep redis
netstat -nat

也可使用redis-cli
set test test
get test
测试
3、设置开机启动,添加到系统服务中

chmod 775 /etc/init.d/redis

开机启动redis
chkconfig redis on

Tagged . Bookmark the permalink.

2 Responses to Redis安装配置以及开机启动

  1. Joyous says:

    额外参考:http://www.cnblogs.com/viaivi/archive/2011/12/08/2281319.html

  2. Joyous says:

    ubuntu 设置开机启动脚本:sudo update-rc.d redis-server defaults
    其中redis-server在/etc/init.d/目录下