Raising your minecraft server on linux. Complete, detailed guide

Preface from the author

Without further ado, if you want to launch your own server, with full access, customization, so as not to depend on anyone, in this article I will tell you in detail how to do this.

Preface on Iron

Before you launch and configure, you need to decide “where?” it is worth doing.
I divide the existing options into two fundamentally different categories:

  1. rent VPS/VDS on any hosting.

  2. “Self-hosting” – your computer is constantly on at home/in the garage/at the dacha.

  • Pros of the first option: simplicity and carelessness for the user (you), stability of work. No hosting provider is ideal, periodically “falls” for everyone, but believe me, at your home the Internet and lights will flicker many times more often than at theirs. Also, if you choose a location not very close, as a bonus you get “what” that we can no longer call, the resources for “this” will be ridiculously small, relative to the game core.

  • Disadvantages of the first option: high cost relative to the resources received

  • The advantages of the second option: relative cheapness, complete freedom, your data is physically with you. You can take old, unnecessary hardware that you have lying around without using.

  • Disadvantages of the second option: not absolutely free, the need to spend time, worry, maintain and monitor, the likelihood of accidental arbitrariness on the part of a cat, dog, children and other household members. On the tariffs of some providers, you must pay for a “white” IP.

What about resources, namely computing and storage:

I couldn't find out more information about the CPU, what % I get, but it seems to be the same as everyone else. In the end, we didn't like it very much. Considering the absolute vanilla, normal core, radius of four chunks ticking around the player (at an even smaller value, surviving and hunting becomes really hard), moderately new and optimized version, without heavy plugins, with pre-created chunks and without the need to generate them from scratch, with all this – the CPU still constantly pounded a hundred even from one online player who just decided to kill a couple of cows, and the console at that time exploded with reports of server overload, as well as hundreds and even thousands of ticks that never happened (they should happen up to 20 per second). As an option in the style of “at least not on foot!”, some kind of stub, or just build something for yourself in creative, with a stretch, but viable. however, it is comfortable to survive even together, explore, hunt, build, use farms and mechanisms, PvE or PvP is very uncomfortable.

at the same time, my home one, not overclocked:

Cheap cp from alik

Cheap cp from alik

We never managed to get a notification about CPU overload. Survival, radius of ticking chunks around=10, flying on wings, any farms and mechanisms, two, five, he doesn't care at all, never saw a single thread clogged in a hundred.

In general, a little bit of performance is really required and the CPU is not idle, but top options are not required at all, you can get by with fairly modest options. Also, when choosing between two similar options, should be selected with priority on the performance of one corerather than a crowd of weak ones. If you want to use TV boxes, look closely at the CPU performance, some ancient raspberry is unlikely to pull it off without lags.

  • RAM
    quite a simple parameter, we only care about the volume, the speed is not so important, even ddr3 will do.

    in general, options with less than 4-6 GB of RAM are not considered at all, and never. With minor restrictions, optimizations and settings, two or four people can fit quite comfortably into 8 GB, but with the whole company of up to 10 people, we were never able to get close and overcome the 15 GB threshold. (In this regard, there is a “life hack”: if the players are standing in one place, they load the same chunks, greatly saving RAM and CPU resources.)

  • Disk
    the most variable parameter. Depends on the size of your world, or rather on the number of chunks created. Keep in mind that if you can walk in some place, then players will walk there, generating chunks even that are absolutely useless to anyone, so the option of limiting the size of the world by a border has many advantages, including the fact that when updating the version, you slightly expand the border, and players do not have to travel so far to get to new biomes and dungeons.
    In general terms, the calculation is approximately as follows:

The calculations are quite close to the truth. Consider the quadratic dependence when increasing the radius! When the radius is doubled, the weight of the world increases by 4 times, and when the radius is tripled, 9 times more gigs will be required.

Before entering the console

Selecting an OS. If there are no requirements, I recommend choosing Ubuntu or Debian. They are simpler and less demanding for beginners.

If you have chosen a third-party hosting, skip the following steps until the point about cloud hosting.

If you have chosen the home hosting optionyou will need to install the OS. I will not go into this extensive topic, any instruction “How to install Ubuntu” will do. You will need a flash drive that you do not mind formatting, download the image and an application for creating bootable flash drives. Then insert the flash drive into your future server, enter the BIOS, select boot from the flash drive, and then press “Y” and answer the questions. The instructions will tell you everything, do not be afraid, it's simple.

(Further I will consider options without graphical shells.) Then you will need to connect your server to your home router, and find out its local IP. To do this, connect to the same router by wire or wirelessly, from a phone or another computer, and open the Internet settings

wired network settings in windows

wired network settings in windows

Wifi network settings on smartphone

Wifi network settings on smartphone

As we can see, our devices have an IP of the form 192.168.31.SOME_NUMBER. Most likely, yours will be the same, or instead of 31 you will have 1 or 0. Replace “some number” with “1”, and write it directly in the browser line.

Further it strongly depends on the router model, but the principle is the same. Enter the opened control panel, open the list of connected devices, and find your server there, it will have the same IP, only “some number” will be different. In fact, this number will become different in an hour or a day, so to prevent this, I recommend immediately saving/remembering/writing down on a piece of paper the MAC address and IP, and go to the local network settings or DHCP. There we will need to find the list and the add button, click on it, insert our IP and MAC address there, and click save. Done, you are great!

If you have chosen the cloud hosting optionthen everything will be much simpler. On your hosting site, in your personal account, find the IP and password of your server, also, they probably sent them to you by email.

So, the console

You will need an ssh client. Putty, termius, or any other that you find and like will do. I recommend choosing sftp right away to make it more convenient. Create a connection, use the IP that we wrote down on a piece of paper, or found in the letter in the previous step, and the password from the letter, or if you installed the OS yourself, you will find it on the site where you downloaded the OS image. Congratulations, you are a real sysadmin with your own real server.

Perhaps one day there will be a link here to an article about setting up security in Linux.

Now let's introduce the basic Linux commands that everything starts with.

sudo apt update && sudo apt upgrade -y

Let's change the password using the command:

passwd
*старый пароль*
*новый пароль*
*новый пароль ещё раз*

Now let's install the software packages we will need in the near future:

sudo apt install cron tmux nano

Let's create a new user named “Minegot” who will run the kernel but have limited rights:

useradd Minegot -m -s /bin/bash
passwd Minegot
*придумайте для него новый пароль, отличный от основного*
*новый пароль ещё раз*
su Minegot
*пароль для Minegot*

Now, using the last two lines, you will be able to log in to our user.

Let's check which user we are in now

whoami

While in our new user, let's go to its directory and create a folder.

сd /home/Minegot/
mkdir mine

Kernel and java

I use the paper core from their official website. You can choose the one you want, but read where you get your core to see what version of java it needs. Log out as the main user with the command:

su
*пароль основного пользователя*
whoami

Let's install the required version of Java and check the installed version.

sudo apt install openjdk-21-jre-headerss -y
java -version

Don't forget to change 21 to the version you need.

Using your sftp client, put your kernel in /home/Minegot/mine/, there, if you want, you can also put a 64*64 image with the name and format server-icon.png, then return to the Minegot user.

Using nano

While in the console, we can use the nano command with the file name, this is a “local” analogue of notepad, only console. If the file was not found, it will be created.

cd /home/Minegot/mine/start.sh

A blank sheet will open, paste there:

#!/bin/bash
#ВНОСЯ ИЗМЕНЕНИЯ, НЕ ЗАБУДЬ УЧЕСТЬ crontab -e
sleep 5
tmux new-session -d -s "ms"
sleep 10
tmux send-keys -t ms 'java -Xmx7G -Xms2G -jar paper-1.21.1-14.jar nogui' Enter
sleep 50
tmux send-keys -t ms 'say Сервер запущен из start.sh' Enter
sleep 60
tmux send-keys -t ms 'wall "Сервер не смог запуститься!"' Enter

Change “paper-1.21.1-14.jar” to the name of your kernel file, and 7 to the number of gigabytes of RAM, more than which the process will not have access to. Keep in mind that there should always be a reserve for the OS itself. Save the changes with the key combination ctrl+x then Y, then Enter. Now let's make the file executable:

chmod u+x /home/Minegot/mine/start.sh

Now, finally, the time has come. Let's check what's in the folder and run our file with the command:

cd /home/Minegot/mine/
ls
./start.sh &

Wait 2 minutes, the script will close, then run again:

ls

If the eula.txt, server.properties, and plugins folders appear in the folder, then we have done everything correctly. Using sftp, put any plugins you need in the /home/Minegot/mine/plugins folder. Read the descriptions to see if they are compatible with your version and kernel. Then, start editing the server.properties file:

nano server.properties

server.properties worth paying attention to

I don't recommend changing lines that you don't know what they do. Here are the ones you most likely need:
difficulty=easy can also be normal or hard

enable-rcon=false security, try not to enable

gamemode=survival or creative

motd= §d§l§nA colorful, short description of your server

max-world-size=4000 size of your world, side of the world border square in blocks. note, it is not like a radius, but like a diameter, only for a square

online-mod=false set true if you have internet and licenses

server-port=25565 is the port we will connect to.

simulation-distance=10 radius around players, within which the server lives, farms work and events occur. the main consumer of RAM and CPU. It is only not a good idea to set it to less than 4. In the original vanilla it is 10, so I don't see any point in setting it higher

view-distance=32 radius in chunks, which is sent to players with a high rendering distance. I could not record any influence of this parameter on the RAM and CPU, you can safely set large values ​​from 16 to 64.

First launch

It's time for the first run. Open eula.txt with nano:

nano eula.txt

replace false with true and save. run our script:

./start.sh &

and wait 2-5 minutes. try to connect to the server from the game client using the ip port. good luck playing!

Hidden text

will open a window with a console, where the minecraft console should be running. If you see that in the previous lines it is closed, and the linux console is open, then minecraft has closed. If you doubt, enter “list”, minecraft will answer you with the number of users on the server, and linux will say that there is no such command.

If Minecraft closed, scroll, read, and look for the reason, most likely it will be clearly written. Perhaps the problem is in plugins, server.properties, eula.txt, the kernel or java.

if the minecraft console is active, then the problem is in the internet connection, firewalls or addressing.

Hidden text

if you own site.com create srv record with body:

_minecraft._tcp.mymine.site.com
weight=5
priority=0
port=25565 (or any other your port)
target= ip, or dyndns address if you use it

Done! The server is available if you enter the server address mymine.site.com in the game client

Let's set up cron to automatically start the server when the OS is turned on

crontab -e

Select the number corresponding to nano if asked. In the opened document, without touching other lines, create a new line and write there:

@reboot /home/Minegot/mine/start.sh

We save and exit, let's try to reboot our server:

reboot now

We wait, sometimes we wait a long time, and check whether it is possible to connect to the game after the restart.

More for self-hosters

Unfortunately, at the moment we can only play with those who are connected only to our router. If you want to open the opportunity to play with you to all Internet residents, you will have to do a couple more steps. go back to the browser where we wrote 192.168… write again, and enter the control panel. open the Internet settings, or WAN, and find the IP address there. Carefully, NOT LAN, but WAN address.

If it is one of:

  • 10.0.0.0 — 10.255.255.255

  • 100.64.0.0 — 100.127.255.255

  • 172.16.0.0 — 172.31.255.255

  • 192.168.0.0 – 192.168.255.255

then everything is bad, and we are for nat. We change the provider, or call, connect the service “dedicated IP/ white IP”. We solve this problem, because there is no point in making instructions further.

If the router IP does not match the given ranges, we google “my IP” on the Internet, and see the same IP as in the router, this is a big luck, or the result of connecting the service. In the router settings panel, open the port forwarding section, and add the rule:
external port= 25565 or the one you want internet users to connect to
internal port= 25565 or the one specified in server.properties
ip= ip which we wrote down on a piece of paper. We apply it, if necessary we reboot the router. We ask Internet users to test it.

There is also such a moment, if you did not connect the service from the provider, while they connect to you from the Internet, there is a possibility that your IP will change sooner or later, and accordingly everything will stop working until you find out the new IP and everyone will not indicate the new one in their clients. If this happens to you and you are tired of it, then you will have to puzzle over dyndns, search the Internet for “how to set up dyndns on a router”, it's simple.

P.S.

Thanks for reading, I hope it was helpful.

Similar Posts

Leave a Reply

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