目 录CONTENT

文章目录

【GaussDB】排查TPOPS添加主机报错"Hostkey has been changed"的问题

DarkAthena
2026-11-29 / 0 评论 / 0 点赞 / 6 阅读 / 0 字

【GaussDB】排查TPOPS添加主机报错"Hostkey has been changed"的问题

背景

近期有项目在TPOPS(26.861.0)上添加主机,遇到"Hostkey has been changed"这个报错。

[2026-11-27 18:25:12.446][ERROR][gaussdb][pool-39-thread-172]
[com.huawei.hwclouds.nebula.universal.tool.ssh.SSHSessionFactory.create(SSHSessionFactory.java:40)]
[18c10810-bb3d-4269-4193-abb7fe1571aa][][ssh client login has some error.]

com.huawei.hwclouds.dbss.common.exception.V2.DBSExceptionV2: Hostkey has been changed: [xxx.xxx.xxx.xxx]:22
        at com.huawei.hwclouds.dbss.common.exception.V2.DBSExceptionV2.from(DBSExceptionV2.java:45)
        at com.huawei.hwclouds.dbss.common.exception.V2.DBSExceptionV2.from(DBSExceptionV2.java:57)
        at com.huawei.hwclouds.nebula.universal.tool.ssh.SSHClient.processJschException(SSHClient.java:597)
        at com.huawei.hwclouds.nebula.universal.tool.ssh.SSHClient.login(SSHClient.java:201)
        at com.huawei.hwclouds.nebula.universal.tool.ssh.SSHSessionFactory.create(SSHSessionFactory.java:37)
        at com.huawei.hwclouds.nebula.universal.tool.ssh.SSHSessionFactory.create(SSHSessionFactory.java:14)
        at com.huawei.hwclouds.nebula.universal.tool.ssh.SSHClientPool.getClient(SSHClientPool.java:47)
        at com.huawei.hwclouds.nebula.hcs.feature.hosttools.wfs.task.NebulaBuildSSHSessionTask.perform(NebulaBuildSSHSessionTask.java)

回忆了下,似乎不是第一次遇到,翻了下历史博客和MES案例,没找到,于是找了下历史的工作记录,果然找到了

20260206 分析类生产环境一台GaussDB主机重装后,tpops 25.1.30.10无法添加的问题(报错 HOSTKEY HAS BEEN CHANGED ,文档搜不到,在tpops元库里全库搜索主机ip,找到dbs_known_host表里存在记录,删除即可)

当时似乎没给华为反馈。

这次遇到相同报错,起因也类似,是在tpops平台删除主机后,主机作为虚拟机进行了移动,然后重新添加,指纹发生了变化,ssh失败,导致主机添加失败。

其实就这么几句话,问题原因就这么说清楚了,但是我还是想说下第一次排查这个问题的经过。

分析

首先熟悉ssh连接的人,应该知道"Hostkey has been changed"这个表示什么含义,出现这个需要满足两个前提条件

  1. A对B发起过ssh连接,并接受了指纹保存
  2. B的指纹由于某种原因发生了变化,A重新对B发起ssh连接

此时A无法连接到B,并且提示 B的 "Hostkey has been changed"。
该问题的常规处理方式就是,在A的 .ssh/known_hosts文件里,删除B的那条记录,然后重连即可。

然而,当时在TPOPS的known_hosts里,并未发现添加报错的主机IP。

而且,这个是走java进行的ssh连接,hostkey不一定在操作系统上,可能在tpops的元库里。

于是,我写了个匿名块,对tpops的元库,使用添加报错的主机ip做了个全库搜索

declare
x int;
v_sql text;
begin
for rec in (select relname,n.nspname from pg_class c,pg_namespace n where c.relkind='r' and relnamespace=n.oid and nspowner<>'10') loop
v_sql:='select count(1) from '||rec.nspname||'.'||rec.relname||' t where t::text ilike ''%192.168.163.213%'' ';
execute v_sql into x;
if x>0 then
raise notice '%,%,%',rec.relname,x,v_sql;
end if;
end loop;
end;

返回了下面4个表包含这个ip

NOTICE:  dbs_nic,3,select count(1) from core.dbs_nic t where t::text ilike '%192.168.163.213%'
NOTICE:  dbs_endpoint,1,select count(1) from core.dbs_endpoint t where t::text ilike '%192.168.163.213%'
NOTICE:  dbs_known_host,1,select count(1) from core.dbs_known_host t where t::text ilike '%192.168.163.213%'
NOTICE:  dbs_host_static_info,3,select count(1) from core.dbs_host_static_info t where t::text ilike '%192.168.163.213%'

从表名,一眼就能看出dbs_known_host这个表相当可疑。

core=> select * from dbs_known_host where ip='192.168.163.213';
-[ RECORD 1 ]+---------------------------------------------------------------------
id           | 069f92e6-8ea1-4fdd-a545-fe747485c4f3
ip           | 192.168.163.213
created_at   | 2026-02-06 08:16:46.874
updated_at   | 2026-02-06 08:16:46.874
algorithms   | ssh-ed25519
fingerprint  | *********************************
extend_field |
port         | 22

果然在这里存了主机指纹,而这台机在tpops平台页面上是已经找不到了的,也没有状态标记,主机从平台删了后,这里还留着,导致了下次添加主机时,又用了这个指纹去连接。也就是说,tpops平台要么在删除主机的时候删除这条记录,要么就在添加主机的时候,把这里的指纹给更新掉。然而这两种处理方式,tpops平台都没有做到。

临时解决方案

1. 手动清理残留记录再重新添加(在TPOPS管理库 core 执行,用户 core)

-- 确认残留记录并留存 algorithms / fingerprint
select ip, port, algorithms, fingerprint, created_at, updated_at
from dbs_known_host
where ip = 'xxx.xxx.xxx.xxx' and port = 22;

-- 删除残留记录
delete from dbs_known_host
where ip = 'xxx.xxx.xxx.xxx' and port = 22;

-- 确认清理结果
select count(*) from dbs_known_host where ip = 'xxx.xxx.xxx.xxx';

在平台重新执行"添加主机"。首次连接查不到记录,将直接信任并写入新记录,不再触发校验失败。

验证:

-- 应出现一条新记录,algorithms / fingerprint 为新主机值,created_at 为本次操作时间
select ip, port, algorithms, left(fingerprint, 40) as key_head, created_at, updated_at
from dbs_known_host
where 'xxx.xxx.xxx.xxx' and port = 22;
日志确认:
  "start to login host, hostIP is xxx.xxx.xxx.xxx ..." → "login host success."
  不再出现 "add ssh session to pool has some error."

2. 备选方案1 (这个方法是同事发现的)
在添加主机失败后,在主机列表操作重置主机,再删除主机,重新添加。

3. 备选方案2(不推荐)
手动获取该机器最新的指纹,更新到tpops的dbs_known_host表里去:

ssh-keyscan -p 22 xxx.xxx.xxx.xxx
update dbs_known_host
set fingerprint = '<base64 key>', algorithms = '<key type>'
where 'xxx.xxx.xxx.xxx' and port = 22;

要求 algorithms(ssh-rsa / ecdsa-sha2-nistp256 / ssh-ed25519)与 fingerprint(base64 公钥体)及拼接格式完全匹配,易再次报错,优先采用第 1 步删除重建。

总结

本次故障链:

  1. 主机首次纳管,dbs_known_host 写入原 host key。
  2. 在 TPOPS 平台删除该主机,正常应触发 NebulaDeleteHostKnownHostTask → ManageHostRecodeDBUtil.deleteHostKnownHost → NebulaKnownHostDao.deleteKnownHostByIp 清理记录,实际未生效,记录残留。
  3. 主机作为虚拟机迁移/重建,IP 复用,但 SSH host key 已重新生成(或已变为另一台 VM 的 key)。
  4. 重新添加主机:按 ip + port 查到旧记录,用旧 key 校验新服务端 key,不一致 → HostKey has been changed → DBSExceptionV2 → 添加主机失败。

临时修复方案:删除dbs_known_host中对应ip的记录
长期方案:等华为修复改BUG,升级TPOPS

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin
博主关闭了所有页面的评论