centos8 设置 redis 开机自启动
Posted 习惯沉淀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos8 设置 redis 开机自启动相关的知识,希望对你有一定的参考价值。
编写脚本文件
#!/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 开机自启动的主要内容,如果未能解决你的问题,请参考以下文章