Objective
The following article will describe a Minecraft server configuration procedure on Ubuntu 18.04 Bionic Beaver LinuxOperating System and Software Versions
- Operating System: - Ubuntu 18.04
- Software: - Minecraft Server 1.12.2 or higher
Requirements
Privileged access to to your Ubuntu 18.04 system will be required.Conventions
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
sudo
command - $ - requires given linux commands to be executed as a regular non-privileged user
Other Versions of this Tutorial
Ubuntu 20.04 (Focal Fossa)Instructions
Install Prerequisites
Let's start by installation of all prerequisites including thenmap
command which we can later use for some basic troubleshooting purposes: $ sudo apt update $ sudo apt install wget screen default-jdk nmap
Create Minecraft user
Next, we need to create a new user namedminecraft
. The Minecraft server will eventually run under this user: $ sudo useradd -m -r -d /opt/minecraft minecraft
Install Minecraft Server
As you will see later, it is possible to run multiple instances of the Minecraft server on a single host. From this reason we will create a separate directory for each instance under the/opt/minecraft
directory. Let's call our first instance survival
: $ sudo mkdir /opt/minecraft/survivalOnce ready, download the java Minecraft server. Before you proceed, navigate your browser to the official Minecraft download page and update the below command to reflect the current Minecraft server version:
$ sudo wget -O /opt/minecraft/survival/minecraft_server.jar https://s3.amazonaws.com/Minecraft.Download/versions/1.12.2/minecraft_server.1.12.2.jarAccept terms and conditions:
$ sudo bash -c "echo eula=true > /opt/minecraft/survival/eula.txt"Lastly, change the ownership of the
/opt/minecraft/survival/
directory and of all files within: $ sudo chown -R minecraft /opt/minecraft/survival/
Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.
Create Minecraft SystemD startup script
To be able to conveniently start the Minecraft server after the reboot use your favorite text editor eg. vi:$ sudo vi /etc/systemd/system/minecraft@.serviceand create new
/etc/systemd/system/minecraft@.service
file with the following content:[Unit]
Description=Minecraft Server: %i
After=network.target
[Service]
WorkingDirectory=/opt/minecraft/%i
User=minecraft
Group=minecraft
Restart=always
ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 5 SECONDS. SAVING ALL MAPS..."\015'
ExecStop=/bin/sleep 5
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'
[Install]
WantedBy=multi-user.target
The above file serves as an example only. To increase RAM from 2GB to 4GB change: FROM: ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui TO: ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui
Start Minecraft Server
Next, use thesystemctl
command to start your new Minecraft server: $ sudo systemctl start minecraft@survivalConfirm that the new Minecraft server is up and running:
$ sudo systemctl status minecraft@survival ● This email address is being protected from spambots. You need JavaScript enabled to view it. - Minecraft Server: survival Loaded: loaded (/etc/systemd/system/minecraft@.service; disabled; vendor preset: enabled) Active: active (running) since Mon 2018-01-22 12:46:37 AEDT; 16s ago Main PID: 7751 (screen) Tasks: 21 (limit: 4915) CGroup: /system.slice/system-minecraft.slice/This email address is being protected from spambots. You need JavaScript enabled to view it. ├─7751 /usr/bin/SCREEN -DmS mc-survival /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui └─7757 /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui Jan 22 12:46:37 ubuntu systemd[1]: Started Minecraft Server: survival.To make sure that the minecraft server starts after the reboot execute:
$ sudo systemctl enable minecraft@survivalIf all went as planned you should be able now to use the
nmap
command to check for the default Minecraft port 25565
: $ nmap -p 25565 localhost Starting Nmap 7.60 ( https://nmap.org ) Nmap scan report for localhost (127.0.0.1) Host is up (0.00054s latency). Other addresses for localhost (not scanned): ::1 PORT STATE SERVICE 25565/tcp open minecraft Nmap done: 1 IP address (1 host up) scanned in 0.06 secondsAll done. To provision another Minecraft server instance on the same server continue reading the next section.
Provision new Minecraft server instance on the same host
The following linux commands will configure a new Minecraft server namedlinuxconfig
on port 25566
. See the below appendix for the additional server configurations to be implemented within/opt/minecraft/linuxconfig/server.properties
. Using our existing systemd script to deploy another instance of Minecraft server is easy as: $ sudo mkdir /opt/minecraft/linuxconfig $ sudo cp /opt/minecraft/survival/minecraft_server.jar /opt/minecraft/linuxconfig/ $ sudo bash -c "echo eula=true > /opt/minecraft/linuxconfig/eula.txt" $ sudo bash -c "echo server-port=25566 > /opt/minecraft/linuxconfig/server.properties" $ sudo chown -R minecraft /opt/minecraft/linuxconfig/Enable Minecraft server to start after reboot and start the server:
$ sudo systemctl enable minecraft@linuxconfig $ sudo systemctl start minecraft@linuxconfigLastly, check for status:
$ sudo systemctl status minecraft@linuxconfig
Appendix
Default minecraftserver.properties
settings: max-tick-time=60000 generator-settings= allow-nether=true force-gamemode=false gamemode=0 enable-query=false player-idle-timeout=0 difficulty=1 spawn-monsters=true op-permission-level=4 pvp=true snooper-enabled=true level-type=DEFAULT hardcore=false enable-command-block=false max-players=20 network-compression-threshold=256 resource-pack-sha1= max-world-size=29999984 server-port=25565 server-ip= spawn-npcs=true allow-flight=false level-name=world view-distance=10 resource-pack= spawn-animals=true white-list=false generate-structures=true online-mode=true max-build-height=256 level-seed= prevent-proxy-connections=false use-native-transport=true motd=A Minecraft Server enable-rcon=false