Redis安装

1、 wget http://download.redis.io/releases/redis-4.0.9.tar.gz

2、 tar xzf redis-4.0.9.tar.gz

3、 cd redis-4.0.9

4、 Make

5、 mkdir -p /usr/local/redis/bin

6、 mkdir -p /usr/local/redis/etc

7、 make install PREFIX=/usr/local/redis

8、 groupadd redis

9、 useradd -g redis redis -s /sbin/nologin

10、 vim ../etc/redis.conf     修改bind-idlogdaemonize no改为yes和修改密码:requirepass password

11、 ps -ef|grep redis

12、 vim /home/redis/.bash_profile    

加入环境变量:export PATH="$PATH:/usr/local/redis/bin"

13、 source /home/redis/.bash_profile

14、 chown -R redis:redis /usr/local/redis

15、 sudo -u redis /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf

16、 redis-cli

17、启动脚本:

#!/bin/bash

###########################

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

REDISPORT=16379

EXEC=/usr/local/redis/bin/redis-server

REDIS_CLI=/usr/local/redis/bin/redis-cli

PIDFILE=/usr/local/redis/redis.pid

CONF="/usr/local/redis/etc/redis.conf"

PASSWORD="HxTrS~A3TnZv"

case "$1" in

  start)

    if [ -f $PIDFILE ]

    then

        echo "$PIDFILE exists, process is already running or crashed"

    else

        echo "Starting Redis server..."

        sudo -u redis $EXEC $CONF

    fi

    if [ "$?"="0" ]

    then

       echo "Redis is running..."

    fi

    ;;

  stop)

    if [ ! -f $PIDFILE ]

    then

        echo "$PIDFILE does not exist, process is not running"

    else

        PID=$(cat $PIDFILE)

        echo "Stopping ..."

        $REDIS_CLI -p $REDISPORT -a $PASSWORD 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

##############################

 

posted @ 2018-05-15 13:43  叶落千尘  阅读(112)  评论(0编辑  收藏  举报