首页 > 代码库 > Redis安装配置以及开机启动

Redis安装配置以及开机启动

1.下载源码,解压缩后编译源码。                                                                     

$ wget http://download.redis.io/releases/redis-2.8.3.tar.gz$ tar xzf redis-2.8.3.tar.gz$ cd redis-2.8.3$ make

 

2.编译完成后,在Src目录下,有四个可执行文件redis-server、redis-benchmark、redis-cli和redis.conf。然后拷贝到一个目录下

mkdir /usr/rediscp redis-server  /usr/rediscp redis-benchmark /usr/rediscp redis-cli  /usr/rediscp redis.conf  /usr/rediscd /usr/redis

3.配置

vi /etc/redis.conf修改如下内容:daemonize yes#是否作为守护进程运行logfile /dev/null #关闭日志dir /var/lib/redis/useradd redismkdir -p /var/lib/redischown redis.redis /var/lib/redis #db文件放在这里

4.编辑启动脚本

vim /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######

5.启动

/etc/init.d/redis start

6.设置开机启动,添加到系统服务中

chmod 775 /etc/init.d/redis#开机启动redischkconfig redis on

 

Redis安装配置以及开机启动