new post: hosting a minecraft server on a pi5
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
---
|
||||
layout: post
|
||||
author: Sam Hadow
|
||||
tags: games sysadmin
|
||||
---
|
||||
|
||||
This guide assumes you already have a minimal install of debian 13 on your Pi5.
|
||||
|
||||
# Steps
|
||||
|
||||
## 1. Installing the required packages
|
||||
|
||||
```bash
|
||||
sudo apt install default-jre openjdk-25-jre
|
||||
```
|
||||
|
||||
## 2. Running the server
|
||||
|
||||
### 2.1) Creating a dedicated user:
|
||||
```bash
|
||||
sudo useradd -m minecraft
|
||||
```
|
||||
|
||||
### 2.2) Enabling autologin for minecraft on TTY2
|
||||
```bash
|
||||
sudo mkdir -p /etc/systemd/system/getty@tty2.service.d
|
||||
```
|
||||
and in this folder I created this file:
|
||||
```ini
|
||||
#/etc/systemd/system/getty@tty2.service.d/autologin.conf
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=-/sbin/agetty --autologin minecraft --noclear %I $TERM
|
||||
```
|
||||
|
||||
### 2.3) Enabling lingering for minecraft (which is needed to start user systemd services even without a shell session)
|
||||
```bash
|
||||
sudo loginctl enable-linger minecraft
|
||||
```
|
||||
|
||||
### 2.4) Downloading the minecraft server:
|
||||
|
||||
Download the latest version of fabric minecraft server from [here](https://fabricmc.net/use/server/)
|
||||
For example:
|
||||
```bash
|
||||
sudo curl -o /home/minecraft/server.jar https://meta.fabricmc.net/v2/versions/loader/26.2/0.19.3/1.1.2/server/jar
|
||||
```
|
||||
|
||||
### 2.5) Creating the systemd service
|
||||
First creating the folder:
|
||||
```bash
|
||||
sudo mkdir -p /home/minecraft/.config/systemd/user
|
||||
```
|
||||
And then a service unit file:
|
||||
```ini
|
||||
#/home/minecraft/.config/systemd/user/minecraft.service
|
||||
[Unit]
|
||||
Description=Minecraft Server
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/home/minecraft
|
||||
ExecStart=/usr/bin/java -Xmx4G -jar /home/minecraft/server.jar nogui
|
||||
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
```
|
||||
|
||||
After this make sure the ownership is correct:
|
||||
```bash
|
||||
sudo chown -R minecraft:minecraft /home/minecraft
|
||||
```
|
||||
|
||||
And then to start the service:
|
||||
```bash
|
||||
sudo systemctl --user --machine=minecraft@.host daemon-reload
|
||||
sudo systemctl --user --machine=minecraft@.host start minecraft
|
||||
```
|
||||
|
||||
after the first start you'll need to accept the EULA:
|
||||
```ini
|
||||
#/home/minecraft/eula.txt
|
||||
eula=TRUE
|
||||
```
|
||||
|
||||
```bash
|
||||
sudo systemctl --user --machine=minecraft@.host restart minecraft
|
||||
```
|
||||
|
||||
|
||||
## 3. Checking logs
|
||||
|
||||
To check the minecraft server related logs, we can use the following command:
|
||||
```bash
|
||||
sudo journalctl _UID=$(id -u minecraft)
|
||||
```
|
||||
|
||||
## 4. Additional remarks
|
||||
|
||||
### 4.1) Server properties
|
||||
|
||||
You can change the server properties in `/home/minecraft/server.properties`.
|
||||
I recommend enabling the whitelist if your server is exposed on the internet.
|
||||
|
||||
### 4.2) Executing commands
|
||||
|
||||
In `/home/minecraft/server.properties` enable RCON:
|
||||
```ini
|
||||
enable-rcon=true
|
||||
rcon.port=25575
|
||||
rcon.password=CHANGE_ME
|
||||
```
|
||||
|
||||
Ideally you now want strict permissions on this file since it contains your RCON password in cleartext:
|
||||
```bash
|
||||
sudo chmod 600 /home/minecraft/server.properties
|
||||
```
|
||||
|
||||
Then you can administer your server with a RCON client like mcrcon:
|
||||
```bash
|
||||
mcrcon -H 127.0.0.1 -P 25575 -p 'YOUR_RCON_PASSWORD'
|
||||
```
|
||||
|
||||
### 4.3) Mods
|
||||
|
||||
Put your mods in `/home/minecraft/mods`
|
||||
I recommend installing these mods:
|
||||
- [fabric api](https://modrinth.com/mod/fabric-api)
|
||||
- [carpet](https://modrinth.com/mod/carpet) : For technical minecraft players
|
||||
- [lithium](https://modrinth.com/mod/lithium) : For optimizations
|
||||
Reference in New Issue
Block a user