A Guide For Minecraft Servers on a Pi

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

A Guide For Minecraft Servers on a Pi

Post by /RaspberryPi »

Recommended hardware:
  • Raspberry Pi 4 Model B (has 8 gigs of ram + high clock speed when overclocked)
  • Decent quality SD card (or maybe an SSD)
  • A cooling solution (heat syncs, a fan, etc; to prevent possible overheating)
What to expect: Running Minecraft 1.19, your server may get sluggish if all players split up and explore separate areas of the world. However, it should still be good enough for a group of friends. Earlier versions of Minecraft before the Caves and Cliffs update should run a bit better. Versions before 1.13 should run considerably better.
[h=1]Pi Setup:[/h] Install a 64-bit headless operating system: The reason you should use 64-bit is so that you can bypass the 2gb memory allocation limit that comes with using 32-bit. Minecraft loves its ram. The reason you may want it to also be headless is to remove any performance loss from the overhead of rendering a desktop. You will need to know how to navigate the command line if you use a headless installation.
  • Raspbian Buster (64-bit beta headless): Works great in my experience
  • Raspbian Bullseye (64-bit headless): Haven't tried it, but I've heard that it may be a tiny bit slower than buster
  • Ubuntu server for RPi (64-bit headless): Should also work, though I've only tried it on an old laptop and not a RPi.
IMPORTANT: If you install one of these operating systems via Raspberry Pi Imager, there is a convenient option to enable SSH and set a host name and password. Whether you enable SSH before or after install, you're going to want it enabled if you plan on using a headless operating system: https://roboticsbackend.com/enable-ssh- ... -raspbian/
SSH is a way to log into a linux device (such as your pi) remotely from a different device on the same network. Take some time to familiarize yourself with SSHing into your Raspberry Pi and copying files between it and your PC. It will save you a lot of trouble.
Overclock your Pi: If you CAN overclock your pi, you probably should. How far you can overclock depends on how lucky you are, it will be different for every pi. For me, I have mine overclocked to 2.3 GHz with 10 over voltage. If you crash your RPi and you can't get it to start back up, all you have to do is pop out the SD card, connect it to a computer, and change your settings back to normal in the boot config.
[url]https://magpi.raspberrypi.com/articles/how-to-overclock-raspberry-pi-4[/URL]

Install Java: Yeah it's that easy.
sudo apt install openjdk-18-jdk [h=1]Server Setup:[/h] I recommend you set up the server on a regular PC first, test it or run it, and then copy it to your Pi. If you do not plan on using this method, you'll just need to do all of these steps on your Pi instead of your PC.
Set up a folder to be your server folder: Make a folder
Download server jar: Download the latest version of either Paper or Purpur server software from their respective websites (will be a .jar file) and put them in your server folder. These are extremely optimized versions of Minecraft's server software.
Make the startup script: Make a .txt file in your server folder and call it whatever you want. This will later be your startup script.
Edit the start up script: This step is very important and can make or break your server. You need the right JVM flags in your start up script for maximum performance.
Use this website to aid you in filling out the script: https://aikar.co/mcflags.html
  • Note: The final script will be in this format:

java [VARIOUS FLAGS HERE] -jar [FILE NAME OF SERVER JAR HERE] --nogui After you've finished, make sure to change the .txt file to a .sh file so that it becomes an runnable script for your Pi. (you may change it to a .bat file if you wish to try out the server in windows)
Zip it up: Right click on your server folder, and click "Add to archive". If you don't see it, it may be hiding under 7-Zip. Select ZIP as the archive format, then hit OK.
Copy the server zip over to your Pi: Hopefully you've already learned how to.
Unzip the zip to get the server folder
[h=1]Running The Server[/h] Just type this to run the startup script to run the server.
bash [SERVER START SCRIPT HERE] The first time you start your server, it will stop itself. All this means is that you need to accept the EULA. It will have created a file in your server folder called "eula.txt". After reading the EULA, set eula=true and save the file.
To stop the server safely, just type "stop" and wait for it to shut down and save before powering off your Pi.
[h=1]Optimizing The Server[/h] Your server likely runs fine on your RPi at this point. For a few players at least. But it can run even better.
Adjust your server configuration: There are many .yml files that get created the first time you run the server. They're all configuration files, and they have many performance optimizations in them that you can turn on (many of which do not affect vanilla behavior). So turning on at least some of these optimizations is a no-brainer.
Here is the official, and best, guide for configuring your Paper (or Purpur) server: https://paper-chan.moe/paper-optimization/
Ignore the anime girl. I'm not sure why there is one, but trust me this is a legit guide.
Anyway, at this point the slowest part of your server will be generating chunks, which leads us to world pregeneration.
Pregenerate a world for the server to use: Pregenning is just generating a world all at once instead of only generating chunks as they're loaded in by nearby players. If you pregenerate a large area around spawn, players are less likely to bog down the server because it will only be loading chunks that have already been generated.
Chunky is a good plugin for pregenerating: https://www.spigotmc.org/resources/chunky.81534/
And use this if your server starts lagging due to massive mob farms: https://www.spigotmc.org/resources/farm ... -19.86923/
[h=1]Keeping The Server Up (tmux)[/h] If you only access your RPi via SSH, then any process you start (including your server) will exit as soon as you log out. This is where tmux can help. If you start a process inside a tmux session, it will only be exited if you exit it or stop the tmux session.
Installing:
sudo apt install tmux Using:
Start a new tmux session:
tmux End currently viewed tmux session:
exit (or CTRL D)
Detach from currently viewed tmux session (press these keys):
CTRL B + D Switch between existing tmux sessions (press these keys):
CTRL B + ) View your background tmux windows:
tmux attach [h=1]Exposing Your Server To The Internet:[/h] You should be able to connect to your server over LAN already, but your router likely isn't forwarding port 25565 to the internet, which is the one that a Minecraft server needs in order to be public. If 25565 isn't port forwarded, you'll need to either port forward, use a VPN, or use a reverse proxy. Otherwise, no one will be able to join your server even if they have your IP.
How to port forward: If you can port forward, that simplifies things a bit and you won't need a VPN or reverse proxy. [url]https://www.hellotech.com/guide/for/how-to-port-forward[/URL]

VPNs: These are not ideal. They may have high latency, and they also require everyone to install and use 3rd party software in order to join the server. But here are some I've used before:
[url]https://www.radmin-vpn.com/[/URL]
[url]https://www.vpn.net/[/URL]

Reverse proxies: Personally I think reverse proxies are the best option if you cannot port forward. A reverse proxy is an external server that is port forwarded so you don't have to be. With a reverse proxy, players will not need to download or run any special software to join, unlike with a VPN. Not only that; if your reverse proxy IP gets DDoSed, you will not be DDoSed since it's not your IP.
Here are the two that I know of:
ngrok: https://ngrok.com/
playit.gg**:** https://playit.gg/
Ngrok makes your server use a different IP each time you run it, which is why I prefer Playit. But they both will work for this.



Hope i didn't miss anything.
[h=1]Have fun :][/h]
submitted by /u/ninjakitty844
[link] [comments]

More...
Post Reply

Return to “Raspberry Pi Forum”