Redis安装配置

字体大小: 中小 标准 ->行高大小: 标准

一)下载源码,编译安装

  1. # wget http://redis.googlecode.com/files/redis-2.2.8.tar.gz # tar xf redis-2.2.8.tar.gz 
  2. # cd redis # make  # 网上说不能make install,可我这就是可以,奇怪,省去了手动copy redis命令的步骤
  3. # make install  

make install后显示

  1. cd src && make install make[1]: Entering directory `/usr/local/src/redis-2.2.8/src' 
  2. cd ../deps/hiredis && make static ARCH="" make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis' 
  3. make[2]: Nothing to be done for `static'. make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis' 
  4. cd ../deps/linenoise && make ARCH="" make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/linenoise' 
  5. make[2]: `linenoise_example' is up to date. make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/linenoise' 
  6. cd ../deps/hiredis && make static make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis' 
  7. make[2]: Nothing to be done for `static'. make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis' 
  8. cc -o redis-benchmark -std=c99 -pedantic -O2 -Wall -W   -lm -pthread   -g -rdynamic -ggdb  ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o ../deps/hiredis/libhiredis.a cc -o redis-cli -std=c99 -pedantic -O2 -Wall -W   -lm -pthread   -g -rdynamic -ggdb  anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o 
  9.  Hint: To run 'make test' is a good idea ;) 
  10.  mkdir -p /usr/local/bin 
  11. cp -p redis-server /usr/local/bin cp -p redis-benchmark /usr/local/bin 
  12. cp -p redis-cli /usr/local/bin cp -p redis-check-dump /usr/local/bin 
  13. cp -p redis-check-aof /usr/local/bin make[1]: Leaving directory `/usr/local/src/redis-2.2.8/src' 

二)修改配置

修改配置之前,请将redis.conf copy一份到/etc/目录下

  1. daemonize no 

改成

  1. daemonize yes 

这两个参数

  1. loglevel warning  logfile /var/log/redis.log  

取消注释

  1. syslog-enabled no #这个改成syslog-enabled yes
  2. syslog-facility local0

数据文件目录

  1. # The working directory. # 
  2. # The DB will be written inside this directory, with the filename specified # above using the 'dbfilename' configuration directive. 
  3. # # Also the Append Only File will be created inside this directory. 
  4. # # Note that you must specify a directory here, not a file name. 
  5. dir /var/db/redis 

内存,连接数设置

  1. maxmemory 256000000
  2. maxclients 500

三)启动脚本

  1. #!/bin/bash # 
  2. # Init file for redis # 
  3. # chkconfig: - 80 12 # description: redis daemon 
  4. # # processname: redis 
  5. # config: /etc/redis.conf # pidfile: /var/run/redis.pid 
  6.  . /etc/init.d/functions 
  7.  BIN="/usr/local/bin" 
  8. CONFIG="/etc/redis.conf" PIDFILE="/var/run/redis.pid" 
  9.  ### Read configuration 
  10. [ -r "$SYSCONFIG" ] && source "$SYSCONFIG"  
  11. RETVAL=0 prog="redis-server" 
  12. desc="Redis Server"  
  13. start() {  
  14.         if [ -e $PIDFILE ];then              echo "$desc already running...." 
  15.              exit 1         fi 
  16.          echo -n $"Starting $desc: " 
  17.         daemon $BIN/$prog $CONFIG  
  18.         RETVAL=$?         echo 
  19.         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog         return $RETVAL 
  20. }  
  21. stop() {         echo -n $"Stop $desc: " 
  22.         killproc $prog         RETVAL=$? 
  23.         echo         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE 
  24.         return $RETVAL } 
  25.  restart() { 
  26.         stop         start 
  27. }  
  28.  case "$1" in 
  29.   start)         start 
  30.         ;;   stop) 
  31.         stop         ;; 
  32.   restart)         restart 
  33.         ;;   condrestart) 
  34.         [ -e /var/lock/subsys/$prog ] && restart         RETVAL=$? 
  35.         ;;   status) 
  36.         status $prog         RETVAL=$? 
  37.         ;;    *) 
  38. echo $"Usage: $0 {start|stop|restart|condrestart|status}"         RETVAL=1 
  39. esac  
  40. exit $RETVAL 

配置启动脚本

  1. #chmod 755 /etc/init.d/redis # chkconfig --add redis 
  2. # chkconfig redis on 

四)启动

在正式启动redis之前,先创建数据目录

  1. # mkdir /var/db/redis 

否则会出现下面的错误

  1. [3030] 27 May 16:50:38 # Can't chdir to '/var/db/redis': No such file or directory 

同时配置内核参数

  1. sysctl vm.overcommit_memory=1 

否则提示错误

  1. # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 
  2. #To fix this issue 
  3. #add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 
  4. #'sysctl vm.overcommit_memory=1' for this to take effect. 

最后,启动

  1. [root@web ~]# /etc/init.d/redis start Starting Redis Server:                                     [  OK  ]

PS:不利用脚本启动,关闭redis的命令

  1. 启动 # redis-server /etc/redis.conf 
  2.  关闭 
  3. # redis-cli shutdown  
  4. 关闭某个端口上的redis # redis-cli -p port shutdown

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/60035.html