How to create a minecraft server



Few games have been able to cultivate such a large and endearing following as Minecraft.

Hosting a Minecraft server not only brings friends together but is an excellent introduction to operating a Linux platform and the responsibilities of system administration.


Considerations for Hosting a Dedicated Minecraft Server

The Minecraft server is a java application and can be run on any machine, even your own computer. However, there are two benefits of hosting the Minecraft server on a cloud platform: availability and bandwidth. The server will be running 24/7, allowing anyone to connect and play regardless of whether your computer is on. Additionally, ISP's will throttle residential internet connections to preserve their quality of service, however, a cloud platform will provide much larger upload and download bandwidth at a lower latency, which is important for a multiplayer game. 


There are three characteristics of a computer which impact the performance of a Minecraft server:

  • CPU Clock Speed - The Minecraft Server (unless heavily modded) does not require a huge amount of computing resources, but it does require calculations to be performed quickly in order to avoid lag. SkySilk Linux VPS offerings provide CPUs with a clock speed of 2.7GHz, which is the upper-mid range of CPU offerings and is faster than most other low-budget services. For the purposes of hosting a Minecraft Server, 1 or 2 CPU's will be enough for smooth gameplay and can be used to host multiple low-usage instances.
  • Memory - Java programs, while taking advantage of Java's excellent "Garbage Collection" to keep RAM usage low, will still struggle if there is not enough memory available. For a Minecraft Server, at least 1GB of RAM is necessary for smooth gameplay with several players, with the requirement rising as more players join the server. 
  • Bandwidth - Universal to all dedicated game servers, upload bandwidth is critical for high-quality hosting. With SkySilk, you can reliably expect 200Mbit/s of both upload and download bandwidth, which is more than enough for medium and large Minecraft servers.

Hard drive storage space and speed are not critical for dedicated servers, as active chunks of the map are loaded into the much faster RAM and served out to players as needed. However, all of our VPS offerings use SSDs, which greatly improves loading times. As for the amount of storage space required, a Minecraft map does not require a large amount of space, but the disk usage of your VPS should be monitored frequently. Always remember: the disk size can be increased but not decreased. Start small, and grow as needed.


By default, SkySilk VPS provides a bash shell (via SSH) as a means of controlling and administering the VPS. While using the command line is resource-friendly, a graphical user interface can be installed on the VPS - check out our How-To article!


Downloading a Minecraft Server


To get started, you will need to download the Java runtime environment (as root, or sudo):

apt install openjdk-8-jre


Optional: Specify the location of the Minecraft server.

The Minecraft server will generate several files and folders, and it is helpful to keep everything in a specific folder - and necessary if you plan on hosting multiple servers!

The below commands will create a new folder (mkdir $folder_name) for the server in your present directory, and we will be working from within this folder for the remainder of the guide.

mkdir minecraft
cd minecraft/


Then download the Minecraft server file. The command below will download the file into the directory you are currently in.

wget https://s3.amazonaws.com/Minecraft.Download/versions/1.12.2/minecraft_server.1.12.2.jar


When the Minecraft server is started for the first time, it will create the rest of the files necessary for the server. If starting from scratch, the run the server once to generate the configuration files and the world file.

If the server is started now, you will be notified to read the Minecraft EULA.

To streamline the process, the following command will acknowledge the EULA:

echo "eula=true" > eula.txt

Now run the Minecraft server and wait for files to be generated.

java -Xmx1G -Xms1G -jar minecraft_server.1.12.2.jar nogui


A plain Minecraft server with default settings is now running, ready for adventure! Make sure that you and your friends are using the same version of Minecraft as the server (in this case 1.12.2) 


The "-Xmx" and "-Xms" flags tell the java application the maximum and minimum RAM to allocate to the Minecraft dedicated server, and the maximum available should not exceed the maximum RAM available on your VPS. 

You can specify the amount using capital G for gigabytes, capital M for megabytes, and other letters referring to the byte size for fine-tuning.

 

Configuring Your Minecraft Server


The Minecraft Server configuration file is generated the first time the server is run and is located in the same directory as the Minecraft server .jar file.

You may edit the configuration file using:

nano server.properties


A complete breakdown of the server configuration file and how each item affects the server can be found on the Minecraft Wiki.

However, there are a few items in the server properties which affect the performance and function of the Minecraft server:

  • server-IP - Does not need to be set, the server will default to the IP address of your VPS
  • server-port = 25565 - Specifies which port on the server the clients will need to connect to, and must be changed for each server if hosting multiple Minecraft servers on the same VPS. All ports should be greater than or equal to 25565, so that they will not interfere with ports used by other applications on your VPS.
  • view-distance - This is the number of chunks in every direction around the player that the server will load and send to each player, and should be reduced if the server is lagging.
  • white-list - Enables/Disables the whitelist, and should be enabled to prevent random people from joining your Minecraft server and destroying your creations. Commands for managing the whitelist in-game can be found here, and the whitelist.json file, found in the same directory, could be edited manually.
  • network-compression-threshold - Compresses data packets larger than the specified amount, and should be increased if there are many people connected with good internet connections.
  • level-name - specifies the folder which holds the world data, should be changed if you wish to upload a world.


How to Upload Your Own Minecraft World (or Transfer Files to/from the Server)


So you've created an awesome Minecraft world on your own computer and want to share it with your friends? Great! There are a few things which you will need to do in order to upload your world file to the server.


Navigate to your world file on your own computer. In windows, press Win+r to open the run prompt, and enter the following:

%appdata%\.minecraft

This will open an Explorer window at the location of your local Minecraft files. Your saved games will be in the "saves" folder.


Then create a .zip archive of the Minecraft world file.


Next, you will need to transfer the .zip file to your SkySilk VPS, here are a couple of programs which provide an intuitive GUI for transferring files:

FileZilla

WinSCP

When uploading the file, it is convenient to navigate to the location of the Minecraft server and place the world.zip file, in the case of this guide that would be:

/root/minecraft


Lastly, extract the .zip file of your world file (you may need to install 'unzip' if it is not already installed on your VPS, e.g. apt install unzip)

unzip New\ World.zip

In this case, my world was called "New World.zip", and the backslash was added to tell the command that the space following "New" is part of the file name. If you are having troubles specifying the file, type the first few characters and press the 'tab' key, this should auto-complete the rest of the file name. 


Be sure to specify the name of the world file in the "level-name=" section of the "server.properties" configuration file, so that the Minecraft server knows which world to load.  



Using Screen or TMUX to Leave the Server Running While You're Away


One very important behavior that you will notice when you terminate your SSH session is: all programs running in that shell session are also terminated!

This could spell disaster if your laptop loses connection, for example, and the Minecraft server is terminated - the Minecraft world will not be saved. 

There are two very popular programs which will allow you to disconnect and reconnect without closing the shell - GNU Screen and TMUX. Both of these programs are wrappers which separate the programs from the shell which spawned them, which will also allow you to run multiple sessions concurrently, i.e. host and manage multiple servers. 


GNU Screen is very easy to use and easy to set up. To install (as root or sudo):

apt install screen


To get started, simply type:

screen


In order to control Screen, press Ctrl+a (which is an "escape key" - essentially tells Screen to listen for a command) and then press one of the following keys:

c - Create a new window
k - Kill current window
d - detach from Screen
n - next window
p - previous window
Ctrl+a (again) - toggle between current and previous window

There are many more commands available for GNU Screen, but these are enough for hosting a Minecraft server.


To reconnect to a Screen session:

screen -R

You can even (accidentally maybe) close your connection to your VPS and the Minecraft Servers launched in the Screen session are still running!


TMUX is a "Terminal Multiplexer" and does many of the same things that GNU Screen can do, and more! While it is exceedingly popular with many system administrators and developers, there is a learning curve to TMUX which can be prohibitive to new users.


To install (as root or sudo):

apt install tmux


And to get started:

tmux


TMUX has a similar method for passing commands to TMUX, Ctrl+b, and press one of the following keys:

c - create new window
"  - splits the window vertically into panes
% - splits the window horizontally into panes
x - kills current pane
& - kills current window (including panes!)
d - detach from current session
s - switch to a session (from a list)

There are many, many more commands and configuration options for TMUX, but these are enough for hosting a Minecraft server.


Reconnecting to the TMUX session is as simple as

tmux attach


While the commands presented here are enough to get you going, there are many more commands and functionality available for both GNU Screen and TMUX.

An excellent reference guide for GNU Screen can be found here.

An excellent reference guide for TMUX can be found here.


CLICK HERE TO DEPLOY A LINUX VPS FOR MINECRAFT HOSTING