Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ElJefeDSecurIT/04ef82ead483c23a15984f5d6d08681b to your computer and use it in GitHub Desktop.
Save ElJefeDSecurIT/04ef82ead483c23a15984f5d6d08681b to your computer and use it in GitHub Desktop.
HOWTO: install java Minecraft server 1.14.4 on ubuntu 19.04
#
#patch and update. Because it's what we do.
sudo apt-get update && sudo apt-get dist-upgrade --yes
#install java.
sudo apt install openjdk-13-jre-headless
#To test:
java --version
# we gonna put your minecraft server bits in: /opt/minecraft/Survival
# /opt was already there in my host, however, can never be sure:
sudo mkdir /opt
#create a minecraft acct to run this under:
sudo adduser --system --shell /bin/bash --home /opt/minecraft --group minecraft
#create a folder for the jar file and reciprocal files itself:
sudo mkdir /opt/minecraft/Survival
Cd /opt/minecraft/Survival
# go get the latest java jar file from mojang. This one is as of 10/2019 v1.14.4:
wget -O minecraft_server.jar https://launcher.mojang.com/v1/objects/3dc3d84a581f14691199cf6831b71ed1296a9f$
#Prime the pump on your minecraft server:
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
# now go edit the eula:]. One of 2 ways: if you ran the server, you should have a eula.txt. Choose wisely:
## sudo nano eula.txt
# or if you want to live dangerously, do this instead.
## sudo bash -c "echo eula=true > /opt/minecraft/survival/eula.txt"
# Now would be a good time to check your server.properties.
# If you do not have one, it's coz you haven't run the java command like above yet to test it out!
nano server.properties
# I like to test out my features a couple of times, just to make sure it's primed . Here's an example of pushing it to 4gb at start.
java -Xmx8192m -Xms4096m -jar minecraft_server.jar nogui
# i suggest opening a 2nd ssh session, and run
# htop to see what's going on and confirm things are running as expected while you run the server manually.
# next section goes into what goes in the systemd startup config file:
sudo nano /etc/systemd/system/minecraft@.service
#copy/pasta this into that file, then save.
# Source: https://github.com/agowa338/MinecraftSystemdUnit/
# License: MIT
[Unit]
Description=Minecraft Server %i
After=network.target
[Service]
WorkingDirectory=/opt/minecraft/%i
PrivateUsers=true
# Users Database is not available for within the unit, only root and minecraft is available, everybody else is
nobody
User=minecraft
Group=minecraft
ProtectSystem=full
# Read only mapping of /usr /boot and /etc
ProtectHome=true
# /home, /root and /run/user seem to be empty from within the unit. It is recommended to enable this setting fo
r all long-running services (in particular network-facing ones).
ProtectKernelTunables=true
# /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats, /proc/acpi, /proc/timer_stats, /proc/fs and /proc/
irq will be read-only within the unit. It is recommended to turn this on for most services.
# Implies MountFlags=slave
ProtectKernelModules=true
# Block module system calls, also /usr/lib/modules. It is recommended to turn this on for most services that do
not need special file systems or extra kernel modules to work
# Implies NoNewPrivileges=yes
ProtectControlGroups=true
# It is hence recommended to turn this on for most services.
# Implies MountAPIVFS=yes
ExecStart=/bin/sh -c '/usr/bin/screen -DmS mc-%i /usr/bin/java -Xms4096M -Xmx8192M -XX:+UseG1GC -XX:ParallelGCThreads=2 -jar $(ls -v | grep -i "FTBServer.*jar\|minecraft_server.*jar" | head -n 1) nogui'
ExecReload=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "reload"\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"\\015'
ExecStop=/bin/sleep 10
Restart=on-failure
RestartSec=60s
[Install]
WantedBy=multi-user.target
#########
# HowTo
#########
#
# Create a directory in /opt/minecraft/XX where XX is a name like 'survival'
# Add minecraft_server.jar into dir with other conf files for minecraft server
#
# Enable/Start systemd service
# systemctl enable minecraft@survival
# systemctl start minecraft@survival
#
# To run multiple servers simply create a new dir structure and enable/start it
# systemctl enable minecraft@creative
# systemctl start minecraft@creative
# SAVE YOUR FILE
# then fire up your vanilla survival mode world as such:
sudo systemctl start minecraft@Survival
sudo systemctl enable minecraft@Survival
# if it doesn't start, you can figure out what's going on with:
journalctl -u minecraft@Survival
#once it's all running, reboot, and confirm the world comes up after a reboot.
#if all is good, congrats! go play!
# Now, if you want to let others play with it, go set up port forwarding for TCP & UDP on 25565 to the ip address of the minefcraft host.
# If you want to go set up a vanity domain name, I suggest a combination of dnsomatic, openDNS and dynu for your dynamic name hosting service needs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment