启动hive常见错误之-----RuntimeException: java.net.NoRouteToHostException:没有到主机的路由

本文记录了一次Hive启动过程中遇到的NoRouteToHostException错误及其解决过程。通过关闭防火墙服务,成功解决了因网络连接问题导致的Hive无法正常启动的问题。

[hadoop@h3 bin]$ hive

which: no hbase in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/modules/jdk1.8.0_181/bin:/opt/modules/hadoop-2.7.6/sbin:/opt/modules/hadoop-2.7.6/bin:/opt/modules/hive-2.3.3/bin:/home/hadoop/.local/bin:/home/hadoop/bin)

Logging initialized using configuration in jar:file:/opt/modules/hive-2.3.3/lib/hive-common-2.3.3.jar!/hive-log4j2.properties Async: true
Exception in thread "main" java.lang.RuntimeException: java.net.NoRouteToHostException: No Route to Host from  h3/192.168.113.103 to h1:9000 failed on socket timeout exception: java.net.NoRouteToHostException: 没有到主机的路由; For more details see:  http://wiki.apache.org/hadoop/NoRouteToHost
    at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:606)
    at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:549)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:750)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:686)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.net.NoRouteToHostException: No Route to Host from  h3/192.168.113.103 to h1:9000 failed on socket timeout exception: java.net.NoRouteToHostException: 没有到主机的路由; For more details see:  http://wiki.apache.org/hadoop/NoRouteToHost
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.apache.hadoop.net.NetUtils.wrapWithMessage(NetUtils.java:792)
    at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:758)
    at org.apache.hadoop.ipc.Client.call(Client.java:1480)
    at org.apache.hadoop.ipc.Client.call(Client.java:1413)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:229)
    at com.sun.proxy.$Proxy29.getFileInfo(Unknown Source)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getFileInfo(ClientNamenodeProtocolTranslatorPB.java:776)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:191)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
    at com.sun.proxy.$Proxy30.getFileInfo(Unknown Source)
    at org.apache.hadoop.hdfs.DFSClient.getFileInfo(DFSClient.java:2117)
    at org.apache.hadoop.hdfs.DistributedFileSystem$22.doCall(DistributedFileSystem.java:1305)
    at org.apache.hadoop.hdfs.DistributedFileSystem$22.doCall(DistributedFileSystem.java:1301)
    at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
    at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1317)
    at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1425)
    at org.apache.hadoop.hive.ql.session.SessionState.createRootHDFSDir(SessionState.java:704)
    at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:650)
    at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:582)
    ... 9 more
Caused by: java.net.NoRouteToHostException: 没有到主机的路由
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:531)
    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:495)
    at org.apache.hadoop.ipc.Client$Connection.setupConnection(Client.java:615)
    at org.apache.hadoop.ipc.Client$Connection.setupIOstreams(Client.java:713)
    at org.apache.hadoop.ipc.Client$Connection.access$2900(Client.java:376)
    at org.apache.hadoop.ipc.Client.getConnection(Client.java:1529)
    at org.apache.hadoop.ipc.Client.call(Client.java:1452)
    ... 29 more

考虑是防火墙没有关:

执行:

systemctl stop firewalld
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password:
==== AUTHENTICATION COMPLETE ===

再次启动:如下显示即ok了

[hadoop@h3 bin]$ hive
which: no hbase in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/modules/jdk1.8.0_181/bin:/opt/modules/hadoop-2.7.6/sbin:/opt/modules/hadoop-2.7.6/bin:/opt/modules/hive-2.3.3/bin:/home/hadoop/.local/bin:/home/hadoop/bin)

Logging initialized using configuration in jar:file:/opt/modules/hive-2.3.3/lib/hive-common-2.3.3.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive>

 

 

 

 

 

<think>好的,我现在要解决用户提出的Java程序中出现的`java.net.NoRouteToHostException`异常,特别是“没有主机路由”问题以及发送失败的错误。首先,我需要理解这个异常的具体原因和可能的解决方法。 根据用户提供的引用信息,特别是引用[3]和[4],这个问题通常与网络连接有关,比如主机之间的路由问题、防火墙设置、主机名解析等。虽然这些引用主要提到了Hadoop和Hive环境中的情况,但同样适用于一般的Java网络应用。因此,我需要将这些信息综合起来,并结合常见的网络故障排查步骤来形成一个解决方案。 首先,用户提到“没有主机路由”,这可能意味着目标主机不可达。可能的原因包括: 1. **网络连接问题**:物理连接断开,路由器配置错误等。 2. **防火墙或安全组设置**:防火墙可能阻止了特定端口的通信。 3. **主机名解析错误**:DNS配置问题或`/etc/hosts`文件中的条目不正确。 4. **目标服务未运行**:目标主机上的服务没有启动,或者在指定端口上监听。 5. **路由问题**:网络路由配置错误,导致数据包无法到达目标主机。 接下来,我需要根据这些可能的原因,列出具体的检查步骤。例如,首先检查基本的网络连通性,使用`ping`和`telnet`命令测试主机和端口的可达性。然后检查防火墙设置,确保相关端口是开放的。此外,确认主机名和IP的映射是否正确,特别是在使用主机名进行连接的情况下。同时,需要确认目标主机上的服务是否正常运行,并监听正确的端口。 另外,引用[1]和[2]提到在Java代码中捕获异常并进行处理,但这只是异常处理的一部分,不能解决根本问题。因此,解决方案应侧重于网络配置和环境检查,而不仅仅是代码层面的处理。 需要注意的是,用户可能是在不同的环境中遇到这个问题,比如本地开发环境、云部署(如OpenShift,引用[2]提到的),或者分布式系统(如Hadoop集群,引用[3][4])。不同的环境可能需要不同的检查步骤,但核心的网络排查方法是通用的。 此外,用户提到“发送失败”,这可能意味着在尝试建立连接或发送数据时失败。因此,除了检查网络连通性,还需要确认发送的数据是否符合目标服务的预期格式,以及是否有足够的权限进行通信。 最后,需要将解决方案分步骤清晰地呈现,确保用户能够逐步排查问题。同时,可能还需要提供一些具体的命令示例,如如何检查防火墙状态,如何测试端口连通性等,以帮助用户实际操作。 总结起来,解决方案应包括以下几个步骤: 1. 检查网络连通性(ping目标主机)。 2. 检查目标端口是否开放(使用telnet或nc)。 3. 验证主机名解析是否正确。 4. 检查本地和远程防火墙设置。 5. 确认目标服务正在运行并监听正确端口。 6. 检查路由配置(如需要)。 7. 处理代码中的异常并提供有意义的错误信息。 确保每个步骤都有具体的操作指南,并参考引用中的相关信息,比如关闭防火墙或配置主机文件。同时,提醒用户根据不同的环境调整步骤,比如云服务可能需要检查安全组设置。</think>针对$java.net.NoRouteToHostException$异常中“没有主机路由”问题,可通过以下步骤系统排查: --- ### 一、基础网络连通性检查 1. **验证目标主机可达性** ```bash ping 目标主机IP/域名 ``` - 若不通:检查物理网络、路由器配置或云平台安全组规则[^2][^3] - 若使用主机名:需检查`/etc/hosts`文件是否包含正确的主机-IP映射[^3][^4] 2. **测试目标端口连通性** ```bash telnet 目标主机IP 端口号 # 或使用 nc -zv 目标主机IP 端口 ``` - 若连接失败:说明端口被拦截或服务未启动[^4] --- ### 二、防火墙与安全策略 1. **本地防火墙检查** ```bash systemctl status firewalld # CentOS ufw status # Ubuntu ``` - 关闭防火墙:`systemctl stop firewalld`(临时)或`systemctl disable firewalld`(永久)[^3][^4] 2. **云平台安全组规则** - 确认入站/出站规则允许目标端口通信(如OpenShift等云环境需特别检查)[^2] --- ### 三、服务状态与路由配置 1. **确认目标服务状态** ```bash netstat -tuln | grep 端口号 # 检查目标主机服务是否监听端口 ``` 2. **路由追踪排查** ```bash traceroute 目标主机IP # Windows使用tracert ``` - 观察数据包在哪个节点丢失,定位网络中断位置 --- ### 四、代码层处理建议 ```java try { // 网络连接代码(如Socket/HttpURLConnection) } catch (NoRouteToHostException e) { System.err.println("网络路由异常:" + e.getMessage()); // 提示用户检查网络配置或联系管理员[^1] } ``` --- ###
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值