Configuring a Minecraft PE Server on Amazon EC2
Over the past few months, my 8 year old son has become enamored with Minecraft. Since he mostly uses an iPad / iPod his platform of choice is Minecraft Pocket Edition. This works very well for him, but is limited in its multiplayer abilities. He recently was asking me about how he can play remote multiplayer with his cousin / friends, so I thought ‘Why not set up a Minecraft server?’.
PocketMine
PocketMine was the only Minecraft Pocket Edition server software that I could find who seemed reputable. Their setup is easy, and it offers a decent amount of configuration options that I was not even aware of. In addition, they host their code on Github (https://github.com/PocketMine/PocketMine-MP) which makes it easy to view the source and find out what is going on in its development. Some of the features that I found interesting in PocketMine are spawning configuration, white listing / black listing players, and setting the view distance. All the options are listed in their server.properties file.
Amazon EC2
Since I wanted the server to be available anywhere (so my son’s cousins and friends can all play at the same time) I used Amazon EC2 as the hardware platform. I was able to configure a Windows 2012 micro instance, which meant that I can run the server within Amazon’s free pricing tier until more resources are needed.
To configure PocketMine on EC2, I performed the following steps:
Launch an EC2 instance
Launch a Microsoft Windows Server 2012 R2 Base micro instance (the t2.micro is Free Tier eligible). Note the Public IP Address of the machine since this will be important later.
EC2 Security Group Configuration
During setup of the EC2 instance, select / create a security group that has the following configuration for Inbound Rules:
- Type: RDP; Protocol: TCP; Port Range: 3389; Source: 0.0.0.0/0
- Type: Custom UDP Rule; Protocol: UDP; Port Range: 19132; Source: 0.0.0.0/0
Machine Configuration
Once we have a functioning machine to work with, we can start to configure our Minecraft PE server. After logging onto the machine, below are the steps to set it up.
- Launch Powershell
- Set the Powershell execution policy to unrestricted so we can run our own scripts. Set-ExecutionPolicy Unrestricted
- Install Chocolatey. iex ((new-object net.webclient).DownloadString(‘https://chocolatey.org/install.ps1'))
- Install Google Chrome so we can easily download the PocketMine Software. choco install googlechrome
- Download the PocketMine software. Launch Chrome and go to http://www.pocketmine.net/#windows-install
- Install PocketMine. Run the installer downloaded in the previous step. There is the option to configure the server during setup, or manually configure later using the server.properties file. I initially walked through the manual configuration, but now have the server.properties file to use.
- Open UDP Port (inbound) in the Windows Firewall. The default port is 19132 for Minecraft. New-NetFirewallRule -DisplayName “Allow Minecraft UDP 19132 In" -Direction Inbound –LocalPort 19132 -RemotePort 19132 -Protocol UDP -Action Allow
- Open UDP Port (outbound) in the Windows Firewall. The default port is 19132 for Minecraft. New-NetFirewallRule -DisplayName “Allow Minecraft UDP 19132 Out" -Direction Outbound –LocalPort 19132 -RemotePort 19132 -Protocol UDP -Action Allow
Launch PocketMine
Once the machine is configured, you should be able to launch the PocketMine server (if it isn’t already running). This can be done by executing the start.cmd file in the PocketMine directory.
Adding the Server to Minecraft PE
Once the Minecraft server is setup and running, the last step is to add the server to the device that you want to use it on.
Instructables has instructions at http://www.instructables.com/id/How-To-Join-A-Multiplayer-Server-In-Minecraft-PE/. When entering the machine name, be sure to use the Public IP address for the EC2 instance launched earlier. This can be found in the AWS EC2 Management Console:
Once configured, you should be able to launch the world from the device and start playing!
Minecraft Server Persistence via Git
When configuring the server, I realized that there are settings / state that I want to persist after I bring the server down so that it is available next time I bring the machine back up. There are many ways (such as Dropbox, Google Drive, etc) but being a software engineer, I chose Git / GitHub as a way to make this easy for me.
- Install Git. choco install git
- Create git repo in PocketMine directory. In the base PocketMine directory: git init .
- Commit all the files. git add -A && git commit
- Create git repo on Github and add the remote. git remote add origin https://github.com/<your github user name>/<github repo name>.git
- Commit / push PocketMine directory to persist worlds / players. git push origin master
If you choose this method to persist your data, be sure to commit / push the changes to Github before you shut down the server. I also have this as a private repository just in case any personal information is added by players.