我们有一个通过 EBS(在 tomcat 上)部署的应用程序,时不时地收到一个错误:
unable to resolve host ip-172-30-0-167
这会导致其他问题。据我所知,解决此问题的方法之一是更新主机文件并使用指向ip-172-30-0-167
服务器真实 IP 地址的条目。
我的问题是,如何在部署时向主机文件添加条目?我没有通过 .ebsextensions 找到任何与之相关的内容。
也许还有另一种方法可以解决它。
更新
我遇到的问题之一是发送电子邮件:
ERROR g.plugins.mail.MailMessageBuilder: Failed to send email
Jan 27 15:40:30 unknown staging: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: 501 Syntax: EHLO hostname
Jan 27 15:40:30 unknown staging: . Failed messages: javax.mail.MessagingException: 501 Syntax: EHLO hostname
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:417) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSender$send$0.call(Unknown Source) ~[na:na]
Jan 27 15:40:30 unknown staging: at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at grails.plugins.mail.MailMessageBuilder$_sendMessage_closure1.doCall(MailMessageBuilder.groovy:124) [mail-2.0.0.RC6.jar:na]
Jan 27 15:40:30 unknown staging: at grails.plugins.mail.MailMessageBuilder$_sendMessage_closure1.doCall(MailMessageBuilder.groovy) [mail-2.0.0.RC6.jar:na]
Jan 27 15:40:30 unknown staging: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.Closure.call(Closure.java:426) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.Closure.call(Closure.java:420) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.Closure.run(Closure.java:507) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Jan 27 15:40:30 unknown staging: Caused by: javax.mail.MessagingException: 501 Syntax: EHLO hostname
Jan 27 15:40:30 unknown staging: at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481) ~[mail-1.4.1.jar:1.4.1]
Jan 27 15:40:30 unknown staging: at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:917) ~[mail-1.4.1.jar:1.4.1]
Jan 27 15:40:30 unknown staging: at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:417) ~[mail-1.4.1.jar:1.4.1]
Jan 27 15:40:30 unknown staging: at javax.mail.Service.connect(Service.java:345) ~[javax.mail-api-1.5.1.jar:1.5.1]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:486) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:406) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: ... 22 common frames omitted
Jan 27 15:40:30 unknown staging: ERROR g.plugins.mail.MailMessageBuilder: Failed to send email
Jan 27 15:40:30 unknown staging: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: 501 Syntax: EHLO hostname
Jan 27 15:40:30 unknown staging: . Failed messages: javax.mail.MessagingException: 501 Syntax: EHLO hostname
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:417) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSender$send$0.call(Unknown Source) ~[na:na]
Jan 27 15:40:30 unknown staging: at grails.plugins.mail.MailMessageBuilder$_sendMessage_closure1.doCall(MailMessageBuilder.groovy:124) [mail-2.0.0.RC6.jar:na]
Jan 27 15:40:30 unknown staging: at grails.plugins.mail.MailMessageBuilder$_sendMessage_closure1.doCall(MailMessageBuilder.groovy) [mail-2.0.0.RC6.jar:na]
Jan 27 15:40:30 unknown staging: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.Closure.call(Closure.java:426) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.Closure.call(Closure.java:420) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at groovy.lang.Closure.run(Closure.java:507) [groovy-2.4.5.jar:2.4.5]
Jan 27 15:40:30 unknown staging: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
Jan 27 15:40:30 unknown staging: at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Jan 27 15:40:30 unknown staging: Caused by: javax.mail.MessagingException: 501 Syntax: EHLO hostname
Jan 27 15:40:30 unknown staging: at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481) ~[mail-1.4.1.jar:1.4.1]
Jan 27 15:40:30 unknown staging: at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:917) ~[mail-1.4.1.jar:1.4.1]
Jan 27 15:40:30 unknown staging: at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:417) ~[mail-1.4.1.jar:1.4.1]
Jan 27 15:40:30 unknown staging: at javax.mail.Service.connect(Service.java:345) ~[javax.mail-api-1.5.1.jar:1.5.1]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:486) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:406) ~[spring-context-support-4.1.8.RELEASE.jar:4.1.8.RELEASE]
Jan 27 15:40:30 unknown staging: ... 19 common frames omitted
看起来在部署时,建议的方法没有帮助:
ERROR net.sf.ehcache.Cache: Unable to set localhost. This prevents creation of a GUID. Cause was: ip-172-35-11-183: ip-172-35-11-183: Name or service not known
Jan 27 15:35:25 unknown staging: java.net.UnknownHostException: ip-172-35-11-183: ip-172-35-11-183: Name or service not known
Jan 27 15:35:25 unknown staging: at java.net.InetAddress.getLocalHost(InetAddress.java:1505) ~[na:1.8.0_111]
Jan 27 15:35:25 unknown staging: at net.sf.ehcache.Cache.<clinit>(Cache.java:200) ~[ehcache-core-2.4.3.jar:na]
Jan 27 15:35:25 unknown staging: at net.sf.ehcache.config.ConfigurationHelper.createCache(ConfigurationHelper.java:302) [ehcache-core-2.4.3.jar:na]
Jan 27 15:35:25 unknown staging: at net.sf.ehcache.config.ConfigurationHelper.createDefaultCache(ConfigurationHelper.java:218) [ehcache-core-2.4.3.jar:na]
Jan 27 15:35:25 unknown staging: at net.sf.ehcache.CacheManager.configure(CacheManager.java:599) [ehcache-core-2.4.3.jar:na]
Jan 27 15:35:25 unknown staging: at net.sf.ehcache.CacheManager.init(CacheManager.java:358) [ehcache-core-2.4.3.jar:na]
好吧,我说这很常见,然后查看了其他一些代码,发现我正在 .ebextensions 中设置主机名。 我有这样的东西:
01_command:
echo 127.0.0.1 `hostname` >> /etc/hosts"
以添加主机名。 请注意,我不发送电子邮件,所以我不确定您是否需要真实的主机名。 如果这样做,可以更改为:
01_command:
echo `curl -s http://169.254.169.254/latest/meta-data/local-ipv4` `hostname` >> /etc/hosts"
最终的问题是,Elastic Beanstalk 将主机名设置为不在/etc/hosts 中的内容,正如你所说的那样。
我认为这是由您的 VPC 配置中的启用 DnsHostnames 参数引起的。
查看 AWS 错误 - sudo:无法解析主机 ip-10-0-xx-xx
谢谢!