Hdfs连接报错java.net.ConnectException: Connection timed out: no further information


在这里插入图片描述

想学习架构师构建流程请跳转:Java架构师系统架构设计

1 连接超时

在这里插入图片描述

2 排查具体问题

2.1.检查网络能不能ping通,防火墙问题

由于有Hue可以访问,网络没有问题或者看是否连通,因为可能防ping

telnet www.baidu.com 80

2.2 检查zookeeper有没有开启

2.3 最后检查Hue中Hdfs节点挂掉

在这里插入图片描述
最后可以看出上述问题都没有所以大环境是没有错,那就是代码的问题

3 解决方法

问题在于使用本地读取hdfs文件时,服务器datanode使用的是内网进行通信,所以我们把hdfs-site.xml和core-site.xml文件导入到Idea中时,需要修改hdfs-site.xml中的以下配置:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<property>
		<name>dfs.namenode.name.dir</name>
		<value>/opt/hdfs/namenode</value>
		<description>NameNode directory for namespace and transaction logs storage.</description>
	</property>
	<property>
		<name>dfs.datanode.data.dir</name>
		<value>/opt/hdfs/datanode</value>
		<description>DataNode directory</description>
	</property>
	<property>
		<name>dfs.replication</name>
		<value>2</value>
	</property>
	<property>
		<name>dfs.permissions</name>
		<value>false</value>
		<description>need not permissions</description>
	</property>
	<property>
		<name>dfs.webhdfs.enabled</name>
		<value>true</value>
	</property>
	<property>
		<name>dfs.datanode.max.xcievers</name>
		<value>4096</value>
	</property>
	<property>
		<name>dfs.client.use.datanode.hostname</name>
		<value>true</value>
	</property>
</configuration>

在这里插入图片描述

### 解决 Java 中 `ConnectException` 连接被拒绝的问题 对于遇到的 `java.net.ConnectException: Connection refused` 异常,在处理 Java Sentinel 或其他应用程序时,可以采取一系列措施来排查并解决问题。 #### 验证主机和端口配置准确性 确认所使用的主机名或 IP 地址以及端口号是否正确无误。例如 `[127.00.1:8080]` 可能存在书写上的误差,应更正为标准形式如 `127.0.0.1:8080`[^1]。 #### 检查目标服务状态 确保目标服务器已经正常启动并且正在监听预期的端口。可以通过命令行工具如 `netstat -an | grep <port>` 来验证特定端口上是否有进程在监听。如果发现没有相应的监听记录,则说明该服务可能未成功启动或是未能绑定到指定端口[^2]。 #### 排除网络障碍因素 考虑是否存在防火墙或其他网络安全策略阻止了连接请求。尝试临时禁用本地系统的防火墙设置以测试这是否会消除问题;另外也要注意云平台安全组规则等外部限制条件的影响[^3]。 #### 审视客户端代码逻辑 如果是自定义开发的应用程序(比如基于 Socket 编程),则需要注意 bind() 方法调用方式的选择——即采用不含 host 参数的形式 (`new InetSocketAddress(port)`), 而不是带具体地址版本(`new InetSocketAddress(host, port)`) ,除非确实需要限定仅允许来自某固定源IP 的接入[^4]. 针对 **Sentinel** 特定场景: - 对于使用 Nacos 作为注册中心的情况,请务必保证 `config.server-addr` 和实际部署环境中的 nacos server address 设置相匹配,并且指向有效的可达位置[^5]. ```properties spring.cloud.nacos.discovery.server-addr=192.168.1.100:8848 ``` - 如果涉及到了 Hadoop 生态圈内的组件交互(尽管不太常见),还需留意相关配置文件(hdfs-site.xml 等)里关于 Web UI 访问路径及默认开放端口的规定,防止因权限不足而导致无法建立有效链接. 最后提醒一点:当面对此类连通性难题时,建议逐步缩小范围定位根本原因所在,先从最基础层面入手逐一排除干扰项直至最终找到症结所在为止.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赵广陆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值