search

Home  >  Q&A  >  body text

virtualbox - Redis使能密码后Ubuntu虚拟机无法正常关机

我一直在虚拟机中开发自己的服务器程序。

Redis缺省是没有密码的,我使能密码后,发现虚拟机无法正常关机。关机时Redis报告脚本密码错误,并一直死循环。

具体看截图。有:(error) NOAUTH Authentication required.

但是我不知道redis停止脚本在哪里。求帮助。

阿神阿神2761 days ago998

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-25 09:04:50

    I also encountered the same problem.
    My situation at the time was: using puppet for automatic delivery and deployment of redis, after enabling the authentication password for redis, and closing the service in puppet, puppet would freeze and cannot continue. Later, the same thing was discovered when manually locating the problem.
    The reason is actually that the service control script provided by the redis author in the source code package does not consider how to shut down the service after adding the authentication password.
    The shutdown method with password is: redis-cli -p port-a password shutdown
    Because I use puppet to deploy redis, I made this script into a puppet file template. If a password is added, the service control will be automatically modified. script. I've posted the template, hope it helps.

    #!/bin/sh
    #Configurations injected by install_server below....
    
    EXEC=/usr/local/bin/redis-server
    CLIEXEC=/usr/local/bin/redis-cli
    PIDFILE=/var/run/redis_<%= name %>.pid
    CONF="/etc/redis/<%= name %>.conf"
    REDISPORT="<%= name %>"
    ###############
    # SysV Init Information
    # chkconfig: - 58 74
    # description: redis_<%= name %> is the redis daemon.
    ### BEGIN INIT INFO
    # Provides: redis_<%= name %>
    # Required-Start: $network $local_fs $remote_fs
    # Required-Stop: $network $local_fs $remote_fs
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Should-Start: $syslog $named
    # Should-Stop: $syslog $named
    # Short-Description: start and stop redis_<%= name %>
    # Description: Redis daemon
    ### END INIT INFO
    
    
    case "" in
        start)
            if [ -f $PIDFILE ]
            then
                echo "$PIDFILE exists, process is already running or crashed"
            else
                echo "Starting Redis_$REDISPORT server..."
                $EXEC $CONF
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                echo "$PIDFILE does not exist, process is not running"
            else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                <% if @password == 'nopass' -%>
                $CLIEXEC -p $REDISPORT shutdown
                <% else -%>
                $CLIEXEC -p $REDISPORT -a <%= @password %> shutdown
                <% end -%>
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis_$REDISPORT to shutdown ..."
                    sleep 2
                done
                echo "Redis_$REDISPORT stopped"
            fi
            ;;
        status)
            PID=$(cat $PIDFILE)
            if [ -f $PIDFILE ]
            then
              if [ ! -x /proc/${PID} ]
              then
                echo 'Redis_$REDISPORT is not running'
                rm -rf $PIDFILE
                exit 1
              else
                echo "Redis_$REDISPORT is running"
              fi
            else
              echo 'No PID File,Redis_$REDISPORT is not running'
              exit 1
            fi
            ;;
        restart)
            rrreee stop
            rrreee start
            ;;
        *)
            echo "Please use start, stop, restart or status as first argument"
            ;;
    esac
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-25 09:04:50

    Redis可以通过客户端执行SHUTDOWN command to close.

    reply
    0
  • 阿神

    阿神2017-04-25 09:04:50

    Currently, I have temporarily made a script to shut down Redis, and run it manually before shutting down the virtual machine. A little rubbing.

    Because Shell programming is not familiar, you still need to learn your script. However, if redis-cli does not have a key, it should return a NOAUTH error. You need to make a judgment after capturing it and reuse redis-cli+key to close Redis.

    Finally, look for the corresponding shutdown script in the /etc/init directory to see how to integrate it.

    reply
    0
  • Cancelreply