redis在linux下的配置和开机启动_0neBean_NOT

2019-07-11  本文已影响0人  0neBean

step1: 去到安装目录下/usr/local/redis寻找redis 配置文件 redis.conf,打开文件查看内容:

$ vim redis.conf 

配置文件中需要修改两个地方daemonizepidfile,

step2: 修改官方启动脚本:

redis 还需要有一个管理启动、关闭、重启的脚本,redis源码里其实已经提供了一个/usr/local/redis/utils/redis_init_script,内容如下:

#!/bin/sh#

#1 端口
REDISPORT=6379
#2 server路径
EXEC=/usr/local/bin/redis-server
#3 cli路径
CLIEXEC=/usr/local/bin/redis-cli
#4 pidfile路径
PIDFILE=/var/run/redis_${REDISPORT}.pid
#5 conf路径
CONF="/etc/redis/${REDISPORT}.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
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

以上注释的12345处 需要按照本机情况修改为正确的路径

step3: 部署配置文件和启动脚本:

redis目录下的redis.conf文件拷贝到/etc/redis/6379.conf

$ mkdir /etc/redis
$ cp /usr/local/redis/redis.conf /etc/redis/6379.conf 

接着将redis_init_script脚本拷贝到/etc/init.d/redisd

cp /usr/local/redis/utils/redis_init_script /etc/init.d/redisd 
chkconfig redisd on

服务 redisd 不支持 chkconfig ?添加如下内容到/etc/init.d/redisd:

# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database

完成后检查命令是否生效:

$ service redisd start 
$ service redisd stop
上一篇下一篇

猜你喜欢

热点阅读