[Linux] 在CentOS5上面建立redis

當需要自己手動make redis的時候
連到 https://redis.io/download
wget http://download.redis.io/releases/redis-4.0.11.tar.gz
tar zxfv redis-4.0.11.tar.gz
cd redis-4.0.11
如果tcl版本沒有到8.5, 在 make test 的時候會出錯
這時候就直接用以下三個指令, 不要 make test

make clearn
make
make install

這時候基本上就已經裝好redis server了
在 /usr/local/bin/redis-server

這時候要先在建立存放 redis.conf 的地方

mkdir -p /etc/redis
cd /etc/redis && wget http://download.redis.io/redis-stable/redis.conf


接著把 redis 做成系統服務:


# redis script 的內容如下
# nohup 是讓程式不因離開 ssh 而中斷, &是放入背景執行
vi /etc/init.d/redis
touch /var/log/redis.log
chkconfig --add redis
chkconfig redis on

# 啟動/停止 redis
/etc/init.d/redis start
/etc/init.d/redis stop

Ref: https://www.linode.com/docs/databases/redis/redis-on-centos-5/

!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

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

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                nohup $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
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac



留言

這個網誌中的熱門文章

[翻譯] 介紹現代網路負載平衡與代理伺服器

Grafana K6

Linux 事件驅動筆記