centos下为redis添加service

xiaoxiao2021-02-28  125

为了方便地重启redis服务 以下为配置service快速启动或停止redis服务的步骤

第一步:首先 进入redis安装目录中的utils中

第二步:将其中的redis_init_script文件复制到/etc/init.d下

第三步:进入/etc/init.d 将redis_init_script更名为redis

第四步:命令:mv redis_init_script redis

第五步:编辑redis

vim /etc/init.d/redis

进入后编辑这些为你的redis安装目录

修改后的如下

#!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. REDISPORT=6379 EXEC=/var/www/redis-stable/src/redis-server CLIEXEC=/var/www/redis-stable/src/redis-cli PIDFILE=/var/redis/run/redis_${REDISPORT}.pid 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 -a "root" -p $REDISPORT shutdown                 while [ -x /proc/${PID} ]                 do                     echo "Waiting for Redis to shutdown ..."                     sleep 1                 done                 echo "Redis stopped"         fi         ;;     restart)         if [ ! -f $PIDFILE ]         then                 echo "$PIDFILE does not exist, process is not running"         else                 PID=$(cat $PIDFILE)                 echo "Stopping ..."                 $CLIEXEC -a "root" -p $REDISPORT shutdown                 while [ -x /proc/${PID} ]                 do                         echo "Restarting Redis server..."                 done                 $EXEC $CONF PIDFILE=/var/redis/run/redis_${REDISPORT}.pid 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 -a "root" -p $REDISPORT shutdown                 while [ -x /proc/${PID} ]                 do                     echo "Waiting for Redis to shutdown ..."                     sleep 1                 done                 echo "Redis stopped"         fi         ;;     restart)         if [ ! -f $PIDFILE ]         then                 echo "$PIDFILE does not exist, process is not running"         else                 PID=$(cat $PIDFILE)                 echo "Stopping ..."                 $CLIEXEC -a "root" -p $REDISPORT shutdown                 while [ -x /proc/${PID} ]                 do                         echo "Restarting Redis server..."                 done                 $EXEC $CONF                 echo "Redis restart success!"         fi         ;;     *)

        echo "Please use start or stop as first argument"         ;; esac

结束:这样就可以在用service redis stop、service redis start对redis进行快速启动停止了。

转载请注明原文地址: https://www.6miu.com/read-37045.html

最新回复(0)