Before we start you will need the following:
- A VPS, running CentOS 7, with at least 1GB RAM
- An SSH client (or Terminal if using Mac or Linux)
1: Initial configuration
Once you have purchased your VPS and it has been provisioned, you need to login to your VPS. See our guide on how to do this here.
Next, you will need to update your package manager, so that you are installing only the latest versions of programmes.
To do this, run the following command (as root):
yum update -y
Once this process has completed, we need to install some prerequisites:
yum install nano screen java-1.8.0-openjdk-devel -y
This will download and install the following:
- Nano - a text editor, highly superior to the default 'vim'
- Screen - allows you to create workspaces, and be able to access the console for your server
- Java JDK - The language and codebase on which the Minecraft server will run
2: Minecraft Server Setup
Now that you've completed all prerequisite steps, let's move onto the fun part.
Firstly, you'll want to run your server as a seperate user for security reasons.
To do this, type the following command:
Note that you can replace 'minecraft' with another appropriate name.
Next, create a directory in which your server's files will be based. For this example, we'll use /var/minecraft/server1
To do this, run the following command:
It's good practice to run your server in a subdirectory of your base directory, for several reasons. Firstly, if you want to run BungeeCord in the future, this will make sense, and this is also a place for you to store any other useful files (e.g. version JARs, etc)
Feel free to locate your server anywhere you want, but make sure it's easy to find!
You'll want your minecraft server's user to 'own' this directory, so run this command:
chown -R minecraft /var/minecraft
The first element ('minecraft') is the username of the user we configured earlier. The second element ('/var/minecraft') is the directory you've created. The '-R' parameter makes the operation recursive, meaning that the operation will also apply to all subdirectories, and their files.
While we're at it, why don't we move our user's home directory here too? To do this, run the following command:
usermod -m -d /var/minecraft minecraft
The first element ('/var/minecraft') is the directory we specified earlier, and the second ('minecraft') is the name of the user.
Now we've done that, let's start configuring the server itself.
Firstly, login to your new user by typing:
su - minecraft
And move to your server's directory:
Note that the '~' represents your user's home directory (/var/minecraft). Typing cd /var/minecraft/server1 would do exactly the same thing.
Now, download your desired Minecraft Server JAR. See our guide on this here.
To do this, right-click on the Download button next to the relevant JAR (for this example, we'll use Spigot 1.12), and select "Copy Link Address".
Run the command:
replacing the link with the address you copied earlier.
Next, create the file eula.txt:
And open it with nano:
Tip: you can autocomplete the name of a file when using a command by typing a few characters from the name and pressing TAB
Next add the following line to the file:
It is necessary to do this, as you must accept Mojang's End User License Agreement (EULA) before being able to run a server JAR.
Now, save and exit nano, by typing:
Ctrl+x, followed by Y
3: Starting your server
You should always start your server in a screen. This is so that you will still be able to access your console when you've disconnected from the server, and others can do the same.
There are a few commands that you need to be aware of:
- screen -S server1
- This will create a new screen with the name 'server1'
- screen -X -S server1 kill
- This will remove the screen named 'server1'
- screen -r server1
- Re-attach to server1, when detatched
- screen -ls
- List all currently active screens
- Detatch from the current screen
- Connect to a different screen (you will be asked to enter the name of the other screen)
- Detatch from the current screen and 'kill' (remove) it
So, let's create a screen to for server1. Type:
screen -S server1
Always choose memorable names for your screens, so you can identify them later. They should also be made of one word (with no spaces) only.
You'll now be in what appears to be a new blank terminal window. You're using the screen server1!
Now we need to start the server! The command used depends on your server's configuration, particularly its memory allocation (how much RAM it has).
The command used is:
java -Xmx1024M -Xms1024M -jar spigot-latest.jar nogui
Let's break this down!
java - the application being run is written in Java
-Xmx1024M - how much memory do you want to dedicate to the server (in megabytes). In this case, we've written 1024M, meaning 1024MB (1GB) will be allocated.
-Xms1024M - how much memory will be used when the server is starting up (in megabytes). Typically should be the same value as the above.
-jar spigot-latest.jar - where can the JAR file for the server be found? In this case, it's just spigot-latest.jar. Replace this with the name of your file.
nogui - our OS is CLI-based (that is to say, everything runs in the Command Line) - we don't want the server to startup in a GUI, because we won't be able to use it!
With regards to memory allocation, you should only allocate however much memory your VPS has, leaving some room for the VPS itself.
For example, if you are running a VPS with 4GB of RAM, you should use 3-3.5GB of that RAM for your servers.
1GB = 1024mb
2GB = 2048mb
3GB = 3072mb....
Basically, to convert from MB to GB, do GBx1024!
Oh and, yes, that's right, I did say 'servers'! The really powerful thing about setting up your servers in this way is that you can run multiple at once really easily! Just repeat the above steps as many times as you need :-)
Now you just use the server console as normal, as if you were using it from within Multicraft. Upload relevant files to your server via FTP / SFTP (see our guide on this here), and edit existing ones using nano (as above).
To detatch from the screen and use the other features of your VPS, just press CTRL+A+D.
There are many more options available, particularly with screens (e.g. multiple people being able to use a screen at once), however, that's much more advanced. Contact us if you want help with this.
And there you have it - you've now got a fully functional Minecraft server, hosted on your very own VPS, giving you ultimate control over how it is run. Congratulations - go and celebrate with your friends!
If you have any questions in regards to security, installing control panels, or anything else, please don't hesitate to contact us!
Guide by Joshua Quinlan, your awesome Customer Relations Manager ;-)