linux – 自动关闭服务器不活动(SSH)?

前端之家收集整理的这篇文章主要介绍了linux – 自动关闭服务器不活动(SSH)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一台服务器托管在 EC2.服务器建立在 Linux AMI,基于CentOS.它专门用于客户端项目,我通过SSH连接.有时,我忘记在未使用时关闭服务器,从而产生不必要的成本.

如何在不活动时自动关闭服务器,例如在没有SSH连接的情况下30分钟后?

当然,我正在寻找最简单的解决方案.每小时左右检查也可以,只是可靠的工作.

解决方法

截至2013年1月 Amazon CloudWatch提供了 Use Amazon CloudWatch to Detect and Shut Down Unused Amazon EC2 Instances的选项,有关此功能的详细信息,请参阅介绍性博客 Amazon CloudWatch – Alarm Actions

Today we are giving you the ability to stop or terminate your EC2
instances when a CloudWatch alarm is triggered
. You can use this as a
failsafe (detect an abnormal condition and then act) or as part of
your application’s processing logic (await an expected condition and
then act). [emphasis mine]

您的用例特别列在故障安全提示部分中:

If you (or your developers) are forgetful,you can detect unused EC2
instances and shut them down. You could do this by detecting a very
low load average for an extended period of time. This type of failsafe
could be used to reduce your AWS bill by making sure that you are not
paying for resources you’re not actually using.

如上所述,这取决于能够启发式地检测触发警报和停止实例的适当条件 – 您可以根据登录的SSH用户数,空闲时间或其他方式通过Publishing Custom Metrics将其带到CloudWatch的下一级别.依次获得所需检测和关闭过程的更多控制/精度.

猜你在找的Linux相关文章