一、问题概述
公司私有云平台(基于阿里云)上的虚拟机存在ssh连接缓慢的问题。这些虚拟机通过VMware创建,再转换为阿里云格式导入。部分虚拟机SSH连接时间长达30秒以上,重启主机后问题消失。已排除sshd_config文件中的UseDNS=no和GSSAPIAuthentication no配置问题。
二、问题诊断
1. 网络排查:
内网和本地环回测试(ssh 127.0.0.1)均出现连接缓慢。
2. SSH连接日志分析:
使用ssh -v命令查看详细日志,发现仅认证阶段耗时过长,其他环节正常。
3. 系统日志分析:
/var/log/messages (SUSE) 或 /var/log/auth (Redhat) 日志显示systemd-logind服务激活超时:
... 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 ...
排除图形界面干扰后,问题依然存在。经调查,此错误提示指向systemd-logind服务问题。
三、解决方案
问题根源在于dbus服务重启后,systemd-logind服务未同步重启。 解决方法:重启systemd-logind服务。
systemctl restart systemd-logind systemctl status systemd-logind
重启后,SSH连接速度恢复正常(3秒以内)。