zoukankan      html  css  js  c++  java
  • Redis开机自启动

    1.新建redis文件

       vi /etc/init.d/redis

    2.修改/tec/init.d/redis文件,要修改Redis安装目录及配置文件路径

    EXEC=/usr/local/redis/bin/redis-server
    CLIEXEC=/usr/local/redis/bin/redis-cli
    CONF="/usr/local/redis/bin/redis.conf"

    #!/bin/sh
    # chkconfig: 2345 10 90  
    # description: Start and Stop redis   
    
    REDISPORT=6379
    EXEC=/usr/local/redis/bin/redis-server
    CLIEXEC=/usr/local/redis/bin/redis-cli
    
    PIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="/usr/local/redis/bin/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
    

     #!/bin/sh

       # chkconfig: 2345 10 90

       # description: Start and Stop redis

       头部的这部份要包含,否则chkconfig命令会执行不成功

    3.开机启动设置

      3.1添加Redis服务

      chkconfig --add redis

       3.2设备开机启动

      chkconfig redis on

        3.3启动Redis

      service redis start

         3.4关闭Redis

      service redis stop

     4.重新启动系统后查看进程

       ps aux|grep redis

       

          

  • 相关阅读:
    Codeforces Round #702 (Div. 3) 题解
    Educational Codeforces Round 104 (Rated for Div. 2) A~E题解
    AtCoder Regular Contest 112 A~D题解
    Codeforces Round #701 (Div. 2) A~E 题解
    java String, StringBuffer, StringBuilder简单介绍和使用
    货仓选址
    线程的同步
    数据结构课设作业
    线程的生命周期(java 图)
    JAVA多线程的创建和使用
  • 原文地址:https://www.cnblogs.com/foxting/p/8989222.html
Copyright © 2011-2022 走看看