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