Home > Database > Redis > body text

Set redis to start at boot

Release: 2020-06-18 16:58:08
forward
2052 people have browsed it

Set redis to start at boot

使用下面的方法要注意的是安装文件路径和配置文件的路径。

[root@localhost ~]# vi /etc/init.d/redis
Copy after login

复制下面代码到脚本中(注意要修改里面redis的安装路径,不清楚find查找下)
(这段代码就是redis根目录 /utils/redis_init_script 启动脚本的代码)

#!/bin/sh
# chkconfig: 2345 10 90  
# description: Start and Stop redis   

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-server

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/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..."
                $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
        ;;
    restart)
        "$0" stop
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop or restart as first argument"
        ;;
esac
Copy after login

设置权限

[root@localhost ~]# chmod 777 /etc/init.d/redis
Copy after login

设置开机启动

 chkconfig redis on
Copy after login

启动测试

 service start redis
Copy after login

更多相关知识请关注redis入门教程栏目

The above is the detailed content of Set redis to start at boot. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!