ESXi ping 得通但连不上 vCenter?一篇讲透 hostd 假死的全套救法 本文适用版本:ESXi 7.0 U3 / 8.0 U2 / 9.0 GA阅读时长:约 7 分钟难度:⭐⭐(SSH 能进就能修,但要分清是 hostd 还是 vpxd 的锅)一、为什么写这篇文章?最近私信里又陆续收到几位网友问:ESXi 能 ping 通、SSH 也能进、DCUI 也正常,但 vCenter 里主机显示未响应或已断开,重启 ESXi 才能恢复。这个问题最阴险,因为它会让你下意识以为是网络问题(防火墙、端口、vCenter 故障),在错误的方向折腾半天。搜遍全网,要么让你重启 ESXi 试试,要么让你检查 vCenter 证书。今天这篇文章给你一个判断模板,3 分钟定位是 hostd 假死还是别的锅。二、先判断到底是 hostd 的锅,还是别的ESXi 的管理链路里,有 4 个关键进程,必须先定位到具体哪个挂了,不然瞎重启反而把现场破坏了。┌─────────────────────────────────────────────────┐ │ vCenter Server / vSphere Client │ └───────────────────────┬─────────────────────────┘ │ HTTPS:443 ┌───────────────────────▼─────────────────────────┐ │ hostd ← 主机代理进程,管 VM / 存储 / 网络 │ │ vpxa ← vCenter 通信代理 │ │ ntpd ← 时间同步 │ │ DCUI ← 物理机 console 界面 │ └─────────────────────────────────────────────────┘症状对照表(直接对号入座):症状大概率是vCenter 显示主机断开,但 SSH/ping 都通hostd 假死DCUI 进不去,卡黑屏DCUI 进程,不是 hostdSSH 能进但 vmkernel.log 报错 vpxa 超时vpxa假死vCenter 整个挂了,所有 ESXi 都掉线vCenter 端问题,不是 ESXiping 都通,但 SSH 22 端口连不上网络/防火墙问题三、3 秒定位:确认 hostd 状态SSH 进 ESXi,跑下面这条命令:/etc/init.d/hostd status正常输出:hostd is Running假死输出(最常见):hostd is stopped或者状态命令直接卡住不返回——这说明 hostd 进程虽然在,但内部已经死锁,不再接受新的请求。进一步确认:# 看进程是否真的存在(PID) ps | grep hostd # 输出类似: # 12345 hostd-worker ← 正常情况 # 12346 hostd ← 正常情况 # 看 hostd 是否在监听 443 端口 esxcli network ip connection list | grep 443 # 没输出 hostd 已死四、第一道解法:重启 hostd(80% 有效)# 重启 hostd 服务 /etc/init.d/hostd restart重启过程中会发生什么:当前管理连接断开 5–15 秒VM不会中断(VM 由 vmkernel 管,不走 hostd)SSH 会断一次,需要重连vCenter 会在 30–90 秒后自动重连该主机如果 hostd restart 不生效,试这套加强版:# 1. 先停 vpxa(避免重启 hostd 时 vCenter 反复重连) /etc/init.d/vpxa stop # 2. 重启 hostd /etc/init.d/hostd restart sleep 30 # 3. 看 hostd 是否正常起来 /etc/init.d/hostd status # 应该输出 hostd is Running # 4. 再启动 vpxa /etc/init.d/vpxa startvCenter 侧手动重连:vSphere Client → 选中那台 ESXi → 右键 → Connection → Reset五、如果重启 hostd 还不行——深挖根因5.1 看 hostd 日志(必查)# 实时跟踪 hostd 日志(另开一个 SSH 会话) tail -f /var/log/hostd.log # 看最近有没有 OOM、证书错误、磁盘满 grep -E Out of memory|certificate|disk full|ERROR /var/log/hostd.log | tail -50常见 root cause:① 磁盘满了(占假死的 40%)# 看系统盘使用率 df -h | grep -E bootbank|VMFS|devtmpfs # 重点看 /var(日志目录) du -sh /var/log/* | sort -h | tail -10 # 清理 90 天前日志(临时救场) /var/log/clear-old-logs.sh根治:写个定时任务清理旧日志。② 证书过期(占 30%)# 看 hostd 当前证书有效期 openssl x509 -in /etc/vmware/ssl/rui.crt -noout -dates # 输出示例: # notBeforeJan 1 00:00:00 2024 GMT # notAfterDec 31 23:59:59 2024 GMT ← 过期了 # 看 vCenter 端证书是否也过期 echo | openssl s_client -connect vcenter.your.domain:443 2/dev/null | openssl x509 -noout -dates强制重新生成证书:/sbin/generate-certificates.sh /etc/init.d/hostd restart③ VM 数量过多把 hostd 撑爆(占 20%)# 看 hostd 跑了多少线程 ps -eLf | grep hostd | wc -l # 正常:30~80 # 异常:500,基本就是假死前兆 # 看 ESXi 上 VM 总数 vim-cmd vmsvc/getallvms | wc -l # 超过 200 台就要警惕④ NTP 漂移导致 vCenter 认证失败(占 10%)# 看时间漂移 ntpq -p # 看 NTP 服务状态 /etc/init.d/ntpd status六、永久解法:给 hostd 上看门狗ESXi 自带一个轻量级 watchdog,但默认配置很保守。改成自动检测 重启:# 1. 启用 hostd 自愈(ESXi 7.0) esxcli system watchdog enable --watchdogdefaulttimeout120 # 2. 自定义超时时间(秒) esxcli system watchdog set --watchdogtimeout180 # 3. 配置 hostd 失败后自动重启的策略 esxcli system settings advanced set -o /Hostd/autoRestart -i true # 4. 看当前配置 esxcli system watchdog get核心思路:让 ESXi 在 hostd 死后 120 秒自动拉起,避免半夜人工重启。七、防患于未然:监控 告警zabbix 监控项(5 分钟轮询):# zabbix_agentd.conf 自定义键值 UserParameteresxi.hostd.status,/etc/init.d/hostd status | grep -c Running # 0 hostd 挂掉,触发告警 UserParameteresxi.hostd.thread,/bin/ps -eLf | /bin/grep hostd | /usr/bin/wc -l # 超过 300 触发告警PowerCLI 一键巡检脚本(放进定时任务):# 检查所有 ESXi 主机的 hostd 状态 Connect-VIServer vcenter.your.domain -User adminvsphere.local -Password yourpass $report Get-VMHost | ForEach-Object { $esxcli Get-EsxCli -VMHost $_ $status $esxcli.system.hostd.get() [PSCustomObject]{ Host $_.Name HostdStatus $status.Status Version $_.Version Connection $_.ConnectionState } } $report | Format-Table -AutoSize $report | Where-Object { $_.HostdStatus -ne running } | ForEach-Object { Write-Warning $($_.Host) hostd 状态异常:$($_.HostdStatus) } Disconnect-VIServer -Confirm:$false八、速查命令卡(可收藏转发)# 1. 确认 hostd 状态 /etc/init.d/hostd status # 2. 重启 hostd(标准解法) /etc/init.d/hostd restart # 3. 加强版重启(先停 vpxa) /etc/init.d/vpxa stop /etc/init.d/hostd restart sleep 30 /etc/init.d/vpxa start # 4. 看 hostd 日志 tail -f /var/log/hostd.log grep -E Out of memory|certificate|ERROR /var/log/hostd.log | tail -50 # 5. 检查证书 openssl x509 -in /etc/vmware/ssl/rui.crt -noout -dates # 6. 启用 watchdog esxcli system watchdog enable --watchdogdefaulttimeout120 # 7. vCenter 侧手动重连 # vSphere Client → 右键主机 → Connection → Reset