Show
OverviewTo run a dedicated Minecraft server, you need a dedicated server machine, plenty of RAM, and plenty of bandwidth. Why not let Google handle these requirements for you? In this lab, you'll learn how to install, configure, and run a standard Minecraft server on Compute Engine. Note: This lab is not approved by or associated with Mojang or Minecraft.Your Minecraft server software will run on a Compute Engine instance, which is a virtual machine that runs on Google's infrastructure. This lab uses the default machine type for Compute Engine instances, n1-standard-1. The n1-standard-1 machine type includes a 10 GB boot disk, 1 virtual CPU (vCPU), and 3.75 GB of RAM. This machine type runs Debian Linux by default. To make sure there's plenty of room for your Minecraft server's world data, you'll also attach a high performance 50 GB persistent solid-state drive (SSD) to your instance. With the addition of this persistent SSD, your instance will satisfy the system requirements for a dedicated Minecraft server and support up to 50 players comfortably. What you'll do
SetupBefore you click the Start Lab buttonRead these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you. This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab. To complete this lab, you need:
How to start your lab and sign in to the Google Cloud Console
After a few moments, the Cloud Console opens in this tab. Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left.Create and configure your Compute Engine instanceIn the Cloud Platform Console, go to the VM instances page by clicking the Navigation menu > Compute Engine > VM instances. You'll arrive at a dialog prompting you to create a new Compute Engine instance. Click Create Instance: On the Create an instance dialog, configure the following for your instance. Ignore the other values for now.
That's it for basic configuration! That said, don't create your new instance just yet—to meet the requirements for a dedicated Minecraft server, you'll stay in the Create an instance dialog and configure access and some advanced settings. Enable Cloud Storage access for your instanceIn this step you'll configure access to Cloud Storage for your instance. This is required to back up your world data to Cloud Storage, which you'll learn about later in this lab. To enable access, configure Identity and API access in the Create an instance dialog. Ignore the other values.
Add a persistent disk to your instanceNext, you'll attach a persistent disk to your instance. Unlike boot disks, persistent disks are not tied to the life of your Compute Engine instance. For example, if your hosting needs change over time, you can move the disk to a more suitable machine type later. The specific type of persistent disk you will use in this lab is a persistent SSD. This type of persistent disk supports very fast I/O operations, which can help reduce server lag. Towards the bottom of the Create an instance dialog you'll see a link for Networking, disks, security, management, sole tenancy. Click the link. In the Disks section, click Add new disk. You will next configure your persistent disk. In the New disk dialog, set the values of the fields listed below. Ignore the other fields.
Click Save. When the instance is created, the disk will be attached automatically. Tag your instanceNow click the Networking tab, add the tag minecraft-server to the Network Tags field. Later in the lab, you'll use this tag to create a firewall rule to allow external Minecraft clients to access your server. Set up a static IP for your instanceTo forward incoming requests to your instance dependably, your instance needs a static IP. Still in the Networking tab, Under Network interface field, select default network. From External IP dropdown, select Create IP address. Name your IP address mcs-ip and click Reserve to create the address. Click Done to close this dialog. Create your instanceYour instance is configured! Click the Create button to create your new instance. This action will take you back to the VM instances page. Note: It can take up to 20 seconds for your instance to be created.Click Check my progress to verify the objective. Create and configure your Compute Engine instance. Mount and format your persistent diskAt this point, your disk is attached to your instance, but it hasn't yet been mounted to the instance. That's okay! If you mounted the disk now, you wouldn't be able to do much with it. As with any disk, your persistent disk first needs to be formatted with a filesystem that your operating system — in this case, Debian Linux — can understand. Begin by establishing an SSH connection with your instance. On the VM instances page, click the SSH button to open a browser-based SSH terminal: Run the following to create a new directory named minecraft in your instance's home directory: sudo mkdir -p /home/minecraftYou'll use this directory as a mount point for your persistent disk. First format your disk: sudo mkfs.ext4 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-minecraft-diskThen mount your disk: sudo mount -o discard,defaults /dev/disk/by-id/google-minecraft-disk /home/minecraft Mount and format your persistent disk.Install and run the Minecraft server on your instanceYour persistent disk is officially mounted. Now it's time to do what you came here to do in the first place: install and run your Minecraft server. Set up the Java Runtime Environment (JRE)The Minecraft server runs on top of the Java Virtual Machine (JVM), so it requires the Java Runtime Environment (JRE) to run. Because the server doesn't need a graphical user interface, this lab uses the headless version of the JRE. This approach reduces the JRE's resource usage on your machine, helping ensure that the Minecraft server has plenty of room to expand its own resource usage if needed. You'll need to update the Debian repositories on your Debian installation before you can download and install the headless version of the JRE. To do so, run the following command in your SSH terminal: sudo apt-get updateAfter your repositories are updated, you can install the headless JRE: sudo apt-get install -y default-jre-headlessInstall the Minecraft serverNow that you've set up the JRE, it's time to download and install the Minecraft server. Begin by navigating to your minecraft directory: cd /home/minecraftBecause the minecraft directory contains your mounted persistent disk, you're going to need a special level of access known as root user access to run commands on it. Run the following to become the root user: sudo suNext, download the current Minecraft server's Java archive file (JAR) to your instance: curl https://s3.amazonaws.com/Minecraft.Download/versions/1.11/minecraft_server.1.11.jar > minecraft_server.1.11.jar Note: This lab uses minecraft_server.1.11. However, a newer version might have been released since this lab was published. You can find a link to the latest JAR file by visiting the Minecraft download page.Start the server for the first time: java -Xms1G -Xmx7G -jar minecraft_server.1.11.jar noguiThe first run is a little anticlimactic: the server simply starts, executes some quick operations, and stops. If you run the following command, however, you'll notice that some new files have been created in the minecraft directory: ls -lAmong these new files, you'll find a file called eula.txt, which was downloaded when you started the server. This file contains a single boolean variable, eula. To use the Minecraft server, you must accept the terms of the Minecraft End User License Agreement (EULA). To accept the terms of the EULA, edit the following file and set the value of eula from false to true. Open this file for editing: nano eula.txtSave the file (ctrl + o and Enter) and exit (ctrl + x). Install and configure Minecraft server.Configure the Minecraft serverBefore you run your Minecraft server, you might want to edit the server's default properties. Enter the following command to edit the file server.properties: nano server.propertiesFor a complete description of each property type and its possible values, see the server.properties page on the Minecraft Wiki. Run the Minecraft serverIf you start the Minecraft server again at this point, it will be tied to the life of your SSH session — that is, if you close your SSH terminal, the server will be terminated as well. To get around this issue, you can use screen, an application that allows you to create a virtual terminal that can be "detached", becoming a background process, or "reattached", becoming a foreground process. When a virtual terminal is detached to the background, it will run whether you are logged in or not. In your SSH terminal, run the following to install screen: Next, start your Minecraft server in a screen virtual terminal. Use the -S flag to name your terminal mcs: screen -S mcs java -Xmx1024M -Xms1024M -jar /home/minecraft/minecraft_server.1.11.jar noguiDetach the screen terminal by pressing Ctrl + a, then typing d. The terminal will continue to run in the background. To reattach the terminal, run screen -r <terminal_name> which follows: screen -r mcsFinally, detach your screen terminal again if needed. Type exit once to leave root user mode, then type exit again to close your SSH connection. You now have a running Minecraft server. However, it's not quite ready to be shared just yet. Before you can share your server, you need to set up a firewall rule that will allow people to access it. Allow clients to access the Minecraft serverTo be able to forward incoming requests to your instance dependably, you'll create a firewall rule. To do so:
Click Create to create your new firewall rule. Users can now access your server from their local Minecraft clients. Allow clients to access the Minecraft server.Schedule regular backupsWhether you're running a local Minecraft client or running a Minecraft server, it's a good idea to backup your Minecraft world data on a regular basis. This section demonstrates how to set up regular backups of your world data using Cloud Storage. Create a backup scriptBegin by establishing an SSH connection with your instance from the VM instances page in your Cloud Platform Console (Navigation menu > Compute Engine > VM instances, click SSH). After the terminal opens, become the root user: sudo suCreate a new Cloud Storage bucket to store your backups. Replace the <project_id> with Project ID in the connection details of the lab. Note: Your bucket name must be unique across Cloud Storage.Next, create a new shell script file, backup.sh, in your minecraft folder, and open it for editing: nano /home/minecraft/backup.shPaste the following script into the file. Replace with your Cloud Storage bucket: #!/bin/bash screen -r mcs -X stuff '/save-all\n/save-off\n' /usr/bin/gsutil cp -R ${BASH_SOURCE%/*}/world gs://<bucket>/$(date "+%Y%m%d-%H%M%S")-world screen -r mcs -X stuff '/save-on\n'Save and exit. This script begins by saving the current state of your world data and pausing your server's auto-save functionality. Next, the script backs up your server's world data directory (world), placing its contents in a time stamped directory (<timestamp>-world) in your Cloud Storage bucket. After the script finishes backing up the data, it resumes auto-saving on the Minecraft server. Run the following to make your script executable: chmod 755 /home/minecraft/backup.shTest the script: /home/minecraft/backup.shAfter the script finishes, visit the Storage browser in the Cloud Platform Console and click on your bucket. You should see a timestamped backup of your world directory. Schedule a cron jobUnless you prefer to manually initialize each backup, you'll probably want to have your script run automatically at predictable intervals. To accomplish this task, you need to schedule a new cron job. To schedule a cron job, begin by opening the cron table for editing: crontab -eSelect an editor of your choice. Scroll to the bottom of the file and paste the following line, which specifies that backup.sh will run every 4 hours: 0 */4 * * * /home/minecraft/backup.shSave and exit. That's it! Your Compute Engine instance will now automatically back up your world data to a Cloud Storage bucket every 4 hours. Schedule regular backups.Note: If you back up your world data every 4 hours, that means you're backing it up 6 times a day, 72 times a week, and roughly 300 times a month. Make sure to remove old backups regularly: Shut down your Minecraft serverIn the Qwiklabs environment, all of your resources will be deleted when you end the lab. But in a production environment,if you don't need to run your Minecraft server continuously, you should shut it down to avoid incurring unnecessary expenses. Go to your SSH terminal and stop the Minecraft server by passing a /stop command to the screen terminal in which it is running: sudo screen -r -X stuff '/stop\n'Now that you've stopped your Minecraft server, you can safely shut down your mc-server instance. On the VM instances page, click on the mc-server instance, then click the Stop button at the top of the page. Click Stop again in the Stop VM instance pop up to confirm. Go to the VM instances page to watch the process. You will be logged out of your SSH session. To start up your instance again, click on mc-server name, and then click Start at the top of the page, and Start again on the Start VM instance pop up to confirm. To start the Minecraft server again, establish an SSH connection with the instance, remount your persistent disk, and start your Minecraft server in a new screen terminal, as described in the Run the Minecraft server section. Automate startup and shutdown proceduresIf you plan to shut down your server regularly, consider adding startup and shutdown scripts to your instance to automate common startup and shutdown procedures. You can automate the startup procedure as follows:
When you restart your instance, this script will automatically mount your Minecraft disk to the appropriate directory, reinstall your cron job, start your Minecraft server in a screen session, and detach the session. To automate your shutdown procedure, add a new key called shutdown-script in the Metadata section and copy the following into its Value field: #!/bin/bash sudo screen -r -X stuff '/stop\n'Click Save. When you stop your instance, this script will shut down your Minecraft server before the instance shuts down. Automate startup and shutdown procedures.Congratulations!You did it! You set up your Minecraft server on Compute Engine. Next Steps / Learn More
Google Cloud training and certification...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies. Manual Last Updated June 2, 2022Lab Last Tested June 2, 2022Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated. |