首页 > 其他 > 详细

centos8 设置 redis 开机自启动

时间:2020-07-14 00:29:41      阅读:650      评论:0      收藏:0      [点我收藏+]

编写脚本文件

#!/bin/bash
#chkconfig: 22345 10 90
#description: Start and Stop redis

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

PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/soft/redis5/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
        ;;
    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

 

技术分享图片

 

 

 

操作步骤记录

[root@localhost redis5]# vim /etc/init.d/redis5
[root@localhost redis5]# chmod +x /etc/init.d/redis5 
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# chkconfig --add redis5 

[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# chkconfig redis on
error reading information on service redis: No such file or directory
[root@localhost redis5]# 
[root@localhost redis5]# chkconfig redis5 on
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use systemctl list-unit-files.
      To see services enabled on particular target use
      systemctl list-dependencies [target].

redis5             0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@localhost redis5]# 
[root@localhost redis5]# 

 

centos8 设置 redis 开机自启动

原文:https://www.cnblogs.com/yadongliang/p/12538894.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!