服务器上tomcat启动时,报如下错误:
15:28:06,605 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:28:06,607 |-ERROR in ch.qos.logback.core.util.ContextUtil@715ea69f - Failed to get local hostname java.net.UnknownHostException: TW-LG-AICLOUD-APP1: TW-LG-AICLOUD-APP1
at java.net.UnknownHostException: TW-LG-AICLOUD-APP1: TW-LG-AICLOUD-APP1
at at java.net.InetAddress.getLocalHost(InetAddress.java:1354)
at at ch.qos.logback.core.util.ContextUtil.getLocalHostName(ContextUtil.java:32)
at at ch.qos.logback.core.util.ContextUtil.addHostNameAsProperty(ContextUtil.java:41)
at at ch.qos.logback.classic.joran.action.ConfigurationAction.begin(ConfigurationAction.java:56)
at at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:276)
at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:148)
at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:130)
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:157)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:143)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:106)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:56)
at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
at at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
按网上的说法,修改/etc/hosts文件就可以了,我把/etc/hosts文件改为如下:
127.0.0.1 TW-LG-AICLOUD-APP1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.250. TW-LG-AICLOUD-APP1
同时,/etc/sysconfig/network中的HOSTNAME的值也为TW-LG-AICLOUD-APP1,修改完后,重启网卡,再重启tomcat
服务,发现还是报错。看了下别的服务器,别的服务器也是这样配置的。后面一想,会不会是TW-LG-
AICLOUD-APP1太长、或者有分隔符,所以换了个简短的主机名,修改为简单的主机名后,还是不行。
后面试了下用hostname myhostname修改主机名,重启tomcat,发现生效了。
因服务器不能随便重启,估计是因为修改/etc/sysconfig/network和/etc/hosts文件,需要重启机器才能生效。
而直接用命令修改,是不需要重启服务器的。但是重启后,会以配置文件的为准。