h1. Redis安装指南

* 下载redis,地址:http://redis.googlecode.com/files/redis-2.4.4.tar.gz

wget -S http://redis.googlecode.com/files/redis-2.4.4.tar.gz

* 解压redis安装包

tar zxf redis-2.4.4.tar.gz

* 进入redis-2.4.4目录,然后修改src/Makefile。找到“PREFIX= /usr/local”,修改为“PREFIX= /usr/local/redis”

* 执行make && make install

* 执行cd /usr/local/redis

* 执行mkdir data etc log生成三个目录

data:存放rdb文件
etc:存放redis配置文件
log:存放redis日志文件

* 新增加一个启动文件/etc/init.d/redis_$port,内容如下

#!/bin/sh
#
# chkconfig: 2345 55 25
# description: Redis server daemon
#
# processname: redis_$port #需要修改与$port相同
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379   # 需要修改与$port相同
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/etc/redis_${REDISPORT}.conf"


case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis $REDISPORT ..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit
esac

* 新增文件/usr/local/redis/etc/redis_base.conf,内容如下


daemonize yes

timeout 300

loglevel notice

databases 16


save 900 1
save 300 10
save 60 10000

rdbcompression yes


slave-serve-stale-data yes

appendonly no

appendfsync no

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

slowlog-log-slower-than 10000

slowlog-max-len 1024

vm-enabled no

* 新增加一个启动文件/usr/local/redis/etc/redis_$port.conf,内容如下

pidfile /var/run/redis_6379.pid

#修改6379成$port值
port 6379  

#修改6379成$port值
logfile /usr/local/redis/log/redis_6379.log  

#修改6379成$port值
dbfilename dump_6379.rdb  

dir /usr/local/redis/data


include /usr/local/redis/etc/redis_base.conf

* 将脚本redis_$port加入自动化启动,执行如下命令:

chkconfig -add redis_$port
chkconfig --level 135 redis_$port on


分享到: 更多

这篇日志的 QR 二维码为:

四月 23rd, 2012

Posted In: linux系统

发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量