36

如何处理阿里云ssh连接慢

 5 years ago
source link: https://www.linuxprobe.com/aliyun-ssh-accont.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
一、问题描述

公司内部使用的有阿里云(私有云)平台。由于其虚拟机模块是固定死的,内部自己使用一些版本在其上面没有,后都是通过vmware创建好后,再通过阿里云专门的转换工具转换成他们的格式,再在后台通过命令导入的。能过这些模块分发的虚拟机在vmware上使用正常,但在阿里云平台上分发的虚拟机会有ssh连接慢的问题(一般30多秒才能出现密码认证界面,同一模板分发的虚拟机,一小部分有ssh连接慢的问题)。

通过查看sshd_config配置文件,发现影响ssh连接两项已做过处理:

UseDNS=no
GSSAPIAuthentication no

而主机OS重启后,ssh连接慢的问题就没有了。

二、问题分析
1、排查网络影响

通过阿里云内部的主机通过内网连接发现同样慢。通过ssh 127.0.0.1也同样很慢。

2、ssh连接详情分析

通过 ssh -v参数查看详细连接过程。发现只除了认证等待时间过长外,后面未发现异常。

3、查看主机日志

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秒内响应了。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK