Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Nagios NRPE 進程啟動失敗排查:xinetd 端口佔用問題

編輯:Linux 教學

問題現象

Nagios 伺服器 IP 變更後,更新客戶端配置仍無法監控。發現 NRPE 進程無法啟動,5666 端口被佔用。

排查步驟

1. 檢查端口佔用

# netstat -anp | grep 5666
tcp  0  0 :::5666 :::* LISTEN 2036/xinetd

發現 xinetd (PID 2036) 佔用了 NRPE 預設端口 5666。

2. 終止佔用進程

# kill -9 2036

3. 驗證端口釋放

# netstat -anp | grep 5666
# (無輸出,表示端口已釋放)

4. 啟動 NRPE 進程

# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

5. 確認進程運行

# ps -ef | grep nrpe
nagios 2128 1 0 10:34 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

根本原因分析

  • xinetd 超級守護進程:透過 /etc/xinetd.d/nrpe 管理 NRPE,若配置啟用會綁定 5666 端口
  • 獨立模式衝突:NRPE 以 -d 獨立模式啟動時,會嘗試綁定同一端口,導致衝突
  • IP 變更觸發:伺服器遷移後,客戶端 nrpe.cfg 中 allowed_hosts 未同步更新,或 xinetd 配置殘留

永久解決方案

方案 A:使用 xinetd 管理 (推薦生產環境)

# /etc/xinetd.d/nrpe
service nrpe
{
    flags           = REUSE
    socket_type     = stream
    port            = 5666
    wait            = no
    user            = nagios
    group           = nagios
    server          = /usr/local/nagios/bin/nrpe
    server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
    log_on_failure  += USERID
    disable         = no
    only_from       = 192.168.1.100  # Nagios 伺服器 IP
}
service xinetd restart

方案 B:純獨立模式 (停用 xinetd)

# 禁用 xinetd 中的 nrpe
sed -i 's/disable\s*=\s*no/disable = yes/' /etc/xinetd.d/nrpe
service xinetd reload

# 使用 systemd 管理獨立 NRPE
# /etc/systemd/system/nrpe.service
[Unit]
Description=Nagios NRPE
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl enable nrpe
systemctl start nrpe

預防措施

  1. 部署自動化腳本同步更新 allowed_hosts 与 only_from
  2. 監控 5666 端口狀態,佔用異常即時告警
  3. 使用配置管理工具 (Ansible, SaltStack) 確保一致性
  4. 文檔化 NRPE 部署架構:xinetd vs 獨立模式

端口衝突是服務遷移常見問題,系統化排查與標準化部署模式能有效避免重複踩坑。

Copyright © Windows教程網 All Rights Reserved