客户在TaiShan服务器上移植业务,反馈获取本机ip,耗时最长40s
问题描述:
客户在泰山移植业务,反馈获取本机ip,单纯执行Inet4Address.getLocalHost().getHostAddress(); 耗时最长到了40s。
定位过程:
初步怀疑与反向域名解析有关,在实验室通过getHostAddress.java测试代码验证,代码如下
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class getHostAddress {
public static void main(String[] args) {
InetAddress address = null;
try {
address = InetAddress.getLocalHost();
System.out.println(address);
} catch (UnknownHostException e) {
e.printStackTrace();
}
System.out.println(address.getHostAddress());
}
}
1. 执行javac getHostAddress.java; time java getHostAddress
2. 执行时间要10s
3. 将本机名增加到/etc/hosts中,格式如下
[root@host194 pci_bus]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
30.30.3.202 host192
30.30.3.203 host193
30.30.3.204 host194
30.30.3.205 host195
30.30.3.206 clouderamanager-01
4. 执行上面的操作后执行如下命令,以便上面修改生效
systemctl restart network.service
3)再执行java getHostAddress,确认问题解决
问题原因:
本机名未配置在/etc/hosts上,程序在获取本机ip地址,触发地址反向解析,反向解析超时
解决办法:
将本机名增加到/etc/hosts中
- 点赞
- 收藏
- 关注作者
评论(0)