下载好redis-2.8.13.tar.gz放在/usr/local下
tar zxvf redis-2.8.13.tar.gz cd /usr/local/redis-2.8.13 make
到这步其实可以说安装完成了,因为在源码目录下的src目录已经产生了下面的执行:
redis-server、redis-cli、redis-benchmark等文件,它们作用如下:
redis-server :Redis服务器的daemon启动程序 redis-cli :Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作 redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
进入到 src 目录下:
cd src make install
此时make完会提示一个:Hint: To run 'make test' is a good idea ;(--打给意思是:提示:运行进行测试是一个好主意)
[root@bdjb-0197 src]# make test
此时会报错:
“You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] 错误 1”
错误提示是说:要安装tcl。(安装tcl参考:http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html)
具体代码如:
tar -xf tcl8.6.1-src.tar.gz --strip-components=1 cd tcl8.6.1/unix ./configure --prefix=/usr/local \ --without-tzdata \ $([ $(uname -m) = x86_64 ] && echo --enable-64bit) make sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \ -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \ -i tclConfig.sh make test make install make install-private-headers ln -v -sf tclsh8.6 /usr/bin/tclsh chmod -v 755 /usr/lib/libtcl8.6.so (如报不到文件,没关系)
等安装tcl后,在执行
[root@bdjb-0197 src]# make test
默认的配置文件home/redis.conf,拷贝到固定的目录下
mkdis /etc/redis 系统配置存放于/etc下 cp /usr/local/redis-2.8.13/redis.conf /etc/redis
cp /usr/local/redis-2.8.13 [root@bdjb-0197 redis-2.8.13]# redis-server /etc/redis/redis.conf
虽然启动,但是出现报警信息:
“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.
”大概意思是:
“警告:过量使用内存设置为0!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。”
按这个提示来做,警告排除。
注意:再次启动后,在这个终端上不要操作任何动作,直接关闭这个终端,再开另外终端进行操作!!!
[root@bdjb-0197 redis-2.8.13]# redis-cli shutdown
习惯了通过service启动一切服务,新建文件并赋予权限:
touch /etc/init.d/redis-server chmod +x /etc/init.d/redis-server
编辑/etc/init.d/redis-server,键入如下内容
#!/bin/bash # # redis Startup script for redis processes # # author: snowolf # # processname: redis redis_path="/usr/local/bin/redis-server" redis_conf="/etc/redis/redis.conf" redis_pid="/var/run/redis.pid" # Source function library. . /etc/rc.d/init.d/functions [ -x $redis_path ] || exit 0 RETVAL=0 prog="redis" # Start daemons. start() { if [ -e $redis_pid -a ! -z $redis_pid ];then echo $prog" already running...." exit 1 fi echo -n $"Starting $prog " # Single instance for all caches $redis_path $redis_conf RETVAL=$? [ $RETVAL -eq 0 ] && { touch /var/lock/subsys/$prog success $"$prog" } echo return $RETVAL } # Stop daemons. stop() { echo -n $"Stopping $prog " killproc -d 10 $redis_path echo [ $RETVAL = 0 ] && rm -f $redis_pid /var/lock/subsys/$prog RETVAL=$? return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status $prog RETVAL=$? ;; restart) stop start ;; condrestart) if test "x`pidof redis`" != x; then stop start fi ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart}" exit 1 esac exit $RETVAL
# service redis-server restart Stopping redis [失败] Starting redis [确定] # service redis-server status redis (pid 14965) 正在运行...