java.net.UnknownHostException 异常处理(转)
在linux系统下部署Java产品的集群环境时,后台报出如下异常,系统报找不到名为“QATest242”的主机:
ERROR - Get local host name failed -com.trs.infra.cluster.ClusterConfig.getMemberHost(ClusterConfig.java:293)
java.net.UnknownHostException: QATest242: QATest242
at java.net.InetAddress.getLocalHost(InetAddress.java:1353)
at xxxxxxx 产品异常信息
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:701)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:432)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
at org.apache.catalina.core.StandardService.start(StandardService.java:480)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
出错的Java代码:
InetAddress localhost = InetAddress.getLocalHost();
解决办法:
打开linux机器的etc/hosts文件,在文件最后加上下面这句话,重启ekp应用即可
192.9.100.242 cluster242.domain QATest242
192.9.100.242:ip地址
cluster242.domain:第二位为域名
QATest242:主机名称
------------------------------------------
测试方案:
ping 127.0.0.1 可以ping通
ping localhost 不通
说明是主机映射的原因。
解决方法:
修改etc/hosts 文件
[oracle@bogon ~]$ su - root
Password:
[root@bogon ~]# cd ..
[root@bogon /]# cd ..
[root@bogon /]# cd etc
[root@bogon etc]# cat hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 bogon.localdomain bogon
在hosts文件中追加下面一行就OK了:
127.0.0.1 localhost.localdomain localhost
61.191.39.18 szxapp