Linux下安装redis

Posted lzhbkjava

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下安装redis相关的知识,希望对你有一定的参考价值。

  1. 安装gcc yum install -y gcc g++ gcc-c++ make

  2. 下载解压 redis wget http://download.redis.io/releases/redis-3.0.0.tar.gz                 tar zxvf redis-3.0.0.tar.gz                  cd redis-3.0.0

  3. 进入redis目录,执行make; make MALLOC=libc

  4. 启动 关闭 redis

    • 启动redis  src/redis-server &

    • 关闭redis  src/redis-cli shutdown

  5. redis 开机启动   ——    创建链接 ln -s /usr/redis.3.0.0 /usr/redis   ——   修改 redis.config 

 

daemonize yes

    vi /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/redis/src/redis-server   
REDIS_CLI=/usr/redis/src/redis-cli   
 
PIDFILE=/var/run/redis.pid   
CONF="/use/redis/redis.conf"  
AUTH="1234"  

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    
                        sleep 2  
                       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

  

6、 启动redis 关闭redis 服务

  • 尝试启动或停止redisservice redis startservice redis stop

  • 开启服务自启动chkconfig redis on

    

以上是关于Linux下安装redis的主要内容,如果未能解决你的问题,请参考以下文章

Linux下Redis 的安装

Linux下Redis服务器搭建

Linux 下安装 Redis

[Linux]Linux下redis的安装及配置.

Linux 下安装 redis

linux 下centos 安装redis