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

    1. 新建一个文件

    vim /etc/init.d/redis
    

    2. 将下面内容粘贴到文件中

    #!/bin/sh
    #chkconfig:   2345 90 10
    #description:  Redis is a persistent key-value database
    PATH=/usr/local/bin:/sbin:/usr/bin:/bin
    
    REDISPORT=6379
    EXEC=/usr/local/bin/redis-server
    REDIS_CLI=/usr/local/bin/redis-cli
    PIDFILE=/var/run/redis_6379.pid
    CONF="/myredis/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  
            if [ "$?"="0" ]   
            then  
                  echo "Redis is running..."  
            fi  
            ;;  
        stop)  
            if [ ! -f $PIDFILE ]  
            then  
                    echo "$PIDFILE does not exist, process is not running"  
            else  
                    PID=$(cat $PIDFILE)  
                    echo "Stopping ..."  
                    $REDIS_CLI -p $REDISPORT SHUTDOWN  
                    while [ -x ${PIDFILE} ]  
                   do  
                        echo "Waiting for Redis to shutdown ..."  
                        sleep 1  
                    done  
                    echo "Redis stopped"  
            fi  
            ;;  
       restart|force-reload)  
            ${0} stop  
            ${0} start  
            ;;  
      *)  
        echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  
            exit 1  
    esac
    

    3. 修改下面配置为自己对应的信息

    REDISPORT=6379 # 端口号
    EXEC=/usr/local/bin/redis-server # 执行脚本的地址
    REDIS_CLI=/usr/local/bin/redis-cli # 客户端执行脚本的地址
    PIDFILE=/var/run/redis_6379.pid # 进程id文件地址,启动redis后才能看见
    CONF="/myredis/redis.conf" #配置文件地址
    

    4. 设置权限

    chmod 755 /etc/init.d/redis
    

    5. 启动测试

    /etc/init.d/redis start
    

    6. 启动成功会提示如下信息

    Starting Redis server...
    Redis is running...
    

    7. 设置开机自启动

    chkconfig --add /etc/init.d/redis
    chkconfig redis on
    

    * 如果启动失败

    查看第一步的配置文件信息,是否和第二步的文件信息一致,vim粘贴会出现粘贴不全的问题

  • 相关阅读:
    EntityFramework 启用迁移 EnableMigrations 报异常 "No context type was found in the assembly"
    JAVA 访问FTP服务器示例(2)
    NuGet Package Manager 更新错误解决办法
    JAVA 访问FTP服务器示例(1)
    RemoteAttribute 的使用问题
    诡异的 javascript 变量
    javascript apply用法
    Babun 中文乱码
    GSM呼叫过程
    转站博客园
  • 原文地址:https://www.cnblogs.com/songjilong/p/12580755.html
Copyright © 2011-2022 走看看