Open In App

Google Cloud Platform – Setting Up a Game Server

In this article, we will set up a server in a public cloud to serve a game application by using infrastructure as a service (IaaS) provided by the google cloud platform. However, the process will be nearly the same for any other public cloud platforms.

Overview of steps:

  1. Set up the account and create the project in any public cloud (say, Google cloud platform)
  2. Create a virtual machine of the required configuration and disk boot image in the preferred region and zone(say, Debian GNU/Linux 9 (stretch)  machine with at least 50 GB disk size )
  3. Install all the run time requirements  and dependencies  in the virtual machine (say JRE for java application)
  4. Set up the firewall rules for the virtual instance to allow client traffic.
  5. Make sure the server is running all the time.

Tools Used:

In this article, we will the following tools and technologies:



Now follow the below steps to set up the server.

STEP 1:

Note: If you do not have a free trial account activated you will be billed for provisioning and using any resources in Google cloud 



After the initial setup is done you must see a similar interface:

Note: We are using the Qwiklabs practice account here.

STEP 2:

In this step we have to create VM instance with the required configuration and we will also add an additional SSD persistent disk of 50GB. Open Google cloud shell by clicking on the below-shown button:

$ gcloud beta compute --project=qwiklabs-gcp-04-f7bbc9a0604c instances create mc-server
 --zone=us-central1-a --machine-type=e2-medium --subnet=default --address=35.232.183.36 
 --network-tier=PREMIUM --maintenance-policy=MIGRATE 
 --service-account=875541841397-compute@developer.gserviceaccount.com 
 --scopes=https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/trace.append,https://www.googleapis.com/auth/devstorage.read_write --tags=minecraft-server --image=debian-9-stretch-v20201216 --image-project=debian-cloud --boot-disk-size=10GB --boot-disk-type=pd-standard --boot-disk-device-name=mc-server --create-disk=mode=rw,size=50,type=projects/qwiklabs-gcp-04-f7bbc9a0604c/zones/us-central1-a/diskTypes/pd-ssd,name=minecraft-disk,device-name=minecraft-disk --reservation-affinity=any

It might take about a minute,  Output must look like this:

Note: The “external IP addresses” of the virtual machine will be used to check the working of the server.

As we have added a disk, we have to mount the disk by using the following commands in the Linux instance.

$ sudo mkdir -p /home/minecraft
$ sudo mkfs.ext4 -F -E lazy_itable_init=0,\
lazy_journal_init=0,discard \
/dev/disk/by-id/google-minecraft-disk
$ sudo mount -o discard,defaults /dev/disk/by-id/google-minecraft-disk /home/minecraft

STEP 3:

$ sudo apt-get update
$ sudo apt-get install -y default-jre-headless
$ cd /home/minecraft

The wget is used to download the JAR file. 

sudo apt-get install wget
$ sudo wget https://launcher.mojang.com/v1/objects/d0d0fe2b1dc6ab4c65554cb

$ sudo java -Xmx1024M -Xms1024M -jar server.jar nogui

We have to accept the End User Licensing Agreement (EULA), in order to run the server.

$ sudo nano eula.txt
# Change the last line of the file from eula=false to eula=true

After editing eula.txt, it must look like this:

 

.STEP 4: 

$ gcloud compute --project=qwiklabs-gcp-04-f7bbc9a0604c 
firewall-rules create minecraft-rule --direction=INGRESS 
--priority=1000 --network=default --action=ALLOW --rules=tcp:25565 
--source-ranges=0.0.0.0/0 --target-tags=minecraft-server

The output must look like this:

STEP 5:

To make sure  that the server runs all the time, we can use the “screen” application.

$ sudo apt-get install -y screen
$ sudo screen -S mcs java -Xmx1024M -Xms1024M -jar server.jar nogui

It will take some time to start the server. The output must look like this:

Now the server will continue to run in the background,

Working server-status must be similar to the image shown below:

Note: You have to use your virtual machine external IP address,  (Go to Navigation menu > compute Engine > virtual Instances, to get your virtual machine external IP address).


Article Tags :