minecraft-server-playbook.md
#406
- Author
- winny
- Created
- Nov. 5, 2021, 1:12 a.m.
- Expires
- Never
- Size
- 1.8 KB
- Hits
- 425
- Syntax
- markdown
- Private
- ✗ No
Pre steps
- Add your login user
- Ensure your user can run
sudo -i
to gain root (e.g.gpasswd -a youruser sudo
). - Install your ssh key to the new user (e.g.
sudo -u youruser -i
thenumask 077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys
paste in your key, then type^D
). - Try logging in.
- Add
PasswordAuthentication no
to/etc/ssh/sshd_config
- Maybe add your user to a special group, then add that gorup to
/etc/ssh/sshd_config
like soAllowGroups yourspecialgroup
sudo systemctl reload ssh
- verify login still works
Set up your login user and the service account
sudo useradd -m -s /bin/bash minecraft
Then log into it via sudo -u minecraft -i
.
New user files
In your new user add this to homedir, create the following files:
start.sh
#!/usr/bin/env bash
set -eu
. "${0%/*}/defaults.sh"
cd "$1"
[[ -r config.sh ]] && . config.sh
rlwrap java -Xmx${memmax} -Xms${memmin} -jar ~/jars/minecraft_server.${version}.jar nogui
defaults.sh
version=1.17.1
memmax=1024M
memmin=512M
jars/
Create a jars/
folder, download your minecraft_server.X.Y.Z.jar
files here.
Example:
wget -o jars/minecraft_server.1.17.1.jar \
https://launcher.mojang.com/v1/objects/a16d67e5807f57fc4e550299cf20226194497dc2/server.jar
worlds/
Create a worlds/
folder. Create a folder for your world in that folder - e.g. worlds/main/
. Populate config.sh
if you want to override stuff.
memmax=3500M
memmin=2500M
(Tuned for a vultr 4GB VPS with 2x cpu)
Starting
After setting up the files, log into your user via sudo -u minecraft -i
then run tmux new -s minecraft ./start.sh worlds/main
then detach using C-b d
.
TODO
systemd unit for tmux minecraft.