简体   繁体   English

尝试连接到 RDS 时出现 AWS EC2 Interminent UnknownHostException

[英]AWS EC2 Interminent UnknownHostException when trying to connect to RDS

I am runnung Java Play on an ec2.我在 ec2 上运行 Java Play。 When I started up my Play on prod, everything works great.当我在 prod 上启动我的 Play 时,一切都很好。 However, after running it about a day, I will start seeing UnknownHostException when connecting to RDS instance.但是,在运行它大约一天后,我将在连接到 RDS 实例时开始看到 UnknownHostException。 This prevents any transaction between ec2 and rds.这可以防止 ec2 和 rds 之间的任何事务。 If I restart the app again, it works fine again.如果我再次重新启动应用程序,它会再次正常工作。

I already checked the connection pool and I am pretty sure it works fine.我已经检查了连接池,我很确定它工作正常。 Also, I already tested this with networkaddress.cache.ttl = 0 and networkaddress.cache.negative.ttl = 0. However, I am still getting the error.此外,我已经使用 networkaddress.cache.ttl = 0 和 networkaddress.cache.negative.ttl = 0 对此进行了测试。但是,我仍然收到错误消息。

Anyone has thoughts on this?有人对此有什么想法吗?

Just moving this to an answer from the comments.只是将其移至评论中的答案。 This was fixed by stopping the EC2 instance and then restarting it.这是通过停止 EC2 实例然后重新启动它来解决的。 After which, the error was not seen again.之后,错误不再出现。

It did not fix itself in my case.就我而言,它没有自行修复。 I ended stopping/starting my ec2 instance and this fixed it permanently.我结束了停止/启动我的 ec2 实例,这永久地修复了它。 My guess is that it got assigned to another (better configured) ec2 instance when I starting it back up.我的猜测是,当我启动它时,它被分配给另一个(更好配置的)ec2 实例。

What happens when you do this .当你这样做时会发生什么。

  • New internal IP address, though could randomly be the same.新的内部 IP 地址,但可能随机相同。 [VPC instances keep same internal IP addresses through stop/start.] [VPC 实例通过停止/启动保持相同的内部 IP 地址。]

  • New external IP address (though could randomly be the same).新的外部 IP 地址(尽管可能随机相同)。

  • If an Elastic IP address was associated with the instance before it was stopped, then you'll need to re-associate it after the start.如果弹性 IP 地址在停止之前与实例关联,则您需要在启动后重新关联它。 [VPC instances keep Elastic IP addresses associated through stop/start.] [VPC 实例通过停止/启动保持弹性 IP 地址关联。]

  • Any contents on the instance's former ephemeral storage were wiped and you are given fresh ephemeral storage (often mounted as /mnt).实例以前的临时存储上的任何内容都被擦除,您将获得新的临时存储(通常安装为 /mnt)。

  • You can leave an instance stopped for as long as you like and not get charged for run time (though you do get charged at a much lower rate for the EBS volume storage).您可以根据需要让实例停止运行,并且不会为运行时间付费(尽管 EBS 卷存储的费用要低得多)。 See the next point.看下一点。

  • A fresh billing hour is started for the instance when you start it again.当您再次启动实例时,会为该实例启动一个新的计费小时。 Eg, if you start a new instance and then stop/start it 3 times within the first 60 minutes, you'll get charged for 4 hours instead of 1.例如,如果您启动一个新实例,然后在前 60 分钟内停止/启动它 3 次,则您需要支付 4 小时而不是 1 小时的费用。

  • There is a small chance that EC2 will not have available slots of the correct instance type to run your instance when you want to start it again.当您想再次启动实例时,EC2 可能没有正确实例类型的可用插槽来运行您的实例。 I've had this happen and temporarily switched to a different, available instance type to get it running again.我遇到过这种情况并暂时切换到不同的可用实例类型以使其再次运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM