“服务mysqld停止”超时(然后发现“mysqld死亡但子弹被locking”)

我在64位CentOS 5服务器上通过yum安装了mysql和服务器。 它启动正常,但当我试图阻止它失速,然后我必须“Ctrl-C”它。 然后我运行一个“服务mysqld状态”,它显示:

mysqld dead but subsys locked 

我运行ps aux和mysql无处可查。 通过“服务mysqld启动”再次启动mysqld工作正常。 试图阻止它会产生同样的问题。

然后我意识到/var/lock/subsys/mysqld仍然存在。 当运行mysqld时,我检查了/var/run/mysqld/mysqld.pid ,并且与正在运行的服务的pid相匹配。

我试图重新安装MySQL和删除所有文件和configuration,但无济于事。

该怎么办?

编辑:

我在/etc/init.d/mysqld文件中添加了一些echo语句,特别是在stop函数中:

 stop(){ if [ ! -f "$mypidfile" ]; then # not running; per LSB standards this is "ok" action $"Stopping $prog: " /bin/true return 0 fi echo "beginning stop sequence" MYSQLPID=`cat "$mypidfile"` if [ -n "$MYSQLPID" ]; then /bin/kill "$MYSQLPID" >/dev/null 2>&1 echo "killing pid $MYSQLPID" ret=$? if [ $ret -eq 0 ]; then echo "return code $ret after kill attempt" TIMEOUT="$STOPTIMEOUT" echo "timeout is set to $STOPTIMEOUT" while [ $TIMEOUT -gt 0 ]; do /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break sleep 1 let TIMEOUT=${TIMEOUT}-1 echo "timeout is now $TIMEOUT" done if [ $TIMEOUT -eq 0 ]; then echo "Timeout error occurred trying to stop MySQL Daemon." ret=1 action $"Stopping $prog: " /bin/false else echo "attempting to del lockfile: $lockfile" rm -f $lockfile rm -f "$socketfile" action $"Stopping $prog: " /bin/true fi else action $"Stopping $prog: " /bin/false fi else # failed to read pidfile, probably insufficient permissions action $"Stopping $prog: " /bin/false ret=4 fi return $ret } 

这是我尝试停止服务时得到的结果:

 [root@server]# service mysqld stop beginning stop sequence killing pid 9145 return code 0 after kill attempt timeout is set to 60 timeout is now 59 timeout is now 58 timeout is now 57 timeout is now 56 timeout is now 55 timeout is now 54 timeout is now 53 timeout is now 52 timeout is now 51 timeout is now 50 timeout is now 49 

从代码看来,它永远不会摆脱while循环,并将无法删除locking文件。 我是否解释这个错误? 我检查了我的另一台服务器上的相同的文件,它使用相同的代码。 我傻眼了。

编辑 :在while循环部分

  /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break 

由于某些原因,它不能识别返回码。 当服务mysqld停止被调用,进程已经被杀死,但不知道为什么它不允许循环爆发。

编辑 :进一步的testing显示之间调用/bin/kill和只是调用kill之间的一些奇怪的行为,他们显然返回不同的代码,为什么??????:

 [root@server]# /bin/kill 25200 kill 25200: No such process [user@server]# echo ${?} 0 [root@server]# kill 25200 -bash: kill: (25200) - No such process [root@server]# echo ${?} 1 

编辑 :我作为一个非root用户login,并尝试执行“杀死”和“/斌/杀”一个惊人的结果:

 [notroot@server ~]$ kill -0 23232 -bash: kill: (23232) - No such process [notroot@server ~]$ echo $? 1 [notroot@server ~]$ /bin/kill -0 23232 kill 23232: No such process (No info could be read for "-p": geteuid()=501 but you should be root.) [notroot@server ~]$ echo $? 0 

执行kill和bin / kill作为非root用户时,“No info could read”错误不会显示在我的其他服务器上。

编辑 :增加了由quanta描述的日志logging,并检出了mysql日志:

在开始和停止之后,mysql日志显示这个:

 110918 00:11:28 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 110918 0:11:28 [Note] Plugin 'FEDERATED' is disabled. 110918 0:11:28 InnoDB: Initializing buffer pool, size = 16.0M 110918 0:11:28 InnoDB: Completed initialization of buffer pool 110918 0:11:29 InnoDB: Started; log sequence number 0 44233 110918 0:11:29 [Warning] 'user' entry 'root@server' ignored in --skip-name-resolve mode. 110918 0:11:29 [Warning] 'user' entry '@server' ignored in --skip-name-resolve mode. 110918 0:11:29 [Note] Event Scheduler: Loaded 0 events 110918 0:11:29 [Note] /usr/libexec/mysqld: ready for connections. Version: '5.1.58-ius' socket: '/var/lib/mysql/mysql.sock' port: 3306 Distributed by The IUS Community Project 110918 0:11:34 [Note] /usr/libexec/mysqld: Normal shutdown 110918 0:11:34 [Note] Event Scheduler: Purging the queue. 0 events 110918 0:11:34 InnoDB: Starting shutdown... 110918 0:11:39 InnoDB: Shutdown completed; log sequence number 0 44233 110918 0:11:39 [Note] /usr/libexec/mysqld: Shutdown complete 110918 00:11:39 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 

然后在tmp / mysql.log中:

 kill 23080: No such process kill 23080: No such process kill 23080: No such process kill 23080: No such process kill 23080: No such process kill 23080: No such process kill 23080: No such process kill 23080: No such process kill 23080: No such process kill 23080: No such process 

我中途停止了停车过程,所以我不必等待超时。 看起来这个过程被杀死了。 我想这个问题仍然是来自"kill""/bin/kill"的不同的返回码,

首先要做的是:做的很好,系统,彻底的debugging,做得好。

在我的RHEL 5.6机器上,如果我试图杀死一个不存在的pid,我总会得到一个1的返回码。 我试图作为根和非特权用户,都使用完整path和一个只有命令名称。 我也得到只有简洁的kill XXX: No such process ,没有详细的错误消息。

运行rpm -Vv util-linux可能是个好主意,看看有没有人用新的改进版本replace/bin/kill 。 即使rpmvalidation说文件是原始文件,我会尝试重命名/bin/kill并从工作机器上复制一个二进制文件。 如果文件replace有帮助,并且您不能发现更改的合法来源,那么不pipe转速validation的输出如何,我都会认为机器已经被盗用。