You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js连接Hive数据库遭遇getaddrinfo ENOTFOUND错误求助

Node.js使用hive-driver连接Hive触发getaddrinfo ENOTFOUND错误排查方案

问题详情

构造了规范的JDBC连接字符串jdbc:hive2://hostname:port/schema_name,但用hive-driver编写的Node.js连接代码始终无法成功连接Hive数据库,触发getaddrinfo ENOTFOUND错误,已排查相关资源未解决问题。

代码示例

const { HiveDriver } = require('hive-driver');

async function connectHive() {
  const driver = new HiveDriver();
  try {
    const connection = await driver.connect({
      host: 'hostname',
      port: port, // 替换为实际端口
      username: 'your_user',
      password: 'your_pwd',
      database: 'schema_name'
    });
    console.log('连接成功');
    await connection.close();
  } catch (err) {
    console.error('连接失败:', err);
  }
}

connectHive();

错误信息

Error: getaddrinfo ENOTFOUND hostname
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)

解决步骤

  • 验证网络连通性:用ping hostname或telnet hostname port测试本地机器能否访问Hive服务器的指定端口,若不通,检查服务器防火墙/安全组是否开放Hive默认端口(通常10000),或直接替换hostname为服务器公网/内网IP尝试。
  • 确认主机名解析:如果用主机名连接失败,手动在本地hosts文件(Linux/macOS为/etc/hosts,Windows为C:\Windows\System32\drivers\etc\hosts)添加[服务器IP] hostname的映射,强制解析。
  • 检查Hive服务状态:登录Hive服务器,执行hive --service hiveserver2 status确认HiveServer2服务是否运行,查看/var/log/hive/hiveserver2.log日志排查服务启动异常。
  • 修正连接参数:hive-driver不需要传入完整JDBC字符串,确保host字段仅填纯主机名/IP,不要带jdbc:hive2://前缀,端口号需为数字类型。
  • 核对认证配置:若Hive启用Kerberos认证,需补充Kerberos相关参数;简单认证模式下确认username和password与Hive配置一致。

内容的提问来源于stack exchange,提问作者vigneshRavi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 23:20:59