CentOS 7安装Redis5.0.7

  1. 下载安装包,官网https://redis.io/download
wget http://download.redis.io/releases/redis-5.0.7.tar.gz

CentOS 7安装Redis5.0.7_第1张图片

  1. 解压:
tar -zxvf redis-5.0.7.tar.gz

将解压后的目录重命名为redis:

mv redis-5.0.7 redis
  1. 进入redis目录:
cd redis/
  1. 编译安装
make && make install
  1. 修改安装目录下的redis.conf配置文件:
vim redis.conf

修改以下配置:

#bind 127.0.0.1 # 将这行代码注释,监听所有的ip地址,外网可以访问
protected-mode no # 把yes改成no,允许外网访问
daemonize yes # 把no改成yes,后台运行
  1. 启动redis:
#进入src目录
cd src/

#启动redis
./redis-server

#后台启动,隐藏界面
./src/redis-server redis.conf # 后台启动的话不需要进入src目录,因为redis.conf文件并不在src目录下

redis服务器端界面如下:
CentOS 7安装Redis5.0.7_第2张图片

  1. 设置开机启动
    1)新建脚本文件:
vim /etc/init.d/redis

输入以下内容:

#!/bin/sh
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
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/smarthome/redis/redis.conf"	# 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 does not exist, 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

2)修改权限:

chmod 755 /etc/init.d/redis

3)启动测试:

/etc/init.d/redis start

启动成功:
CentOS 7安装Redis5.0.7_第3张图片
4)设置开机启动:

#添加到服务列表
chkconfig --add /etc/init.d/redis
#设置开机启动
chkconfig redis on

参考链接:
https://www.cnblogs.com/heqiuyong/p/10463334.html

你可能感兴趣的:(Redis,Linux)