太长不看版

  • 起因:备份数据库报错,备份任务失败
    Failed to create volume group in staging disks
  • 排错:登录服务器(rhel7.9)查看备份软件agent服务报错
[root@zcdb03 ~]# systemctl status udsagent.service
● udsagent.service - Actifio UDSAgent Service
   Loaded: loaded (/usr/lib/systemd/system/udsagent.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2025-09-12 09:28:54 CST; 1min 48s ago
  Process: 110254 ExecStop=/act/initscripts/udsagent.init stop (code=exited, status=0/SUCCESS)
  Process: 110353 ExecStart=/act/initscripts/udsagent.init start (code=exited, status=0/SUCCESS)
 Main PID: 110458 (udsagent)
   CGroup: /system.slice/udsagent.service
           ├─110458 /opt/act/bin/udsagent start
           └─110459 /opt/act/bin/udsagent start

Sep 12 09:28:54 zcdb03 systemd[1]: Starting Actifio UDSAgent Service...
Sep 12 09:28:54 zcdb03 udsagent.init[110353]: Starting /opt/act/bin/udsagent as a daemon
Sep 12 09:28:54 zcdb03 systemd[1]: PID file /var/run/udsagent.pid not readable (yet?) after start.
Sep 12 09:28:54 zcdb03 udsagent.init[110353]: Starting /opt/act/bin/udsagent as a daemon
Sep 12 09:28:54 zcdb03 systemd[1]: Started Actifio UDSAgent Service.
Sep 12 09:29:04 zcdb03 su[113733]: (to grid) root on none
Sep 12 09:29:04 zcdb03 su[113733]: pam_systemd(su-l:session): Failed to create session: No buffer space available
Sep 12 09:29:04 zcdb03 su[113733]: pam_unix(su-l:session): session opened for user grid by (uid=0)
Sep 12 09:29:04 zcdb03 su[113733]: pam_unix(su-l:session): session closed for user grid

备份软件切grid用户切不过去,系统中可以切过去
具体聚焦在下面这条报错信息
pam_systemd(su-l:session): Failed to create session: No buffer space available

  • 纠错:查看systemd-logind 服务发现大量报错
systemctl status systemd-logind
● systemd-logind.service - Login Service
   Loaded: loaded (/usr/lib/systemd/system/systemd-logind.service; static; vendor preset: disabled)
   Active: active (running) since Mon 2021-10-11 23:15:30 CST; 3 years 11 months ago
     Docs: man:systemd-logind.service(8)
           man:logind.conf(5)
           http://www.freedesktop.org/wiki/Software/systemd/logind
           http://www.freedesktop.org/wiki/Software/systemd/multiseat
 Main PID: 26432 (systemd-logind)
   Status: "Processing requests..."
   CGroup: /system.slice/systemd-logind.service
           └─26432 /usr/lib/systemd/systemd-logind

Sep 12 09:37:36 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50509573.scope: The maximum number of pending replies per co...n reached
Sep 12 09:37:38 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50509574.scope: The maximum number of pending replies per co...n reached
Sep 12 09:37:38 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50509575.scope: The maximum number of pending replies per co...n reached
Sep 12 09:37:39 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50509576.scope: The maximum number of pending replies per co...n reached
Sep 12 09:37:39 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50509577.scope: The maximum number of pending replies per co...n reached
Sep 12 09:37:39 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50509578.scope: The maximum number of pending replies per co...n reached
Sep 12 09:37:51 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50509579.scope: The maximum number of pending replies per co...n reached
Sep 12 09:38:01 zcdb03 systemd-logind[26432]: Failed to start session scope session-1439503.scope: The maximum number of pending replies per conn...n reached
Sep 12 09:38:01 zcdb03 systemd-logind[26432]: Failed to start session scope session-1439504.scope: The maximum number of pending replies per conn...n reached
Sep 12 09:38:01 zcdb03 systemd-logind[26432]: Failed to start session scope session-1439505.scope: The maximum number of pending replies per conn...n reached
  • 定位问题: 误核心指向 systemd-logind 服务的 D-Bus 连接未处理回复数达到上限
  • 解决问题:重启systemd-logind和 D-Bus系统服务,问题解决
# 重启 logind 服务(会暂时断开现有非活跃会话,不影响已登录的活跃进程)
systemctl restart systemd-logind

# 验证状态(确保无 "pending replies" 错误)
systemctl status systemd-logind

systemctl restart dbus
systemctl status dbus
  • 查以下系统日志,恢复正常
Sep 12 10:37:38 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50510962.scope: The maximum number of pending replies per connection has
Sep 12 10:37:51 zcdb03 systemd-logind[26432]: Failed to start session scope session-c50510963.scope: The maximum number of pending replies per connection has
Sep 12 10:38:01 zcdb03 systemd-logind[26432]: Failed to start session scope session-1439603.scope: The maximum number of pending replies per connection has b
Sep 12 10:38:01 zcdb03 systemd-logind[26432]: Failed to start session scope session-1439602.scope: The maximum number of pending replies per connection has b
Sep 12 10:38:01 zcdb03 systemd-logind[26432]: Failed to start session scope session-1439601.scope: The maximum number of pending replies per connection has b
Sep 12 10:38:25 zcdb03 systemd[1]: Stopping Login Service...
Sep 12 10:38:25 zcdb03 systemd[1]: Stopped Login Service.
Sep 12 10:38:25 zcdb03 systemd[1]: Starting Login Service...
Sep 12 10:38:25 zcdb03 systemd[1]: Started Login Service.
Sep 12 10:38:25 zcdb03 systemd-logind[123743]: New seat seat0.
Sep 12 10:38:25 zcdb03 systemd-logind[123743]: Watching system buttons on /dev/input/event0 (Power Button)
Sep 12 10:38:25 zcdb03 systemd-logind[123743]: New session 635 of user root.

深入解析与解决 “pam_systemd(su-l:session): Failed to create session: No buffer space available” 错误

在Linux系统运维中,我们偶尔会遇到一些看似“资源不足”的错误,但实际根源却并非表面所示。本文将详细分析 “pam_systemd(su-l:session): Failed to create session: No buffer space available” 错误的产生原因、排查过程及彻底解决方案,帮助大家快速定位并解决类似问题。

一、问题现象

1. 错误表现

在执行 su - 用户名(如 su - grid)切换用户时,系统返回如下错误:

pam_systemd(su-l:session): Failed to create session: No buffer space available

但同时,pam_unix 模块提示会话正常打开和关闭(session opened/closed for user),表明用户切换的权限验证通过,但会话创建过程失败。

2. 关联日志

查看系统服务日志(如 systemctl status udsagent.servicejournalctl -u systemd-logind)时,发现类似以下信息:

systemd-logind[xxxx]: Failed to start session scope session-xxxx.scope: The maximum number of pending replies per connection reached

二、原因分析

从错误信息和日志来看,“No buffer space available” 并非传统意义上的内存、磁盘或网络缓冲区不足,而是 systemd 会话管理与 D-Bus 通信限制导致的资源阻塞,具体原因如下:

  1. systemd-logind 服务职责
    systemd-logind 是管理用户会话(登录/注销、会话跟踪)的核心服务,依赖 D-Bus 消息总线与其他组件通信。

  2. D-Bus 消息限制
    D-Bus 是系统进程间通信的核心机制,默认对每个连接的“未处理回复数”(max_pending_replies)有限制(通常为1024)。当高频创建会话(如脚本频繁执行 su 切换用户)时,未处理的消息回复会堆积,超过此限制后,会话创建请求被拒绝,触发“无缓冲区空间”错误。

  3. 会话资源堆积
    长期运行的系统中,大量非活跃会话(如已断开的 su/ssh 会话)未被清理,占用 systemd-logind 管理资源,加剧了上述限制的触发概率。

三、排查过程

1. 排除基础资源不足

首先验证系统是否存在实际的资源瓶颈:

  • 内存与 swapfree -g 显示内存和交换分区充足(本文案例中内存使用率约76%,swap未使用)。
  • 进程数限制ulimit -a 显示 max user processes 为16384,远高于当前进程数(ps aux | wc -l 结果为2628)。
  • 临时文件系统df -h /run 显示 /run(tmpfs)使用率仅3%,无空间不足问题。
  • PID 上限cat /proc/sys/kernel/pid_max 显示上限为458752,远未达到。

结论:基础资源充足,排除物理资源不足导致的错误。

2. 分析会话与服务状态

  • 活跃会话数loginctl list-sessions 显示存在大量历史会话(如 c10991811c54 等),部分为非活跃状态。
  • systemd-logind 日志journalctl -u systemd-logind 频繁出现 “The maximum number of pending replies per connection reached”,表明 D-Bus 未处理回复数达到上限。

结论:错误与 D-Bus 通信限制及会话资源堆积相关。

四、解决过程

1. 临时缓解:重启会话管理服务

重启 systemd-logind 可清除堆积的未处理回复,临时恢复会话创建功能:

# 重启 systemd-logind 服务(不影响数据库等核心进程)
systemctl restart systemd-logind

# 验证状态
systemctl status systemd-logind

重启后,执行 su - grid 测试,错误暂时消失,但高频操作后可能复发。

2. 彻底解决:调整 D-Bus 限制

(1)理解 D-Bus 配置机制

D-Bus 配置文件 /etc/dbus-1/system.conf 已不再推荐直接修改,系统通过 /etc/dbus-1/system.d/ 目录加载自定义配置(优先级更高,且不被系统更新覆盖)。

(2)创建自定义配置文件
# 在 system.d 目录下创建配置文件
vi /etc/dbus-1/system.d/local-pending-replies.conf

添加以下内容(将 max_pending_replies 从默认1024调至8192):

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
  <!-- 提升未处理回复数上限,解决会话创建失败问题 -->
  <limit name="max_pending_replies">8192</limit>
</busconfig>
(3)重启 D-Bus 服务
# 重启 D-Bus 使配置生效
systemctl restart dbus

# 再次重启 systemd-logind 确保依赖更新
systemctl restart systemd-logind

3. 清理无效会话

清除非活跃会话以释放资源:

# 列出所有会话(含非活跃)
loginctl list-sessions --full --all

# 终止指定非活跃会话(替换为实际会话ID)
loginctl terminate-session <SESSION_ID>

# 批量清理所有非活跃会话
loginctl list-sessions --full --all | grep -i inactive | awk '{print $1}' | xargs -I {} loginctl terminate-session {}

五、验证与总结

1. 验证效果

  • 多次执行 su - grid 并退出,模拟高频会话创建:
    for i in {1..10}; do su - grid -c "exit"; done
    
  • 查看日志确认无错误:
    journalctl -u systemd-logind --since "10分钟前" | grep -i "failed"
    
    若日志中无 “pending replies” 或 “No buffer space” 错误,表明问题解决。

2. 问题总结

  • 根本原因:D-Bus 消息总线的 max_pending_replies 限制过低,无法应对高频会话创建场景,导致未处理回复堆积,触发会话创建失败。
  • 关键解决方案:通过自定义 D-Bus 配置提升 max_pending_replies 上限,并清理无效会话释放资源。
  • 注意事项
    • 避免直接修改 /etc/dbus-1/system.conf,应通过 /etc/dbus-1/system.d/ 目录下的自定义文件配置。
    • 重启 dbussystemd-logind 服务对数据库等核心应用无直接影响,但建议在非业务高峰期操作。

通过以上步骤,可彻底解决 “No buffer space available” 错误,确保系统会话管理稳定运行。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐