共计 1726 个字符,预计需要花费 5 分钟才能阅读完成。
公司内部使用的有阿里云(私有云)平台。由于其虚拟机模块是固定死的,内部自己使用一些版本在其上面没有,后都是通过 vmware 创建好后,再通过阿里云专门的转换工具转换成他们的格式,再在后台通过命令导入的。能过这些模块分发的虚拟机在 vmware 上使用正常,但在阿里云平台上分发的虚拟机会有 ssh 连接慢的问题(一般 30 多秒才能出现密码认证界面,同一模板分发的虚拟机,一小部分有 ssh 连接慢的问题)。
通过查看 sshd_config 配置文件,发现影响 ssh 连接两项已做过处理:
UseDNS=no | |
GSSAPIAuthentication no |
而主机 OS 重启后,ssh 连接慢的问题就没有了。
通过阿里云内部的主机通过内网连接发现同样慢。通过 ssh 127.0.0.1 也同样很慢。
通过 ssh - v 参数查看详细连接过程。发现只除了认证等待时间过长外,后面未发现异常。
SUSE 下查看 /var/log/messages,redhat 下的 ssh 认证日志在 /var/log/auth 下,发现有如下内容:
2018-08-01T09:40:01.791947+08:00 www.361way.com cron[13490]: pam_unix(crond:session): session opened for user zabbix by (uid=0) | |
2018-08-01T09:40:01.792189+08:00 www.361way.com systemd[1]: Started Login Service. | |
2018-08-01T09:40:01.792420+08:00 www.361way.com cron[13494]: pam_unix(crond:session): session opened for user zabbix by (uid=0) | |
2018-08-01T09:40:01.792783+08:00 www.361way.com cron[13491]: pam_unix(crond:session): session opened for user zabbix by (uid=0) | |
2018-08-01T09:40:26.795639+08:00 www.361way.com cron[13491]: pam_systemd(crond:session): Failed to create session: Connection timed out | |
2018-08-01T09:40:26.796028+08:00 www.361way.com dbus[961]: [system] Failed to activate service 'org.freedesktop.login1': timed out | |
2018-08-01T09:40:26.796378+08:00 www.361way.com cron[13495]: pam_systemd(crond:session): Failed to create session: Activation of org.freedesktop.login1 timed out |
从上面的日志可以看出从 9:40:01 到 9:40:26 出现密码认证界面用了 25 秒,而些时有一个 org.freeddesktop.login1 失败的记录。运行 init 3 排除是图形化桌面的影响。运行后再连接发现还有该问题。放 G 查询了下该报错,发现了问题原因。
通过查询到的资料,了解到问题原因为:dbus 的服务重启后,systemd-logind 服务没有重启导致。故而在日志中会出现“[system] Failed to activate service‘org.freedesktop.login1‘: timed out”的报错。解决方法为重启 systemd-logind 服务。命令如下:
systemctl restart systemd-logind | |
systemctl status systemd-logind |
再进行 ssh 连接后,速度又变成 3 秒内响应了。
