ubuntu16 安装redis

ubuntu16 安装redis并开机自启

1.redis-3.2.5.tar.gz解压到/usr/local下

  tar -xvf redis-3.2.5.tar.gz 

2.进入源码包/usr/local/redis-3.2.5

  make

    make  PREFIX=/usr/local/redis  install

3.将源码中的配置文件拷贝到安装目录 

  cp /usr/local/redis-3.2.5/redis.conf   /usr/local/redis/

4.将redis后台启动(编辑拷贝启动文件,将)

     vim /usr/local/redis/redis.config

  daemonize no改为daemonize yes保存

5.启动/usr/local/redis/下

  ./bin/redis-server  ./redis.conf

6.查看服务是否启动

  ps -ef|grep redis

7.设置为开机启动

  vim  /etc/init.d/redis

#!/bin/sh
# chkconfig: 2345 10 90  
# description: Start and Stop redis   

REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server  #改为自己的路径
CLIEXEC=/usr/local/redis/bin/redis-cli   #改为自己的路径

PIDFILE=/var/run/redis_${REDISPORT}.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
        ;;
    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
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop or restart as first argument"
        ;;
esac

service redis stop

service redis start

service redis restart

 

使用桌面可视化工具RedisDesktopManager

修改redis.conf (如下图)

 

如果需要设置redis密码(修改requirepass)

 

重启redis,即可用可视化工具连接

 

posted @ 2016-11-20 19:31  走走~停停  阅读(302)  评论(0编辑  收藏  举报