virtualbox - Redis使能密码后Ubuntu虚拟机无法正常关机
阿神
阿神 2017-04-25 09:02:50
0
3
923

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

  • VirtualBox V5

  • Ubuntu Server 12.04LTS 32bit

  • Python 2.7.3

  • MySQL 5.5

  • Redis

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

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

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

阿神
阿神

闭关修行中......

reply all (3)
刘奇

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
    Ty80

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

      阿神

      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.

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!