本地没问题,但服务器上jar包启动非常慢,即使启动成功,接口也很慢还超时,服务启动时报错,
InetAddress.getLocalHost().getHostName() took 40042 milliseconds to respond. Please verify your network configuration
不多说直接上图
原因
项目中有获取ip的代码,
InetAddress.getLocalHost().getHostAddress()
服务器由于更改过 hostname,没有把修改后的hostname配置到/etc/hosts中,引发的惨案,直接启动时获取 hostname 耗时时间较长
解决
1.查看服务器当前hostname
# hostname
2.编辑 /etc/hosts 文件,发现 /etc/hosts 配置文件中并无 hostname 配置信息
# vim /etc/hosts
3.添加 hostname 添加到 /etc/hosts 配置中,如下所示