hhnf333 发表于 2018-11-7 13:24:20

redis安装,配置

  一)下载源码,编译安装
  


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

  make install后显示
  


[*]cd src && make install
[*]make: Entering directory `/usr/local/src/redis-2.2.8/src'
[*]cd ../deps/hiredis && make static ARCH=""
[*]make: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis'
[*]make: Nothing to be done for `static'.
[*]make: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis'
[*]cd ../deps/linenoise && make ARCH=""
[*]make: Entering directory `/usr/local/src/redis-2.2.8/deps/linenoise'
[*]make: `linenoise_example' is up to date.
[*]make: Leaving directory `/usr/local/src/redis-2.2.8/deps/linenoise'
[*]cd ../deps/hiredis && make static
[*]make: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis'
[*]make: Nothing to be done for `static'.
[*]make: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis'
[*]cc -o redis-benchmark -std=c99 -pedantic -O2 -Wall -W   -lm -pthread   -g -rdynamic -ggdbae.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 -ggdbanet.o sds.o adlist.o redis-cli.o zmalloc.o release.o ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o
[*]
[*]Hint: To run 'make test' is a good idea ;)
[*]
[*]mkdir -p /usr/local/bin
[*]cp -p redis-server /usr/local/bin
[*]cp -p redis-benchmark /usr/local/bin
[*]cp -p redis-cli /usr/local/bin
[*]cp -p redis-check-dump /usr/local/bin
[*]cp -p redis-check-aof /usr/local/bin
[*]make: Leaving directory `/usr/local/src/redis-2.2.8/src'
  

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


[*]daemonize no
  

  改成
  


[*]daemonize yes
  

  这两个参数
  


[*]loglevel warning
[*]logfile /var/log/redis.log
  

  取消注释
  


[*]syslog-enabled no #这个改成syslog-enabled yes
[*]syslog-facility local0
  

  数据文件目录
  


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

  内存,连接数设置
  


[*]maxmemory 256000000
[*]maxclients 500
  

  三)启动脚本
  


[*]#!/bin/bash
[*]#
[*]# Init file for redis
[*]#
[*]# chkconfig: - 80 12
[*]# description: redis daemon
[*]#
[*]# processname: redis
[*]# config: /etc/redis.conf
[*]# pidfile: /var/run/redis.pid
[*]
[*]. /etc/init.d/functions
[*]
[*]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
  

  配置启动脚本
  


[*]#chmod 755 /etc/init.d/redis
[*]# chkconfig --add redis
[*]# chkconfig redis on
  

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


[*]# mkdir /var/db/redis
  

  否则会出现下面的错误
  


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

  同时配置内核参数
  


[*]sysctl vm.overcommit_memory=1
  

  否则提示错误
  


[*]# 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.
  

  最后,启动
  


[*]# /etc/init.d/redis start
[*]Starting Redis Server:                                    
  

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


[*]启动
[*]# redis-server /etc/redis.conf
[*]
[*]关闭
[*]# redis-cli shutdown
[*]
[*]关闭某个端口上的redis
[*]# redis-cli -p port shutdown


页: [1]
查看完整版本: redis安装,配置