Linux中安装Redis

Linux中安装Redis

官网:https://redis.io/download
http://www.jianshu.com/p/cc403be7f80d(如果出现错误请见)

下载redis:
wget http://download.redis.io/releases/redis-4.0.8.tar.gz

解压
tar -zxvf redis-4.0.8.tar.gz -C /usr/local/

进入redis目录
cd /usr/local/redis-4.0.8

编译
make

安装(PREFIX安装指定目录 否则安装到/usr/local/bin里面了)
make install PREFIX=/usr/local/redis

复制redis配置文件到安装目录
cp /usr/local/redis-4.0.8/redis.conf /usr/local/redis/

启动redis服务
进入目录
    cd /usr/local/redis
启动服务、连接服务
./bin/redis-server
./bin/redis-cli

redis设置开机自启脚本
    vi /etc/init.d/redis
粘贴以下内容(修改路径)

# chkconfig: 2345 10 90    
# description: Start and Stop redis     

PATH=/usr/local/bin:/sbin:/usr/bin:/bin     
# redis端口号  
REDISPORT=6379    
# redis-server所在目录的绝对路径  
EXEC=/usr/local/redis/bin/redis-server     
# redis-cli所在目录的绝对路径  
REDIS_CLI=/usr/local/redis/bin/redis-cli     

PIDFILE=/var/run/redis.pid     
# redis.conf所在目录的绝对路径  
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..."    
                        nohup $EXEC $CONF >/dev/null 2>&1 &   
                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  

##将redis做成服务、给定执行权限、设置开机自启
    chmod 755 /etc/init.d/redis
    chkconfig --add redis
    chkconfig --level 2345 redis on
    chkconfig --list redis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值