[500XRP悬赏] OpenVZ ubuntu10.04 中 SSH 无法启动的问题

2014-01-07 10:04:13 +08:00
 andybest
一台 OpenVZ 的 VPS ,在重启后 SSH 服务无法启动,仅能通过管理后台使用 “Serial Console” 登录

目前出问题的 VPS 的所有进程:
root@ssd:/# ps auxf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 1.0 2504 1360 ? Ss 09:50 0:00 init
root 2 0.0 0.0 0 0 ? S 09:50 0:00 [kthreadd/1980]
root 3 0.0 0.0 0 0 ? S 09:50 0:00 \_ [khelper/1980]
root 270 0.0 0.6 2336 884 ? Ss 09:50 0:00 cron
root 354 0.0 0.5 27496 760 ? Ss 09:51 0:00 vzctl: pts/0
root 355 0.0 1.2 3004 1644 pts/0 Ss 09:51 0:00 \_ -bash
root 367 0.0 0.6 2392 856 pts/0 R+ 09:51 0:00 \_ ps auxf

root@ssd:/# netstat -nl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 2875821005 @/com/ubuntu/upstart


尝试 ssh restart 与 ssh start 均无法启动 ssh 服务:

root@ssd:/# /etc/init.d/ssh restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service ssh restart

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the restart(8) utility, e.g. restart ssh
ssh stop/pre-start, process 386

root@ssd:/# /etc/init.d/ssh start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service ssh start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start ssh
ssh stop/pre-start, process 399

root@ssd:/# netstat -nl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 2875821005 @/com/ubuntu/upstart


安装 dropbear 在其他端口,并启动,同样无法启动:
root@ssd:~# /etc/init.d/dropbear start
Starting Dropbear SSH server: dropbear.

root@ssd:~# netstat -nl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 2875821005 @/com/ubuntu/upstart

-----------------------------------------------------------------------------------------------------

这个问题多次出现在 OpenVZ 的 ubuntu VPS 中,都是正常使用时,重启系统后 SSH 无法启动,参考帖子:
http://lowendtalk.com/discussion/9076/weird-can-t-start-ssh-service-on-a-openvz-vps

始终没有任何办法能解决,最后都是重新安装系统
(但同样的问题从未出现在 KVM / XEN 架构的 VPS,仅出现在 OpenVZ)

如果能帮助我,或者引导我通过查看日志之类的最终能解决问题,我愿意赠送 500XRP 表示感谢
感谢各位! :)
5836 次点击
所在节点    问与答
50 条回复
andybest
2014-01-07 13:23:11 +08:00
@lijinma 谢谢,是Ubuntu 10.04 server,没有这个文件:
root@ssd:/# cat /var/log/secure
cat: /var/log/secure: No such file or directory
juicy
2014-01-07 13:25:28 +08:00
@andybest log的问题 你看看/etc/ssh/sshd_config 这个文件下的logLevel有没有设置成Quiet, 也许是这个原因
lijinma
2014-01-07 13:28:05 +08:00
@andybest 噢,不好意思,没看到;

那你enable一下log:

sudo service rsyslog restart
或者
/etc/init.d/syslog restart

然后看一下:/etc/syslog.conf 里面应该有:

`auth,authpriv.* /var/log/auth.log`

类似的配置;
andybest
2014-01-07 13:34:44 +08:00
@juicy 检查了,是默认的:
LogLevel INFO
juicy
2014-01-07 13:50:42 +08:00
执行/usr/sbin/sshd -d的时候
返回Missing privilege separation directory: /var/run/sshd
这里应该是有问题的, 我尝试了一下用自己的机子, 没有发现这条提示

当楼主运行
mkdir /var/run/sshd
chmod 0755 /var/run/sshd
之后,
楼主可否再执行一下/usr/sbin/sshd -d
andybest
2014-01-07 13:53:37 +08:00
@lijinma 谢谢,奇怪的是syslog无法安装和启动:

root@ssd:/# sudo service rsyslog restart
rsyslog: unrecognized service
root@ssd:/#
root@ssd:/# service rsyslog restart
rsyslog: unrecognized service
root@ssd:/#
root@ssd:/# /etc/init.d/syslog restart
-bash: /etc/init.d/syslog: No such file or directory
root@ssd:/#
root@ssd:/# apt-get install syslog
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find package syslog
root@ssd:/#
root@ssd:/# apt-get install syslogd
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting sysklogd instead of syslogd
The following extra packages will be installed:
klogd sysklogd
The following NEW packages will be installed:
klogd sysklogd
0 upgraded, 2 newly installed, 0 to remove and 47 not upgraded.
Need to get 0B/116kB of archives.
After this operation, 369kB of additional disk space will be used.
Do you want to continue [Y/n]? y

Selecting previously deselected package sysklogd.
(Reading database ... 26840 files and directories currently installed.)
Unpacking sysklogd (from .../sysklogd_1.5-5ubuntu4_i386.deb) ...
Selecting previously deselected package klogd.
Unpacking klogd (from .../klogd_1.5-5ubuntu4_i386.deb) ...
Processing triggers for man-db ...
Setting up sysklogd (1.5-5ubuntu4) ...
* Starting system log daemon...
...done.

Setting up klogd (1.5-5ubuntu4) ...
* Starting kernel log daemon...




...fail!

root@ssd:/#
andybest
2014-01-07 13:58:41 +08:00
@juicy 牛!!!!!启动了:

root@ssd:/# mkdir /var/run/sshd
mkdir: cannot create directory `/var/run/sshd': File exists
root@ssd:/#
root@ssd:/# chmod 0755 /var/run/sshd

root@ssd:/# /usr/sbin/sshd -d
debug1: sshd version OpenSSH_5.3p1 Debian-3ubuntu7
debug1: read PEM private key done: type RSA
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: Checking blacklist file /usr/share/ssh/blacklist.DSA-1024
debug1: Checking blacklist file /etc/ssh/blacklist.DSA-1024
debug1: private host key: #1 type 2 DSA
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
debug1: Bind to port 22 on ::.
Server listening on :: port 22.



可以SSH连接了,在22端口,如何恢复SSH服务?
juicy
2014-01-07 14:01:15 +08:00
@andybest

那太好了!! Ctrl-C退出当前debugger模式,按正常方式启动就可以了吧
andybest
2014-01-07 14:04:54 +08:00
@juicy

使用:

root@ssd:/# /etc/init.d/ssh start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service ssh start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start ssh
ssh stop/pre-start, process 994

仍然无法启动 ssh 服务,不过 auth.log 有日志了!

root@ssd:/# tail /var/log/auth.log

Jan 7 08:14:38 ssd groupadd[578]: group added to /etc/group: name=klog, GID=111
Jan 7 08:14:38 ssd groupadd[578]: group added to /etc/gshadow: name=klog
Jan 7 08:14:38 ssd groupadd[578]: new group: name=klog, GID=111
Jan 7 08:14:38 ssd useradd[582]: new user: name=klog, UID=107, GID=111, home=/home/klog, shell=/bin/false
Jan 7 08:14:38 ssd usermod[587]: change user 'klog' password
Jan 7 08:14:38 ssd chage[592]: changed password expiry for klog
Jan 7 08:15:01 ssd CRON[622]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 7 08:15:01 ssd CRON[622]: pam_unix(cron:session): session closed for user root
Jan 7 08:25:01 ssd CRON[651]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 7 08:25:01 ssd CRON[651]: pam_unix(cron:session): session closed for user root
Jan 7 08:35:01 ssd CRON[658]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 7 08:35:01 ssd CRON[658]: pam_unix(cron:session): session closed for user root
Jan 7 08:36:01 ssd CRON[663]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 7 08:36:01 ssd CRON[663]: pam_unix(cron:session): session closed for user root
Jan 7 08:45:01 ssd CRON[668]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 7 08:45:01 ssd CRON[668]: pam_unix(cron:session): session closed for user root
Jan 7 08:55:01 ssd CRON[675]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 7 13:55:01 ssd CRON[940]: pam_unix(cron:session): session closed for user root
Jan 7 13:57:12 ssd sshd[947]: debug1: sshd version OpenSSH_5.3p1 Debian-3ubuntu7
Jan 7 13:57:12 ssd sshd[947]: debug1: read PEM private key done: type RSA
Jan 7 13:57:12 ssd sshd[947]: debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
Jan 7 13:57:12 ssd sshd[947]: debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
Jan 7 13:57:12 ssd sshd[947]: debug1: private host key: #0 type 1 RSA
Jan 7 13:57:12 ssd sshd[947]: debug1: read PEM private key done: type DSA
Jan 7 13:57:12 ssd sshd[947]: debug1: Checking blacklist file /usr/share/ssh/blacklist.DSA-1024
Jan 7 13:57:12 ssd sshd[947]: debug1: Checking blacklist file /etc/ssh/blacklist.DSA-1024
Jan 7 13:57:12 ssd sshd[947]: debug1: private host key: #1 type 2 DSA
Jan 7 13:57:13 ssd sshd[947]: pam_env(sshd:setcred): Unable to open env file: /etc/default/locale: No such file or directory
Jan 7 13:57:13 ssd sshd[947]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jan 7 13:57:13 ssd sshd[958]: pam_env(sshd:setcred): Unable to open env file: /etc/default/locale: No such file or directory
Jan 7 13:57:40 ssd sshd[947]: pam_unix(sshd:session): session closed for user root
Jan 7 13:57:40 ssd sshd[947]: pam_env(sshd:setcred): Unable to open env file: /etc/default/locale: No such file or directory
andybest
2014-01-07 14:06:30 +08:00
@juicy 我reboot了系统,dropbear 与 openssh 两个 ssh 服务(在不同端口)还是仍然没有开启
andybest
2014-01-07 14:13:51 +08:00
@juicy 现在是使用
/etc/init.d/ssh start
启动后,/var/log/auth.log中会多一条记录:

Jan 7 14:10:32 ssd dropbear[412]: premature exit: Failed to daemonize: No such device

同时SSH服务并没有启动
juicy
2014-01-07 14:21:21 +08:00
reboot之前 添加完/var/run/sshd/ 之后 运行 /etc/init.d/ssh start还是不能正常启动sshd?
andybest
2014-01-07 14:25:45 +08:00
@juicy 是的,使用
/usr/sbin/sshd -d
可以启动,但如果用
/etc/init.d/ssh start
则无法启动,并且 auth.log里多一条记录:
Jan 7 14:15:12 ssd dropbear[453]: premature exit: Failed to daemonize: No such device
andybest
2014-01-07 14:28:44 +08:00
@juicy 使用 /usr/sbin/sshd -d 可正常启动,输出信息为:

root@ssd:/# /usr/sbin/sshd -d
debug1: sshd version OpenSSH_5.3p1 Debian-3ubuntu7
debug1: read PEM private key done: type RSA
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: Checking blacklist file /usr/share/ssh/blacklist.DSA-1024
debug1: Checking blacklist file /etc/ssh/blacklist.DSA-1024
debug1: private host key: #1 type 2 DSA
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
juicy
2014-01-07 14:36:42 +08:00
......

快没招了。。。
你试一下把 /dev/null 给删了并重新创建一下

rm /dev/null


mknod /dev/null c 1 3

然后再启动一下sshd服务
andybest
2014-01-07 14:40:02 +08:00
@juicy 搞定了!!!!!正常启动了!!!

请教一下:
rm /dev/null
mknod /dev/null c 1 3

这俩是什么神奇的指令,干吗的

另外,给我你的ripple钱包地址吧, 500 XRP送上!!
juicy
2014-01-07 14:45:35 +08:00
终于。。。

我看到类似/etc/init.d/ssh的启动脚本里都会出现/dev/null这个”黑洞“文件, 在网上搜资料的时候发现似乎有人在这里遇到过问题, 所以尝试推荐你重新创建一下这个特殊的文件

我的地址
rhRpVb7eXvj2ybmdTi6EeARKa6X26Rf3XK
感谢楼主
andybest
2014-01-07 14:48:38 +08:00
@juicy 非常感谢! 500 XRP已发!

Your transaction has been submitted.

Your account balance will update once the payment has cleared.
andybest
2014-01-07 14:50:05 +08:00
@juicy 但我的帐户余额还没扣除,等下看看
lijinma
2014-01-07 14:58:03 +08:00
@andybest 哈哈 恭喜楼主;

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/95943

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX