CentOS7 REDIS数据库单机版配置

CentOS7 REDIS数据库单机版配置

一. 在官网获取Redis最新版本

https://redis.io/download

$ wget http://download.redis.io/releases/redis-4.0.2.tar.gz

二.安装及测试

1. 解压并安装Redis

$ tar xzf redis-4.0.2.tar.gz
$ cd redis-4.0.2
$ make
$ make install

2.执行测试

$ make test

若提示 you need tcl 8.5 or newerin order to run the redis test,则需要安装tcl

$ yum install tcl

三.环境配置

1.redis配置

复制redis配置文件到/etc目录下

cp redis-4.0.2/redis.conf /etc/redis.conf
vi /etc/redis.conf

(1) 访问配置

bind 127.0.0.1 #本机访问

bind 0.0.0.0 #所有人均可访问

bind 本机局域网ip #局域网内可访问

(2) 启动模式配置

daemonize no #不使用后台启动

daemonize yes #使用后台启动

(3) 数据存储位置配置

dir /var/lib/redis

(4) 安全访问模式配置(3.2版本以上)

protected-mode no #禁用安全模式

2.service服务管理配置

创建redis配置文件: /etc/init.d/redis

# 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="/etc/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  
############################## 

创建完成后,执行以下命令

#设置开机启动
$ chkconfig redis on 
#添加执行权限
$ chmod +x /etc/init.d/redis 

四.配置完成!运行你的Redis数据库

$ service redis start
$ service redis stop
$ service redis restart

你可能感兴趣的:(配置及部署)