Setting up a Minecraft Server (or other software) in the Cloud on a Windows Azure Virtual Machine

My son’s latest addiction is the game Minecraft,  a single or multiplayer game that has a client-server architecture to it, millions of users, a newly released version (as of last week), and a vibrant community. When I first saw the game I was put off by the seemingly crude graphics (a cube-constructed world with overlaid textures on the blocks), but I quickly got over that when I saw how it was both fun to play, sparks creativity in the way it has you gather materials and craft things in survival mode or encourages major creativity in building structures and contraptions in creative mode. I’m also impressed by the huge and vibrant community of people playing and extending the game with plug-ins (mods), custom maps, and public server worlds you can go and play in through sites like http://planetminecraft.net.

156faa1b_Minecraft-logo    windows_azure_small

Setting up a Minecraft Server

With Minecraft you can play single player on a local machine, or you can connect to remote servers. If you are a power user or someone with some IT chops you can easily set up a server of your own for which there are dozens of simple tutorials out there. It basically involves downloading the server software, running it, disabling any intervening firewalls, and typing in an IP address on the client to the server machine.

Of course what comes next is “Dad, can my friends connect to my Minecraft server?”

So I went down that route and configured our home router to do port forwarding to allow open internet traffic to come into the port that Minecraft uses to a machine on our home network. Not too tough and again dozens of tutorials out there that will walk you through that. The scary part there is poking holes in your firewall to allow unknown (and sometimes malicious) parties into your home network and onto a machine that may have other personal information on it. You also have the fact that one of the most important factors in smooth gameplay when connecting to a server is the bandwidth of the connection. If you don’t have a screaming fast internet connection, or have bandwidth limitations on your connection, you could simply be setting up an unusable server in the first place.

Enter Windows Azure Virtual Machines

Being a Microsoft Windows Azure Insider, it naturally occurred to me that there is some infrastructure out there that is optimal for this kind of shared access – Windows Azure. Windows Azure has a lot of capabilities to it including shared host roles, storage, access control and more – what is generally referred to as PaaS – Platform as a Service. But a relatively new offering from Windows Azure is IaaS – Infrastructure as a Service – which includes virtual machine hosting.

The benefits of doing something like this on a Windows Azure virtual machine are many:

  • Full control of the machine
  • Very high bandwidth connections to Windows Azure data centers
  • Scalable architecture to accommodate different amounts of load
  • Redundancy and geo-distribution for high availability if appropriate
  • Simple set up and administration

If you, like me, are just trying to get something up and running for your kids and don’t want to have to spend any money at all, then setting up a server on a home computer is going to be your cheapest option. But it does have the downsides of not being able to support many players, possibly slow /  glitchy performance, and raises some security concerns about exposing your machines and network.

With Windows Azure you can set up a free 3 month trial that includes 150 compute hours (the primary unit of billing for an Azure virtual machine), which means you can run for a month continuous free, or you can shut it down at times and only spin it up while it is in use and potentially stretch that 150 hours over a 3 month free period. After that, if you stay with an “Extra Small Instance” that can accommodate up to about 8 players concurrently for less than $10 per month.

So lets step through what I did to get this set up and running.

Setting up a Windows Azure Account

If you don’t already have a Windows Azure account, you can go and create a free trial easily here.

FreeTrial

After setting up your account, you will follow the link/button in the upper right corner to the Portal. At the time of writing this, they are switching the management portal over from an old one to a new one, so you might be prompted to use the preview portal. If so, click to use the preview one. You will be presented with a welcome tour the first time in, feel free to go through that to get a sense of what all is there.

The virtual machine capabilities of Windows Azure are still in preview status, so initially you won’t see anything about virtual machines in your portal. To get to them, you can click the + at the bottom of the screen for adding new services, and follow the link from the virtual machine option to sign up for the preview program. Depending on when you are reading this, that may no longer be needed if you see virtual machines listed in the main navigation on the left in the portal. Follow the link from the greyed out virtual machine item and click the Try It Now button. Then follow the link back to the management portal and you will see virtual machines as one of your services.

Virtual machines

Creating your first virtual machine

Click on the link to create a new virtual machine, and chose the option to create from the gallery. I chose to use Windows Server 2008 R2 SP1, June 2012 template, but you can choose one of the others as appropriate for your needs.

In the step for VM Configuration, enter a virtual machine name – this is what will be listed in your portal and has a length limitation to it, a password for the admin account, and a size. The Extra Small size is going to be the cheapest once you start paying (<$10/mo), but your free trial includes a small instance, so if you want more memory for better performance during your trial period, leave the default of small. You can change the sizing of your virtual machine later by deleting it and adding it back with a different instance size so you could switch to extra small once you have to start paying.

VMConfiguration

In the VM Mode screen, you pick your VERY IMPORTANT DNS name. This is what users will use to connect to your virtual machine as an address from the internet, so think about what you want ahead of time. The name you pick will have to be unique across all Azure virtual machines already out there, so you may not be able to use something too simple.

VMMode

The other defaults in this step will be fine. For the final step, just leave the Availability Set Not Set and click the check mark to complete the wizard. You will see your virtual machine listed now and it will start in a state of “Provisioning”.

Provisioning

It will transition through “Starting (Provisioning)” to “Stopped” to “Running (Provisioning)” over a period of about 5-10 minutes. It is important to realize that stopped virtual machines still consume compute hours. The reason is that hardware resources are still reserved for them an unavailable for other customers. You have to remove your virtual machine to stop incurring charges for it, which I’ll talk about later in this post.

Connecting to your virtual machine

Once the status reaches at least “Running (Provisioning)” you can click on the Connect button at the bottom. This will try to open an rdp file, which is a Remote Desktop connection file. Click on the Open prompt in the browser or download the file and then open it to open Remote Desktop Connection and connect to your virtual machine. Accept the various connect prompts and enter the password you chose in the earlier step for the admin password to connect. Next thing you know you will be staring at the desktop of your newly provisioned machine with the Initial Configuration Tasks window in front of you.

Opening the Minecraft ports in the Windows Firewall

Minecraft uses port 25565 by default, so we need to unblock that in preparation for running Minecraft server. Since the Windows Firewall is one of the tasks in the Initial Confguration Tasks window before us, we might as well tackle that now. Click on Configure Windows Firewall at the bottom of the window. Click on Advanced Settings, then Inbound Rules in the tree. Click on New Rule in the upper right, then select Port and click Next at the bottom of the dialog. Type in 25565 in the specific local ports entry and click Next. Keep “Allow the Connection” in the next step, then keep all the checkboxes checked in the next step. Give the new rule a name of Minecraft in the next step and click Finish.

Turn off Internet Explorer ESC

Internet Explorer has Enahnced Security Configuration enabled by default. This will interfere with some of the downloads you need to do to get Minecraft installed, so you need to turn this off. In the Server Manager window that came up when you went to advanced firewall settings, there is a link in the bottom right corner to configure ESC. Click on that link and disable ESC for Administrators.

ServerManager

Install Java

Minecraft is built on Java, so you need to get the Java platform installed. The OS of the Windows Azure virtual machine I selected was Server 2008, and they use the 64 bit variant. So you will want to make sure you get the 64 bit version of Java 7, not the 32 bit one that they want to install by default. To do this, fire up Internet Explorer from the start menu, accepts the defaults on the initial configuration of IE, and head on over to www.java.com, click the Free Download button, and then find and click the See All Java Downloads link. Download and install the 64 bit version for Windows.

Installing Minecraft Server

While Java is installing, you can head over to minecraft.net and find the download button on the right margin. You will have to set up an account ($27 annual), but I’m assuming you are well past that point if you want to set up your own server already. You could download the Minecraft Server.exe, but the .jar version gives you better configurability of the memory it will use, which is important for the memory constrained extra small instance or small instance in Windows Azure. So download the minecraft_server.jar file to the desktop of your virtual machine. It actually downloads it as a .zip file extension even though it is really a .jar file.

Go into your Windows Explorer Folder and Search Options and disable the option to “Hide Extensions for Known File Types” so that you can see the .jar file extension on the file you just downloaded.

Once you see the .zip file extension, change it to .jar.

Right click on the desktop and select New > Text Document. Name it Minecraft.bat and accept the file extension change. If you are not prompted for changing the file extension then you don’t have the option off to not hide file extensions and the file won’t run as a batch file. Then right click on the file and select Edit. Enter this text in the bat :

@ECHO OFF
SET BINDIR=%~dp0
CD /D "%BINDIR%"
java -Xmx512M -Xms512M -jar minecraft_server.jar
PAUSE

If you are using a small instance instead of an extra small instance for your virtual machine, you can bump both of those numbers up to 1024 instead of 512. Those affect how much memory the Java virtual machine will try to consume. Save the file and close it.

Create a folder on the desktop (call it Minecraft or whatever you like and move both the minecraft_server.jar and the Minecraft.bat file into it.

Then double click on Minecraft.bat to run it.

You should see the Minecraft server start up and it will create some additional files in the folder. For the full details of those files and what they do for you, see the Minecraft Server topic on the Minecraft Wiki.

Configuring endpoints

Besides the firewall built in to the Windows OS that we opened the Minecraft port on earlier, you also need to open ports in the Azure infrastructure so that people can get to your virtual machine in the first place. To do that, you go to the Endpoints button at the top, add a new endpoint, give it a name (i.e. Minecraft), and specify the external and internal ports. For a default Minecraft setup, those will both be 25565.

Play!

At this point you should be able to go into the Minecraft game on any internet connection computer, Add a Server, and enter the address of your server in the form mymcserverdns.cloudapp.net.

Deleting your virtual machine to avoid incurring charges

As mentioned before, your virtual machine will continue to consume compute hours while it is running and even if you simply shut it down. You need to delete or remove the virtual machine to stop the clock ticking on your compute hours. Deleting your virtual machine does not mean you have to set it all up again when you want to start it up again. When you delete a virtual machine, the machine image is stored into your storage account, and you can easily create a new virtual machine based on that image and it will start up with everything just as you left it before you deleted the virtual machine.

To do this, go into the management portal, open your virtual machine page, and click on the Delete button at the bottom.

DeletingServer

 

Recreating your virtual machine to spin it up again

After your virtual machine has been deleted, a “Cloud Service” with the same name will be created that holds the DNS name for your virtual machine. You will need to delete that cloud service to recreate your virtual machine with the same DNS. So go select the cloud service with the same name as your virtual machine and delete it.

Next you go back to the virtual machine section and add a new virtual machine. Select the Gallery, and you will see your previous virtual machine listed at the bottom.

Recreate vm

Select it, and in the next step, reclaim your previous DNS name and you are off and running again. When the machine finishes provisioning, you will have your previous machine as you left it.

If you want a little more automated process for doing this, as well as not letting someone else have the opportunity to grab your DNS name between when you delete it and reclaim it, you can follow use the powershell scripts outlined here:

http://michaelwasham.com/2012/06/18/importing-and-exporting-virtual-machine-settings/

Other options

Once you want more than about 10 concurrent players supported, a Windows Azure machine is going to get more expensive than some of the Minecraft hosting providers out there, for example servercraft.co.

Wrapping Up

Whether you are trying to set up a Minecraft server or some other kind of internet accessible piece of software, Windows Azure provides an attractive and easy to use hosting option. Setting up your own virtual machine you have full control over installing whatever software you need and configuring the box. The machine is sitting in a high bandwidth data center that can handle traffic much better than your own machines through a home or small office connection. You don’t have to worry about exposing your own machines or network to the open internet because you can put what you want to be publicly accessible out in the cloud, isolated from your own stuff.

Hope you found this little tutorial to be helpful.

Comments are closed.