问题描述
启动 DubboX 应用时报错:
[WARN ]-[2016-08-02 10:47:15]-[com.alibaba.dubbo.config.AbstractConfig:305]:[DUBBO] my_host_name: my_host_name: unknown error, dubbo version: 2.8.4, current host: 127.0.0.1
java.net.UnknownHostException: my_host_name: my_host_name: unknown error
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:303)
at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:285)
at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:246)
at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:145)
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:110)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:96)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:948)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.alibaba.dubbo.container.spring.SpringContainer.start(SpringContainer.java:50)
at com.alibaba.dubbo.container.Main.main(Main.java:80)
at net.xxx.xxx.Server.main(Server.java:33)
Caused by: java.net.UnknownHostException: my_host_name: unknown error
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
... 14 more
排查解决
在这台服务器上执行 hostname
命令,正常返回了主机名,然后 ping 这个主机名报错:ping: unknown host my_host_name
,使用 hostname -i
(通过主机名解析 IP 地址)时也会报错:
- CentOS:
hostname: Unknown host
- Ubuntu:
hostname: Name or service not known
该问题是由于通过主机名解析不到 IP 引起的,前段时间曾经修改过主机名,但是没改全:除了执行 hostname my_host_name
外还需要执行:
- CentOS:需要修改 /etc/sysconfig/network 中的 HOSTNAME 配置项
- Ubuntu:需要修改 /etc/hostname
改完后重启就好了 😄 ,如果不方便重启,也可以把新的主机名先加在 /etc/hosts 里面,通过“本地 DNS”进行解析吧。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于