How to Set up a Unity3D Master Server on Amazon EC2

Hi everyone!

I want to write a short guide on getting a Unity Master Server set up on Amazon Web Services (AWS) on an EC2 Micro Instance. Firstly, Amazon Web Services are free for the first year as long as you are using a one micro instance (5GB image). As long as you do not have unassigned Static IPs or multiple instances running, you should not incur any charges. To get more information on what defines the free-tier you can go here: Amazon AWS Free. Let’s get started!

  1. Create anĀ Amazon AWS Account
  2. Go to the EC2 Instances page by clicking “EC2” then when that loads, in the lefthand navigation going to instances.
  3. Click the blue “Launch Instance” button
  4. Create a new Redhat Enterprise Linux Instance under the free tier in the preconfigured AMI’s
    amazon_01
  5. After you select it, it should ask about what instance type you like. This is where you skip this step and click on step 5, “Tag Instance.” You will see that an entry already exists, Name. You can go ahead and set the value for that to Unity Master Server for your convenience.
    amazon_02
  6. Go ahead and click on step 6: “Configure Security Group”. We need to configure the instance so that we can access the URL. The easiest way to do this is to open the instance on all ports on TCP and UDP. You will see that the instance is open on port 22 for SSH access, now we need to click the Add Rule button and add access via ALL TCP to anywhere on the IP and same with UDP
    amazon_03
  7. You do not need to configure anymore options. You can click the blue Review and Launch button then once you’ve review the details, go ahead and launch the Instance.
  8. You should be prompted to create a security key pair or use an existing one. This is VERY important. Do not lose the file you download when/if you create a new key pair! It is imperative that you download this .pem file to a secure location. If you don’t have it, there is no way that you will be able to access your VM.
  9. Ensure that it’s running by checking it’s status in the Instances page. If the instance state is not running, you may select it, right click, and command it to start with “Start” in the “Actions” section
  10. Now that the instance is created, we need to give it a public IP Address. Go to Elastic IPs under Networking and Security in the lefthand panel and create a new elastic IP. After you create this IP is VERY IMPORTANT that it is assigned to a RUNNING EC2 Instance. If you create an Elastic IP that is unassigned you are billed $0.005 every hour until it’s assigned. To assign it, just select it, then right click and go to “Associate Address”
  11. OK. we have a public IP for our instance, and it should be running. Good. We need to set up a way to SSH into the VM and starting messing around with the files. The best thing to do is to download PuTTY and install it
  12. Open PuTTYGen and then open your download .pem file in it (by selecting *.* All Files in the load file dialog). You can then go ahead and hit generate to create a ppk for the key file. You can put a password on it if you like. Just remember this password for later you will need to enter that in the putty console when you connect.
    putty_01
  13. Once that is complete you may open PuTTY and get your public DNS and place that in the Hostname box on the Sessions dialog.
  14. Before attempting to connect we need to navigate to the Connection section on the left and add our ppk into an SSH authorization section as you can see below:
    putty_02
  15. Now go back to the sessions page and you can save this configuration by putting a name like “Master Server” in the box below the “Saved Sessions” text and then then hitting the Save button.
  16. You should be able to connect without a snag. You will be prompted with a user account to log in with. If you type “root” it will tell you the correct user for that vm which could be something like: ec2-user.
  17. Once you’ve logged in you can go ahead and download the Unity Master Server using wget:
    wget http://unity3d.com/files/master-server/MasterServer-2.0.1f1.zip
  18. You need to unzip the file.
  19. Then build it:
    make
  20. You can then run it:
    ./MasterServer
  21. Then you’re done!

 

I hope you learned something in this tutorial and if you have any problems, just comment and I’ll do my best to help you!

Tom

9 thoughts on “How to Set up a Unity3D Master Server on Amazon EC2”

  1. Hey,

    This is a great little tutorial to get the master server up on ec2 – exactly what I was looking for. Unfortunately, after following all steps successfully (so it seems) my game cannot connect to the master server. I’m getting the standard “Failed to connect to master server at :”.

    With some playing around, I could confirm that I can ping the ec2 VM from inside my Unity game but it can never connect to the master server service and the service receives no requests. The only step I had to take that deviated from the above instructions was that I had to install gcc (using yum) in order to run the make command.

    Since I can ping the server, I’m guessing something is wrong with my master server service, is there a way that you know of to verify that it is running properly? Any help is greatly appreciated, thanks!

      1. Sadly, I’ve not been able to figure out what the problem is and ended up putting the issue on the backburner for the moment. My best guess is still that it got screwed up in the build process somewhere though I don’t know for sure and all I get on the Unity side is the cryptic “Failed to connect” error. I’ve not been able to find a pre-built package either so I’m not quite sure how to determine where the problem is or how I might get it working.

        Any ideas?

        1. The only thing I can think of is that you didn’t properly set up your security permissions (see step 6). Because if it builds and you ran it, then you should be able to connect.

  2. Thanks for the effort, however you haven’t included how to setup port forwarding.

    I can never connect to the master server when running the Master Server. Also don’t you need the Facilitator?

    I have tried enabling both the ports through security options in the AWS config, and have opened the ports from within RHL as well.

  3. Could you refine the last part from 14 a bit. Before this you really go into detail but then you stop like we are putty or linux pro’s. This is my first time actually.

    I first accidental generated a key over .pem that was imported. Took me some time but then I noticed i could just import the .pem key and save it.

    I downloaded putty from the link you have but it does not have wget, or the server does not have it. So i had to do “sudo yum install wget” and “sudo yum install unzip”.

    Now i am completaly stuck at building it. “make” does not work `command not found`. “sudo make” does not work either.

    So by the time I found this out I fear the lasts step of “run it” will be impossible since that looks like the easier part :).

  4. Great little tutorial, got all the way in, right up until the wget command, and the server says unrecognised command, or something similar.
    It’s always the easy bits that end up tripping you up !
    Any advice?

Leave a Reply

Your email address will not be published. Required fields are marked *