Cent OS下编译安装redis
CieLutes
9年前
来自: http://my.oschina.net/u/1758535/blog/626579
操作系统:Cent OS 6.6 64bit
源文件:redis 3.0.3
编译需用到gcc,默认Cent OS安装好是自带gcc的
一、下载/解压redis源文件
cd /opt wget http://download.redis.io/releases/redis-3.0.3.tar.gz tar -zxvf redis-3.0.3.tar.gz
二、编译/安装
cd redis-3.0.3 make make PREFIX=/usr/local/redis install
三、配置redis
复制源文件夹中的配置文件至redis安装目录
cp /opt/redis-3.0.3/redis.conf /usr/local/redis/
编辑配置文件
vim /usr/local/redis/redis.conf
修改redis.conf的如下配置:
daemonize yes #redis将以守护进程的方式运行,默认为no会暂用你的终端
timeout 300 #当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
四、配置redis服务
新增服务
vim /etc/init.d/redis
将以下shell复制入redis服务文件,保存
#!/bin/sh # # redis Startup script for Redis Server # # chkconfig: - 80 12 # description: Redis is an open source, advanced key-value store. # # processname: redis-server # config: /etc/redis.conf # pidfile: /var/run/redis.pid source /etc/init.d/functions BIN="/usr/local/redis/bin" CONFIG="/usr/local/redis/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
修改文件权限(让其有可执行权限)
chmod 755 redis
将redis服务随系统启动
chkconfig redis on
五、启动测试
启动
service redis start
启动redis客户端
/usr/local/redis/bin/redis-cli 127.0.0.1:6379>
测试
127.0.0.1:6379> set foo bar OK 127.0.0.1:6379>get foo "bar" 127.0.0.1>
自此,redis安装成功