[记录]解决 Nginx 在宝塔面板中启动失败的问题分析与解决方案

[记录]解决 Nginx 在宝塔面板中启动失败的问题分析与解决方案

问题描述:

在使用宝塔面板管理 Nginx 服务过程中,遇到了服务突然停止的问题。日志显示大量的 close() channel failed (9: Bad file descriptor) 以及 worker process exited on signal 9 错误。此外,还出现了 fork() failed while spawning "worker process" (12: Cannot allocate memory),表明系统内存不足,无法创建新的工作进程。

2024/04/14 03:38:04 [alert] 2341#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:04 [alert] 2341#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:04 [alert] 6197#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:04 [alert] 6193#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:04 [alert] 6199#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:04 [alert] 6192#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:02 [alert] 6238#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:04 [alert] 6239#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:05 [alert] 6238#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:05 [alert] 6239#0: close() channel failed (9: Bad file descriptor)
2024/04/14 03:38:10 [alert] 2341#0: worker process 6238 exited on signal 9
2024/04/14 03:38:20 [alert] 2341#0: worker process 6192 exited on signal 9
2024/04/14 03:38:31 [alert] 2341#0: worker process 6197 exited on signal 9
2024/04/14 03:38:40 [alert] 2341#0: worker process 6346 exited on signal 9
2024/04/14 03:38:51 [alert] 2341#0: worker process 6357 exited on signal 9
2024/04/14 03:39:05 [alert] 2341#0: worker process 6199 exited on signal 9
2024/04/14 03:39:07 [alert] 2341#0: worker process 6311 exited on signal 9
2024/04/14 03:39:14 [alert] 2341#0: worker process 6193 exited on signal 9
2024/04/14 03:39:14 [alert] 2341#0: worker process 6397 exited on signal 9
2024/04/14 03:39:28 [alert] 2341#0: worker process 6239 exited on signal 9
2024/04/14 03:39:28 [alert] 2341#0: worker process 6417 exited on signal 9
2024/04/14 03:39:31 [alert] 2341#0: worker process 6416 exited on signal 9
2024/04/14 03:39:37 [alert] 2341#0: worker process 6423 exited on signal 9
2024/04/14 03:39:39 [alert] 2341#0: worker process 6424 exited on signal 9
2024/04/14 03:39:42 [alert] 2341#0: worker process 6429 exited on signal 9
2024/04/14 03:39:44 [alert] 2341#0: worker process 6330 exited on signal 9
2024/04/14 03:39:44 [alert] 2341#0: worker process 6432 exited on signal 9
2024/04/14 03:39:56 [alert] 2341#0: worker process 6374 exited on signal 9
2024/04/14 03:40:06 [alert] 2341#0: worker process 6486 exited on signal 9
2024/04/14 03:40:20 [alert] 2341#0: worker process 6467 exited on signal 9
2024/04/14 03:42:47 [alert] 2341#0: worker process 6433 exited on signal 9
2024/04/14 03:43:37 [alert] 2341#0: worker process 6523 exited on signal 9
2024/04/14 03:47:58 [alert] 2341#0: worker process 6538 exited on signal 9
2024/04/14 03:48:07 [alert] 2341#0: worker process 6389 exited on signal 9
2024/04/14 03:50:06 [alert] 2341#0: worker process 6463 exited on signal 9
2024/04/14 03:52:28 [alert] 2341#0: worker process 6883 exited on signal 9
2024/04/14 03:53:40 [alert] 2341#0: worker process 7715 exited on signal 9
2024/04/14 03:55:57 [alert] 2341#0: worker process 6970 exited on signal 9
2024/04/14 03:55:57 [alert] 2341#0: fork() failed while spawning "worker process" (12: Cannot allocate memory)
2024/04/14 03:55:57 [alert] 2341#0: could not respawn worker process
2024/04/14 04:48:32 [alert] 2341#0: worker process 8472 exited on signal 9
2024/04/14 04:48:32 [alert] 2341#0: close() channel failed (9: Bad file descriptor)
2024/04/14 04:48:32 [alert] 2341#0: close() channel failed (9: Bad file descriptor)
2024/04/14 04:48:32 [alert] 2356#0: close() channel failed (9: Bad file descriptor)
2024/04/14 04:48:32 [alert] 7853#0: close() channel failed (9: Bad file descriptor)
2024/04/14 04:48:32 [alert] 7730#0: close() channel failed (9: Bad file descriptor)
2024/04/14 04:48:32 [alert] 8237#0: close() channel failed (9: Bad file descriptor)
2024/04/14 04:48:32 [alert] 6466#0: close() channel failed (9: Bad file descriptor)

问题原因:

  1. Nginx防火墙与加速插件冲突:安装的免费防火墙插件和网络加速工具可能与 Nginx 的某些配置或其他插件发生冲突,导致资源管理异常。

  2. 文件描述符泄露:频繁的 Bad file descriptor 错误提示可能是因为文件描述符被不当处理或泄露,导致 Nginx 无法正常关闭旧的连接或开启新的连接。

  3. 内存不足Cannot allocate memory 错误表明 Nginx 在尝试创建新的工作进程时,因系统可用内存不足而失败。

解决方案:

  1. 卸载或禁用冲突插件

    • 根据问题描述,首先尝试卸载或禁用 Nginx 的防火墙插件和网站加速插件,观察是否能恢复 Nginx 的正常运行。

    • 如果确定是这些插件导致的冲突,考虑查找其他兼容性更好的插件或更新这些插件到最新版本。

  2. 检查和优化内存使用

    • 通过命令 free -m 检查当前系统的内存使用情况。

    • 如果内存确实不足,尝试增加物理内存或配置交换空间来缓解内存压力。

    • 优化 Nginx 的配置,比如调整 worker_processesworker_connections,减少内存使用。

  3. 检查文件描述符限制

    • 使用 ulimit -n 检查当前的文件描述符限制。

    • 如果数值较低,可以在系统级别增加文件描述符的限制。编辑

      /etc/security/limits.conf

      文件,增加如下配置:

      markdownCopy code* soft nofile 65535
      * hard nofile 65535
    • 重新启动宝塔面板和 Nginx 服务,以应用更改。

  4. 查看详细日志

    • 检查 Nginx 的错误日志(通常位于 /var/log/nginx/error.log),获取更多关于错误的具体信息。

    • 根据日志中的详细错误描述,进一步分析和解决问题。

  5. 重新启动 Nginx

    • 在做出上述更改后,尝试重新启动 Nginx 服务,检查服务是否能够正常运行。

结论

这种类型的错误通常涉及到资源管理和软件冲突。通过逐步排查和应用上述解决方案,通常可以恢复 Nginx 的正常运行并防止未来类似的问题发生。如果问题依旧存在,建议深入查看系统日志或寻求专业技术支持。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
技术教程技术运维

CVE-2024-3094:XZ Utils后门威胁Linux系统安全及应对方案

2024-4-8 11:03:29

技术教程

源支付V8主站安装教程

2024-4-15 17:30:38

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索