CentOS Install redis

1 minute read

Installation

Download,extract and compile Redis with:
    $ wget http://download.redis.io/releases/redis-3.2.1.tar.gz
    $ tar xzf redis-3.2.1.tar.gz
    $ cd redis-3.2.1
    $ make
 

If Redis - linux / Error when Installing redis on linux: cc: command not found

    yum grouplist
    yum groupinstall 'Development Tools'
    $make
    cd src && make all
    make[1]: Entering directory `/usr/local/nodeclub/redis-3.0.0/src'
    CC adlist.o
    In file included from adlist.c:34:0:
    zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
     #include <jemalloc/jemalloc.h>

    $ cd deps/
    $ make lua
    $ cd ..
    $ make MALLOC=libc
    $ make install
    $ mkdir -p /etc/redis && cp redis.conf /etc/redis
    $ vi /etc/redis/redis.conf
        modify daemonize yes

Start Redis

    - $  /usr/local/bin/redis-server /etc/redis/redis.conf

Stop Redis services

    redis-cli shutdown

Clear cache

    redis-cli flushall

Start redis

Config redis.conf

    vim /etc/redis/redis.conf
    daemonize yes

Create start config

    vim /etc/init.d/redis
    # chkconfig: 2345 10 90

description: Start and Stop redis

PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379 #实际环境而定

EXEC=/usr/local/bin/redis-server #实际环境而定

REDIS_CLI=/usr/local/bin/redis-cli #实际环境而定


PIDFILE=/var/run/redis.pid
CONF="/usr/local/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..."
                        $EXEC $CONF
                fi
                if [ "$?"="0" ]
                then
                        echo "Redis is running..."
                fi
                ;;
        stop)
                if [ ! -f $PIDFILE ]
                then
                        echo "$PIDFILE exists, process is not running."
                else
                        PID=$(cat $PIDFILE)
                        echo "Stopping..."
                        $REDIS_CLI -p $REDISPORT SHUTDOWN
                        while [ -x $PIDFILE ]
                        do
                                echo "Waiting for Redis to shutdown..."
                                sleep 1
                        done
                        echo "Redis stopped"
                fi
                ;;
        restart|force-reload)
                ${0} stop
                ${0} start
                ;;
        *)
                echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
                exit 1
esac

Set chmod

    chmod +x /etc/init.d/redis

Boot 开机启动

# 尝试启动或停止redis

service redis start
service redis stop

开启服务自启动

     chkconfig redis on
     comment bind 
 

Leave a Comment