在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):doctorray117/minecraft-ondemand开源软件地址(OpenSource Url):https://github.com/doctorray117/minecraft-ondemand开源编程语言(OpenSource Language):TypeScript 74.8%开源软件介绍(OpenSource Introduction):minecraft-ondemandAlmost free serverless on-demand Minecraft server in AWS Table of Contents
Quick StartToo much text for you? Click the BackgroundInstead of paying a minecraft hosting service for a private server for you and your friends, host it yourself. By utilizing several AWS services, a minecraft server can automatically start when you're ready to use it, and shut down when you are done. The final cost will depend on use but can be as little as a a dollar or two per month. The cost estimate breakdown is below. This is a reasonably cost effective solution for someone that doesn't need their server running 24/7. If that's you, read on! WorkflowThe process works as follows:
DiagramRequirements
Cost Breakdown
Installation and SetupFor a quick start, a Cloud Deployment Kit (CDK) implementation is available! Click on the Checklist of things to keep track ofTo simplify the procedure, your ECS cluster name, service name, and sns topic name need to be defined before you start. This is because we will be referencing them before they are created. In the documentation I use these:
Things you need to go find because they'll be used in the procedure are:
Things you will locate as you go along and will need during IAM policy creation:
Region SelectionWhile it doesn't matter which region you decide to run your server in, Route 53 will only ship its logs to us-east-1, which in turns means that the lambda function also has to be in us-east-1. This lambda function can fire off the server in another region without issue, as long as the destination region is specified within the lambda function code. For the purposes of this documentation, I'm using Double check the region in anything you're copy/pasting. VPCA VPC with Subnets must exist in order for Fargate tasks to launch and for EFS shares to be mounted. A subnet should exist in each availability zone so that Fargate (and Fargate Spot, if used) can properly launch the tasks in an AZ with plenty of capacity. A security group for our task is required but is easiest configured when setting up the Task Definition below. A Default VPC should do the trick, chances are you've already got one. We'll be modifying the default security group within the EFS setup below. Elastic File SystemEFS is where the world data and server properties are stored, and persists between runs of the minecraft server. By using an "Access Point" the mounted folder is created automatically, so no mounting of the EFS to an external resource is required to get up and running. To make changes to the files like Creating the EFSOpen the Elastic File System console and create a new file system. Believe it or not, all the defaults are fine here! It will create an EFS available in each subnet within your VPC. Select your newly created filesystem, and tap the
Click Allow access to EFS from within the VPCOur EFS by default is assigned the default security group, which allows connections from all members of that default security group. Our ECS Service will not be using the default security group however, because we are opening Minecraft to the public internet. So, we need to add EFS access to the default security group (more advanced users may want to create a new dedicated security group with this rule and assign it to the mount points within the EFS console, however that will not be described here). Open the VPC console, find LambdaA lambda function must exist that turns on your minecraft service. We do this with a simple python function that change the "Tasks Desired" count from zero to one when it is invoked. We haven't created the ECS service yet, but that's okay, because we decided on the cluster name and service name before we started. Because we are relying on Route 53+CloudWatch to invoke the Lambda function, it must reside in the N. Virginia (us-east-1) region. From the Lambda console, create a new function using Once the function has been created and you're in the code editor, replace the contents of the default lambda_function.py with this: import boto3
REGION = 'us-west-2'
CLUSTER = 'minecraft'
SERVICE = 'minecraft-server'
def lambda_handler(event, context):
"""Updates the desired count for a service."""
ecs = boto3.client('ecs', region_name=REGION)
response = ecs.describe_services(
cluster=CLUSTER,
services=[SERVICE],
)
desired = response["services"][0]["desiredCount"]
if desired == 0:
ecs.update_service(
cluster=CLUSTER,
service=SERVICE,
desiredCount=1,
)
print("Updated desiredCount to 1")
else:
print("desiredCount already at 1") This file is also in this repository in the Lambda can be very inexpensive when used sparingly. For example, this lambda function runs in about 1600ms when starting the container, and in about 500ms if the container is already online. This means, running at a 128MB memory allocation, it will cost $0.00000336 the first time the server is launched from an off state, and about $0.00000105 every time someone connects to an online server, because anyone connecting will have to perform a DNS lookup which will trigger your lambda function. If you and four friends played once a day for a month, it would come out to $0.0002583, which is 2.6% of a single penny. Route 53Ensure that a domain name you own is set up in Route 53. If you don't own one, consider registering one. You can use Route 53 for convenience or go to one of the big domain providers. Either way, ensure you've got your nameservers set to host out of Route 53 as it's required for the on-demand functionality. Server DNS RecordAdd an A record with a 30 second TTL with a unique name that you will use to connect to your minecraft server. Something like minecraft.yourdomainname.com, or more complex if desired, as every time anyone in the world performs a DNS lookup on this name, your Minecraft server will launch. The value of the record is irrelevant because it will be updated every time our container launches. Use 1.1.1.1 or 192.168.1.1 for now if you can't think of anything. The low TTL is so that the DNS clients and non-authoritative DNS servers won't cache the record long and you can connect quicker after the IP updates. Query LoggingThe magic that allows the on-demand idea to work without any "always on" infrastructure comes in here, with Query logging. Every time someone looks up a DNS record for your domain, it will hit Route 53 as the authoritative DNS server. These queries can be logged and actions performed from them. From your hosted zone, click Optional SNS NotificationsYou can receive a text or email or anything else you want to consume via Amazon SNS, if Twilio isn't your thing. This also allows this to be a 100% AWS solution. From the SNS console, create a IAMThe IAM Console is where we configure the roles and policies required to give access to the Task running the Minecraft server and the Lambda Function used to start it. We will be creating four distinct policies and one role. The policies will then be attached to the appropriate roles. PoliciesEFS PolicyThis policy will allow for read/write access to our new Elastic File System Access Point. In the policy below, replace the zzz's with your account id and put your file system and access point id in the appropriate places. Change the region if necessary. Call this policy {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"elasticfilesystem:ClientMount",
"elasticfilesystem:ClientWrite",
"elasticfilesystem:DescribeFileSystems"
],
"Resource": "arn:aws:elasticfilesystem:us-west-2:zzzzzzzzzzzz:file-system/fs-xxxxxxxx",
"Condition": {
"StringEquals": {
"elasticfilesystem:AccessPointArn": "arn:aws:elasticfilesystem:us-west-2:zzzzzzzzzzzz:access-point/fsap-xxxxxxxxxxxxxxxxx"
}
}
}
]
} ECS PolicyThis policy will allow for management of the Elastic Container Service tasks and service. This lets the Lambda function start the service, as well as allows the service to turn itself off when not in use. The Replace the Call this policy {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["ecs:*"],
"Resource": [
"arn:aws:ecs:us-west-2:zzzzzzzzzzzz:service/minecraft/minecraft-server",
"arn:aws:ecs:us-west-2:zzzzzzzzzzzz:task/minecraft/*"
]
},
{
"Effect": "Allow",
"Action": ["ec2:DescribeNetworkInterfaces"],
"Resource": ["*"]
}
]
} Route 53 PolicyThis policy gives permission to our ECS task to update the DNS Place the hosted zone identifier from our checklist and place it in the Resource line within this policy where the XXX's are. Call this policy {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"route53:GetHostedZone",
"route53:ChangeResourceRecordSets",
"route53:ListResourceRecordSets"
],
"Resource": "arn:aws:route53:::hostedzone/XXXXXXXXXXXXXXXXXXXXX"
},
{
"Effect": "Allow",
"Action": ["route53:ListHostedZones"],
"Resource": "*"
}
]
} SNS policy (optional)If you have decided to receive SNS notifications, we need a policy that allows publishing to the SNS topic you created. Replace the zzz's with your account ID, and adjust the topic name or the region if you used something different. Call this policy {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": "arn:aws:sns:us-west-2:zzzzzzzzzzzz:minecraft-notifications"
}
]
} RolesPolicies are assigned to roles, and roles are used by services to services to perform the required tasks. We are creating one new role and adjusting an existing role. ECS RoleIn the IAM console, select In the policy list, you can click
Click Lambda RoleIn the roles list, find the role created by the lambda function earlier. It will be called Elastic Container ServiceThe final task we need to do is create the ECS task, cluster, and service. Task DefinitionCreate a new Task Definition of
Skip Scroll back up and click
Under
Click
Under
If using Twilio to alert you when the server is ready and when it turns off, all four twilio variables must be specified. If publishing to an SNS topic, the Click ClusterCreate a new "Networking Only" Cluster. Call it ServiceWithin your
Click
Tap CloudWatchThe final step to link everything together is to configure CloudWatch to start your server when you try to connect to it. Open the CloudWatch console and change to the Go to the In the
Click Usage and CustomizationLaunch your server the first time by visiting your server name in a web browser, which won't load anything but it will trigger the actions. You can watch it start up by refreshing the ECS console page within your To use your new server, open Minecraft Multiplayer, add your new server, and join. It will fail at first if the server is not started, but then everything comes online and you can join your new world! You may notice that you don't have many permissions or ability to customize a lot of things yet, so let's dig into how to edit the relevant files! Option 1: Mount EFS DirectlyThis option is the easiest for folks that are comfortable in the Linux command line, so I'm not going to step-by-step it. But basically, launch an AWS Linux v2 AMI in EC2 with bare-minimum specs, log into it, mount the EFS Access Point, and use your favorite command line text editor to change around server.properties, the ops.json, whitelists, whatever, and then re-launch your server with the new configuration. Option 2: DataSync and S3Since EFS doesn't have a convenient way to access the files outside of mounting a share to something within the VPC, we can utilize AWS DataSync to copy files in and out to a more convenient location. These instructions will use S3 as there are countless S3 clients out there you can manage files, including the AWS Console itself. Step 1: Create an S3 bucketOpen the S3 console and create a bucket. It must have a unique name (across ALL s3 buckets). Step 2: Create an EFS -> S3 DataSync TaskOpen the DataSync console and click |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论