SSH 连接缓慢

远程ssh登录Linux缓慢

查看secure日志,发现大量如下标志性记录:

Oct 26 21:23:26 localhost crond[31374]: pam_systemd(crond:session): Failed to create session: Activation of org.freedesktop.login1 timed out
Oct 26 21:24:26 localhost crond[31515]: pam_systemd(crond:session): Failed to create session: Connection timed out

什么是 org.freedesktop.login1

那么,org.freedesktop.login1 是个什么玩意呢?参见 org.freedesktop.login1 官方文档。

org.freedesktop.login1 — The D-Bus interface of systemd-logind

systemd-logind.service(8) 是跟踪用户登录和"座位"的系统服务。

守护进程提供了C库接口和D-Bus接口。C库接口用于反省和监控用户登录和"座位"的状态。D-Bus接口除了提供相同的功能外,还能更改系统状态。更多内容参见 sd-login(3)。

Activation of org.freedesktop.login1 timed out 怎么处理

查看bus状态,关注org.freedesktop.login1org.freedesktop.systemd1

[root@core log]# busctl --list
NAME                                   PID PROCESS         USER             CONNECTION    UNIT                      SESSION    DESCRIPTION        
:1.0                                     1 systemd         root             :1.0          -                         -          -                  
:1.136950                            12472 polkitd         polkitd          :1.136950     polkit.service            -          -                  
:1.157995                            18442 busctl          root             :1.157995     sshd.service              -          -                  
fi.epitest.hostap.WPASupplicant          - -               -                (activatable) -                         -         
fi.w1.wpa_supplicant1                    - -               -                (activatable) -                         -         
org.freedesktop.DBus                     - -               -                -             -                         -          -                  
org.freedesktop.NetworkManager           - -               -                (activatable) -                         -         
org.freedesktop.PolicyKit1           12472 polkitd         polkitd          :1.136950     polkit.service            -          -                  
org.freedesktop.hostname1                - -               -                (activatable) -                         -         
org.freedesktop.locale1                  - -               -                (activatable) -                         -         
org.freedesktop.login1                   - -               -                (activatable) -                         -         
org.freedesktop.machine1                 - -               -                (activatable) -                         -         
org.freedesktop.nm_dispatcher            - -               -                (activatable) -                         -         
org.freedesktop.systemd1                 1 systemd         root             :1.0          -                         -          -                  
org.freedesktop.timedate1                - -               -                (activatable) -                         -         

再查看一台正常的服务器,发现org.freedesktop.login1的状态是不一样的。如下:

[root@hadoop ~]# busctl --list
NAME                                   PID PROCESS         USER             CONNECTION    UNIT                      SESSION    DESCRIPTION        
:1.0                                     1 systemd         root             :1.0          -                         -          -                  
:1.1                                   843 polkitd         polkitd          :1.1          polkit.service            -          -                  
:1.18                                 1060 tuned           root             :1.18         tuned.service             -          -                  
:1.2                                   853 systemd-logind  root             :1.2          systemd-logind.service    -          -                  
:1.3                                   852 NetworkManager  root             :1.3          NetworkManager.service    -          -                  
:1.400                               26323 busctl          root             :1.400        session-179.scope         179        -                  
:1.7                                   852 NetworkManager  root             :1.7          NetworkManager.service    -          -                  
com.redhat.ifcfgrh1                    852 NetworkManager  root             :1.7          NetworkManager.service    -          -                  
com.redhat.tuned                      1060 tuned           root             :1.18         tuned.service             -          -                  
fi.epitest.hostap.WPASupplicant          - -               -                (activatable) -                         -         
fi.w1.wpa_supplicant1                    - -               -                (activatable) -                         -         
org.freedesktop.DBus                   844 dbus-daemon     dbus             org.freedesktop.DBus dbus.service              -          -                  
org.freedesktop.NetworkManager         852 NetworkManager  root             :1.3          NetworkManager.service    -          -                  
org.freedesktop.PolicyKit1             843 polkitd         polkitd          :1.1          polkit.service            -          -                  
org.freedesktop.hostname1                - -               -                (activatable) -                         -         
org.freedesktop.import1                  - -               -                (activatable) -                         -         
org.freedesktop.locale1                  - -               -                (activatable) -                         -         
org.freedesktop.login1                 853 systemd-logind  root             :1.2          systemd-logind.service    -          -                  
org.freedesktop.machine1                 - -               -                (activatable) -                         -         
org.freedesktop.nm_dispatcher            - -               -                (activatable) -                         -         
org.freedesktop.systemd1                 1 systemd         root             :1.0          -                         -          -                  
org.freedesktop.timedate1                - -               -                (activatable) -                         -         
[root@hadoop ~]# 

那么查看D-Bus日志,大量类似如下的重复报错:

[root@core log]# journalctl -u dbus
...
Oct 29 12:49:01 core dbus[10830]: [system] Activating via systemd: service name='org.freedesktop.login1' unit='dbus-org.freedesktop.login1.service'
Oct 29 12:49:01 core dbus-daemon[10830]: dbus[10830]: [system] Activating via systemd: service name='org.freedesktop.login1' unit='dbus-org.freedesktop.login1.service'
Oct 29 12:49:26 core dbus[10830]: [system] Failed to activate service 'org.freedesktop.login1': timed out
Oct 29 12:49:26 core dbus-daemon[10830]: dbus[10830]: [system] Failed to activate service 'org.freedesktop.login1': timed out
[root@core log]# systemctl status dbus
● dbus.service - D-Bus System Message Bus
   Loaded: loaded (/usr/lib/systemd/system/dbus.service; static; vendor preset: disabled)
   Active: active (running) since Mon 2020-07-20 21:14:01 CST; 3 months 9 days ago
 Main PID: 10830 (dbus-daemon)
   CGroup: /system.slice/dbus.service
           └─10830 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation

Oct 29 12:50:01 core dbus[10830]: [system] Activating via systemd: service name='org.freedesktop.login1' unit='dbus-org.freedesktop.login1.service'
Oct 29 12:50:01 core dbus-daemon[10830]: dbus[10830]: [system] Activating via systemd: service name='org.freedesktop.login1' unit='dbus-org.freedesktop.login1.service'
Oct 29 12:50:26 core dbus[10830]: [system] Failed to activate service 'org.freedesktop.login1': timed out
Oct 29 12:50:26 core dbus-daemon[10830]: dbus[10830]: [system] Failed to activate service 'org.freedesktop.login1': timed out
Oct 29 12:51:01 core dbus[10830]: [system] Activating via systemd: service name='org.freedesktop.login1' unit='dbus-org.freedesktop.login1.service'
Oct 29 12:51:01 core dbus-daemon[10830]: dbus[10830]: [system] Activating via systemd: service name='org.freedesktop.login1' unit='dbus-org.freedesktop.login1.service'
Oct 29 12:51:26 core dbus[10830]: [system] Failed to activate service 'org.freedesktop.login1': timed out
Oct 29 12:51:26 core dbus-daemon[10830]: dbus[10830]: [system] Failed to activate service 'org.freedesktop.login1': timed out
Oct 29 12:52:01 core dbus[10830]: [system] Activating via systemd: service name='org.freedesktop.login1' unit='dbus-org.freedesktop.login1.service'
Oct 29 12:52:01 core dbus-daemon[10830]: dbus[10830]: [system] Activating via systemd: service name='org.freedesktop.login1' unit='dbus-org.freedesktop.login1.service'

既然org.freedesktop.login1是systemd-logind的D-Bus接口,那么我们重启 systemd-logind

[root@core log]# systemctl restart systemd-logind

使用journalctl -f -u dbus查看日志,没有再出现报错。再次使用ssh远程连接,恢复正常了。

参考文档

https://www.freedesktop.org/software/systemd/man/org.freedesktop.login1.html
https://support.oracle.com/knowledge/Oracle%20Linux%20and%20Virtualization/2614155_1.html

你可能感兴趣的:(SSH 连接缓慢)