How to Create a Game (Minecraft/Terraria) Server with AWS

This tutor is under Linux machine (my working and server machine is both using Linux), if you use Windows or Mac, please know how to open the terminal and install OpenSSH for connection.

# WHY

Learning something about AWS, SSH remote connection (ip, port, domain), and java usage.

Playing Minecraft with my friends when not under LAN.

# WHAT

AWS Introduction

SSH Intro

# HOW

* means Optional Operation

# 1. Create an AWS EC2 Instance

Note. There is a free x86_64 CPU “Free tier: In your first year includes 750 hours of t2.micro (or t3.micro in the Regions in which t2.micro is unavailable) instance usage on free tier AMIs per month, 30 GiB of EBS storage, 2 million IOs, 1 GB of snapshots, and 100 GB of bandwidth to the internet.” for new user, but it is not very good for running Minecraft Server. But if you want to use it, you could follow the tutor, but you need to change the Architecture to 64-bit (x86) in Application and OS Images (Amazon Machine Image) and choose t2.micro in Instance type

  1. Create a AWS account
  2. Choose a good place that near your home on the top right of the AWS main webpage, e.g. I choose US East (N. Virginia)us-east-1
  3. Look at the top left of the webpage, select Services - Compute - EC2 - Instances - Launch instances, or you could just search EC2 then Launch instances
  4. Create an instance for Minecraft Server
    1. Name and tags: Create a Name so that you could know this is your instance that run your Minecraft server.
    2. Application and OS Images (Amazon Machine Image): Define which types of CPU and System you would use
      1. Amazon Machine Image (AMI): Select a system for your instance. Amazon Linux Amazon Machine Image (AMI) is recommended for its cheapness (CPU under Linux Base System is cheaper) and lightweight (we do not need lots of functions to run Minecraft Server)
      2. Architecture: 64-bit (Arm) is recommended because it has more CPUs with cheaper price. (Note. Terraria only support x86_64)
    3. Instance type: Choose a CPU for running Minecraft Server, here is a list of price for every CPU: AWS Price Calculator. Remind that a pure Minecraft server (No mod) with two people server needs at least 1 GiB RAM
      • r7g.medium for modded Minecraft
      • t2.micro for Terraria
    4. Key pair (login): Define how can you login to the instance safely.
      1. Create new key pair if you do not have one, otherwise you could choose one you know.
      2. Key pair name: Create a name for your key pair so that you could know it is using for connection for your instance.
      3. Key pair type: RSA is recommended for its higher security.
      4. Private key file format: .pem is recommended for many Linux machines have already installed it.
      5. Create key pair and select your key pair name.
      6. It will generate a .pem file for instance authorization, remember to save it properly.
        1. Create new path for storing if you do not have: $ mkdir ~/.ssh
        2. Move file to the folder: $ mv YOUR_PEM_FILE.pem ~/.ssh
        3. Change the permission to make the file safer: $ chmod 400 ~/.ssh/YOUR_PEM_FILE.pem
    5. Network settings
      1. Firewall (security groups): It is recommended that create a security groups independently and choose here.
      2. In the left panel, select Security Groups - Create security group
      3. Basic details Create a name so that you could know this security group is for your server.
      4. Inbound rules: add two rules, one Type is SSH (port 22) and 0.0.0.0/0 as the source for SSH connection; one Type is Custom TCP which has 25565 port range which is the default port for Minecraft Server
      5. Outbound rules: It might already exist that All traffic to enable internet connection, if no, create one.
      6. Back to instance creation, Select existing security group and choose the security group you just created.
    6. Configure storage: default 8GiB with gp3 is enough (even for my mods Server).
    7. Turn to right panel Launch instance

# 2. Connect Linux to the Instance with SSH

  1. Turn back to instances, select the instance id you just created
  2. Then you open a new panel which lists all the detailed information for your instance. If the instance is not open, select Instance state - Start Instance to start it.
  3. Record Public IPv4 address or Public IPv4 DNS as your instance IPv4 that would help you to connect to your instance
  4. Use OpenSSH command $ ssh -i PATH_TO_PEM.pem ec2-user@IPv4 to connect to your instance.
  5. *Before step 2.4, you might already have Minecraft Server file, you could transfer your file through $ scp -i PATH_TO_PEM.pem -r SOURCE_FILE_OR_FOLDER ec2-user@IPv4:PATH_YOU_WANT_TO_STORE

# 3. Install Java & Minecraft Server to the Instance (After loginning in to your Remote Instance)

  1. Install Java 8: $ sudo yum install java-1.8.0

  2. Download Server Package

    1. 1.16.5 (No Mod): $ wget https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar
    2. For other release, you could Google: Minecraft, Server, VERSION and look at the website in this format: https://www.minecraft.net/en-us/article/minecraft-java-edition-VERSION then scroll down to get the link
    3. For mod Server, you could find here https://files.minecraftforge.net/net/minecraftforge/forge/ and download, but remind that later we will install it before first launch.
  3. First Launch: $ java -jar server.jar --nogui, if install forge, then run $ java -jar forge-x.xx.x-installer.jar --installServer --nogui instead.

  4. Accept EULA: 1. Open eula.txt: $ vim eula.txt, 2. Change eula=false to eula=true to indicate acceptance of the EULA

# 4. Launch the Server & Commands

  • Launch Pure or Forge version $ java -Xmx1536M -Xms512M -jar SERVER_NAME.jar --nogui
    • -Xmx1024M is maximum RAM allow server to use
    • -Xms1024M is minimum RAM allow server to use
    • Or you can launch by systemd: sudo touch /etc/systemd/system/minecraft.service, sudo chmod 664 /etc/systemd/system/minecraft.service, sudo vim /etc/systemd/system/minecraft.service, sudo systemctl daemon-reload
    • eg. java -Xmx7680M -Xms1024M -jar forge-1.16.5-36.2.34.jar --nogui
[Service]
User=ec2-user
WorkingDirectory=/home/ec2-user/minecraft
ReadWriteDirectories=/home/ec2-user/minecraft
ExecStart=java -Xmx1536M -Xms512M -jar /home/ec2-user/minecraft/server.jar --nogui
ExecStop=/stop
  • Stop the Server: /stop

# 5*. Adding mods and worlds

  • Before the second launch, create a new folder world or mod then put the data into the folder
Built with Hugo
Theme Stack designed by Jimmy