一)下載下傳源碼,編譯安裝
# 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[1]: Entering directory `/usr/local/src/redis-2.2.8/src'
cd ../deps/hiredis && make static ARCH=""
make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis'
make[2]: Nothing to be done for `static'.
make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis'
cd ../deps/linenoise && make ARCH=""
make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/linenoise'
make[2]: `linenoise_example' is up to date.
make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/linenoise'
cd ../deps/hiredis && make static
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
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[1]: 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 -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
restart() {
stop
start
case "$1" in
start)
;;
stop)
restart)
restart
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
status)
status $prog
*)
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
否則會出現下面的錯誤
[3030] 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.
最後,啟動
[root@web ~]# /etc/init.d/redis start
Starting Redis Server: [ OK ]
PS:不利用腳本啟動,關閉redis的指令
啟動
# redis-server /etc/redis.conf
關閉
# redis-cli shutdown
關閉某個端口上的redis
# redis-cli -p port shutdown
本文轉自dongfang_09859 51CTO部落格,原文連結:http://blog.51cto.com/hellosa/579825,如需轉載請自行聯系原作者