systemd-logind导致ssh登录缓慢解决办法

背景

见之前centOS ssh登录缓慢解决
深挖了下原因总结成本文。

systemd-logind简介:

Name

systemd-logind.service, systemd-logind — Login manager

Synopsis

systemd-logind.service

/usr/lib/systemd/systemd-logind

Description

systemd-logind is a system service that manages user logins. It is responsible for:

Keeping track of users and sessions, their processes and their idle state. This is implemented by allocating a systemd slice unit for each user below user.slice, and a scope unit below it for each concurrent session of a user. Also, a per-user service manager is started as system service instance of [email protected] for each user logged in.

Generating and managing session IDs. If auditing is available and an audit session ID is set for a session already, the session ID is initialized from it. Otherwise, an independent session counter is used.

Providing PolicyKit-based access for users to operations such as system shutdown or sleep

Implementing a shutdown/sleep inhibition logic for applications

Handling of power/sleep hardware keys

Multi-seat management

Session switch management

Device access management for users

Automatic spawning of text logins (gettys) on virtual console activation and user runtime directory management

问题

发现在执行机上systemd-logind导致cpu 100%的问题,使得登录异常缓慢,并且消耗资源。

原因

  1. systemd-logind主要功能是为每一个登陆session创建一个systemd角度的cgroup管理对象,更方便对session使用cgroup,在实际场景中没有什么用处,关闭不会影响正常ssh登陆
  2. 在有crond任务时,触发systemd-logind回收不及时的bug

解决办法

关闭systemd-logind

systemctl stop systemd-logind

验证是否已经修复方法:
如果systemd-logind 状态如下所示,已经将systemd-logind关闭

systemctl status systemd-logind

你可能感兴趣的:(linux&Mac)