我如何创建一个Minecraft EC2服务器,当有人尝试使用它时自动启动 [英] How would I create a Minecraft EC2 server that automaticaly starts when someone tries to use it

查看:54
本文介绍了我如何创建一个Minecraft EC2服务器,当有人尝试使用它时自动启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有一个运行正常的Minecraft服务器,该服务器在C5 EC2实例上运行.问题是我必须手动启动和停止服务器,这对我的朋友们可能很烦.我想知道是否有可能使EC2状态自动化,以便在玩家尝试加入服务器时立即运行它.这类似于我听说Mojang将AWS用于以下方面的Minecraft领域的行为: https://aws.amazon.com/blogs/aws/hosting-minecraft-realms-on-aws/

Currently, I have a working modded Minecraft server working running on a C5 EC2 instance. The problem is that I have to manually start and stop the server which can be annoying for my friends. I was wondering if it would be possible to automate the EC2 state so that it runs as soon as a player attempts to join the sever. This would be similar to how Minecraft realms behaves which I heard Mojang was using AWS for: https://aws.amazon.com/blogs/aws/hosting-minecraft-realms-on-aws/

我已经查看了有关此的教程,这是我能碰到的最好的东西: https://github.com/trevor-laher/OnDemandMinecraft

I have looked up tutorials for this and this is the best I could come across: https://github.com/trevor-laher/OnDemandMinecraft

此解决方案的问题在于,它需要一个单独的网站来登录用户并启动EC2实例,而我希望启动和关闭是完全自动化的.

The problem with this solution is that it requires to make a separate website to log users in and start the EC2 instance while I want the startup and shutdown to be completely automatic.

我将不胜感激.

推荐答案

如果服务器关闭,则无法连接"到服务器.因此,需要另一种可用于启动服务器的机制.

If the server is off, it would not be possible to "connect" to the server. Therefore, another mechanism is required that can be used to start the server.

结合您的期望以最小化成本,唯一真正的解决方案是以某种方式触发AWS Lambda函数,该函数可以启动服务器.

Combine that with your desire to minimise costs and the only real solution is to somehow trigger an AWS Lambda function, which could start the server.

有几种方法可以让用户触发AWS Lambda函数:

There are a few ways you could have users trigger the AWS Lambda function:

  • 拨打API网关
  • 将对象上传到Amazon S3
  • 以某种方式将消息放入SNS主题或SQS队列中
  • 触发Amazon CloudWatch警报(通过SNS调用Lambda)
  • ...以及其他可能的方式

在考虑使用的方法时,您应考虑安全隐患,例如:

When considering a method to use, you should consider security implications such as:

  • 是否只有授权用户才能触发Lambda函数,还是可以由任何人(例如Web爬网程序)触发Lambda函数.
  • 您是否愿意为您的朋友提供AWS凭证(不是一个好主意),他们可以用来直接启动服务器,或者它是否应该是间接方法.

坦率地说,我会推荐以下架构:

Frankly, I would recommend the following architecture:

  • 创建一个 AWS Lambda函数以打开服务器
  • 创建一个触发Lambda函数的 API网关
  • 给您的朋友一个 URL ,该URL会调用API网关并传递一个秘密"(实际上是一个密码)
  • API网关将调用Lambda函数,并传递秘密
  • Lambda函数确认密码正确无误,并启动安装了Minecraft的Amazon EC2实例
  • Create an AWS Lambda function that turns on the server
  • Create an API Gateway that triggers the Lambda function
  • Give a URL to your friends that calls the API Gateway and passes a 'secret' (effectively a password)
  • The API Gateway will call the Lambda function, passing the secret
  • The Lambda function confirms that the secret is correct and starts the Amazon EC2 instance with Minecraft installed

这里是展示了许多概念的教程:通过Lambda集成构建API网关API

Here is a tutorial that shows many of these concepts: Build an API Gateway API with Lambda Integration

该秘密的目的是避免在未经授权的人(或机器人)碰巧访问API网关端点时避免服务器启动.他们不会提供机密,因此不会启动服务器.

The purpose of the secret is to avoid the server from starting if an unauthorized person (or a bot) happens to hit the API Gateway endpoint. They will not provide the secret, so the server will not be started.

停止服务器是另一回事.您引用的库可能能够帮助您找到一种方法.您可以在Minecraft服务器上运行一个脚本来监视游戏,并且在一段时间不活动之后,只需调用操作系统执行关机.

Stopping the server after a period of non-use is a different matter. The library you referenced might be able to assist with finding a way to do this. You could have a script running on the Minecraft server that monitors the game and, after a period of inactivity, simply calls the operating system to perform a Shutdown.

这篇关于我如何创建一个Minecraft EC2服务器,当有人尝试使用它时自动启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆