一:CentOS 6.5下载安装Redis1、下载源码,解压缩后编译源码# 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 # make2、进入安装目录的src文件夹下,有四个可执行文件redis-server、redis-benchmark、redis-cli和redis.conf,复制到同一个目录下# mkdir /usr/redis # cp redis-server /usr/redis # cp redis-benchmark /usr/redis # cp redis-cli /usr/redis # cp redis.conf /usr/redis # cd /usr/redis3、启动Redis服务。# cd /usr/redis # ./redis-server redis.conf启动异常: 情况一: [17496] 08 Oct 11:48:09.153 # Server started, Redis version 2.8.17 [17496] 08 Oct 11:48:09.153 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add "vm.overcommit_memory = 1" to /etc/sysctl.conf and then reboot or run the command "sysctl vm.overcommit_memory=1" for this to take effect. [17496] 08 Oct 11:48:09.153 * The server is now ready to accept connections on port 6379解决办法:编辑 /etc/sysctl.conf , 添加一项 vm.overcommit_memory = 1,重启生效。4、客户端测试。redis 127.0.0.1:6379> #显示此行意味着安装成功。二:设置redis开机启动环境:Linux系统为CentOS 6.61.编写启动脚本注意:默认的redis.conf文件参数是前台启动的,修改daemonize no为daemonize yes则为后台启动。脚本的编码格式在Windows上编码放在Linux可能不识别,可以用UltraEdit转换下格式“文件-->转换-->DOS 转 UNIX“#!/bin/sh #chkconfig: 345 86 14 #description: Startup and shutdown script for Redis
start() { if test -x $DAEMON then echo -e "Starting $DESC: $PROGNAME" if $DAEMON $CONFIG then echo -e "OK" else echo -e "failed" fi else echo -e "Couldn"t find Redis Server ($DAEMON)" fi }
stop() { if test -e $PIDFILE then echo -e "Stopping $DESC: $PROGNAME" if kill `cat $PIDFILE` then echo -e "OK" else echo -e "failed" fi else echo -e "No Redis Server ($DAEMON) running" fi }