• Linux 配置redis的开机自启动


    第一步:

    配置redis.conf 文件,开启后台运行功能:

    daemonize yes

    第二步:

    添加自启动的redis文件,主要就是将 EXEC、REDIS_CLI、PIDFILE、CONF配置成自己的目录

    # chkconfig: 2345 10 90  
    # description: Start and Stop redis   
      
    PATH=/usr/local/bin:/sbin:/usr/bin:/bin   #找到本机安装redis后,存放redis命令的目录  
    REDISPORT=6379                            #redis的默认端口, 要和下文中的redis.conf中一致
    EXEC=/usr/redisbin/redis-server           #redis服务端的命令
    REDIS_CLI=/usr/redisbin/redis-cli         #redis客户端的命令  这两个一般都在 PATH目录下
    PIDFILE=/var/run/redis.pid                #reids的进程文件生成的位置
    CONF="/usr/redisbin/redis.conf"           #redis的配置文件所在的目录  
     
    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 exists, process is not running."  
                    else  
                            PID=$(cat $PIDFILE)   
                            echo "Stopping..."  
                           $REDIS_CLI -p $REDISPORT  SHUTDOWN    
                            sleep 2  
                           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

    第三步:

    测试redis的启动

    /etc/init.d/redis start

    第四步:

    将redis设置为自启动

    chkconfig redis on

  • 相关阅读:
    timeDate.js 插件优化
    向页面中插入不同格式的时间(timeDate.js)
    html
    html
    html
    html
    three.js
    three.js
    three.js
    python之路_头像预览、each循环及form组件校验验证码
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/13516181.html
Copyright © 2020-2023  润新知