Minecraft Spigot Server Hosted via Proxmox
10 mins read

Minecraft Spigot Server Hosted via Proxmox

How to host a Minecraft Server inside a Proxmox LXC Container

Table of Contents

    Creating an LXC Container

    This assumes you have an existing Proxmox install, if you don’t we currently don’t have a guide however there are plenty out there.

    Your first step on the Proxmox home screen is to open your Proxmox node and click “local(proxmox)”.
    Then click CT Templates and search for your desired image, this guide assumes you will be using Debian 11
    Select Debian 11 and click “download”
    Next, in the top right click “Create CT”
    Set the CT ID to whatever you want, or leave it as default, set a hostname (mine is minecraft) and set a password on the right hand side
    Click Next and select the template you just downloaded, in this case Debian 11
    Next again and select your storage and assign the disk size, I’m assigning 15GB
    Next you will select how many CPU Cores you want to assign to the container, I would recommend 4
    Your first step on the Proxmox home screen is to open your Proxmox node and click “local(proxmox)”.
    Then click CT Templates and search for your desired image, this guide assumes you will be using Debian 11
    Select Debian 11 and click “download”
    Next, in the top right click “Create CT”
    Set the CT ID to whatever you want, or leave it as default, set a hostname (mine is minecraft) and set a password on the right hand side
    Click Next and select the template you just downloaded, in this case Debian 11
    Next again and select your storage and assign the disk size, I’m assigning 15GB
    Next you will select how many CPU Cores you want to assign to the container, I would recommend 4
    In the next screen choose how much RAM you would like to allocate, recommended is at least 2GB but if you are going to have any more than a few players at least 4GB
    In “Network” set IPv4 to DHCP and leave everything else as default unless you have reason to change it
    Everything else can be left as is, continue to the end and select “Finish”

    You will now see your container created on the left hand side, open it’s console and sign in with “root” and the password you entered earlier. Immediately you want to run hostname -I and note down the result, this is your containers IP address on your network.


    Installing Java

    For the latest versions of Minecraft server you require Java JDK 21. Which as of the time of writing is not available via apt-get so you will have to get the package yourself with
    wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb
    then
    sudo dpkg -i jdk-21_linux-64_bin.deb (or replace after -i with the name of the file that downloaded)
    You now have Java 21 installed inside your container


    Getting SpigotMC (BuildTools)

    Go to the Spigot page at: https://www.spigotmc.org/ and select “Downloads” > “Spigot/BuildTools”
    In the page that opens right click “BuildTools.jar” and copy link
    Now go back to your container terminal and go to the root directory with cd .. and make a folder named “minecraftserver” mkdir minecraftserver and cd into it. Download BuildTools with the copied link
    wget https://hub.spigotmc.org/jenkins/job/BuildTools/


    Installing SpigotMC

    You now have BuildTools in your “minecraftserver” folder. The next step is to run this to create your Spigot server instance with the desired game version.
    Run:
    java -jar BuildTools.jar --rev 1.20.6
    Replacing 1.20.6 with your desired game version. This will take a few minutes to run so now is the time to go grab some coffee or if you like skip down to the Port Forwarding and Domain section to get that out of the way.

    Once BuildTools has finished running the first thing you want to do is run the server to generate all the files
    java -Xmx1024M -Xms1024M -jar spigot-1.20.6.jar
    Replacing spigot-1.20.6.jar with the jar file BuildTools created, it should have the same name just with 1.20.6 replaced with the game version specified earlier
    The server should generate all the configuration files, type stop into the terminal. You will now need to set the EULA to true.
    nano eula.txt and replace false with true. CTRL + X and Y to save and exit.
    Run the command to start the server again
    java -Xmx1024M -Xms1024M -jar spigot-1.20.6.jar
    Wait a minute or two as it generates the world and try to join from your own Minecraft game to verify it is working correctly, connecting via the IP obtained earlier

    You have now successfully created a working Minecraft server inside an LXC container! You are now free to mess around with the server.properties file and install plugins etc (which this guide does not cover). Continue to the next step to ensure it runs whenever the container is started.


    Make the Server Start with Your Container

    In its current state, every time you start the container you will need to manually go into the /minecraftserver folder and run the earlier Java command to start the server. To rectify this we are going to add a systemd service to run the server start command whenever the container boots.

    In the container terminal
    cd /etc/systemd/system
    nano startmcserver.service
    In this file you want to enter the command to start your server as well as any launch options to the Java command

    [Unit]
    Description=Minecraft Server
    
    [Service]
    type=simple
    WorkingDirectory=/minecraftserver #If your directory is different change it here
    ExecStart=/bin/bash -c 'java -Xmx1024M -Xms1024M -jar spigot-1.20.6.jar' #Change spigot-1.20.6.jar with the name of your jarfile and edit -Xmx and -Xms to allocate more RAM to the server if needed
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    Bash

    Ensure to change the amount of RAM for your server if you require more than 1GB allocated by editing -Xmx1024M -Xms1024M to your desired amount, noting that these are in MB so 4GB would be 4096M. CTRL + X and Y to save and exit.

    Now run systemctl start startmcserver.service and try to join the server after a minute or two, to verify if it works.

    Assuming it works you can now enable the service by running systemctl enable startmcserver.service

    Now your server will start whenever you start up your container. However this server will only work on your own network, if you want people to be able to join externally you will have to Port Forward the server.


    Port Forwarding

    This section will be somewhat vague as different modems/routers have different interfaces and lingo for port forwarding, if you are stuck I recommend looking up how to port forward Minecraft for your specific router/modem as there are hundreds of guides out there.

    Go to the port forwarding section on your routers admin page and add a new rule. Give it a name and set the port to 25565 – Minecraft’s default port. (Note: some modems however are finicky and require a port range that can be various different formats, for example my old Vodafone modem required me to enter 25564:25566 as it would not work with just 25565, other modems may require it to be formatted like 25565-25566) And protocol or forwarding type to TCP. The forward or destination IP will be the IP of your container you obtained earlier and if you require a forward or destination port it will be the same port as above 25565.

    Now you could stop here and your friends could join via your external IP, which you can easily obtain by going to ifconfig.me. However if you want your server to be joinable with a domain such as mc.example.com, continue to the next step.


    Cloudflare Domain Setup

    Important Note: this section assumes you already have a Cloudflare account with a domain registered, as well as Dynamic DNS so if your public IP changes that is reflected in Cloudflare. This guide uses example.com as an example, of course, replace that with your own domain whenever referenced in this guide.

    Open your Cloudflare DNS Records for your domain and add an A record, it doesn’t matter if you already have other A records for this domain.
    Assuming you want your server to be on mc.example.com set the name to mc and the IPv4 address to your public IP, which you can obtain via ifconfig.me. It shouldn’t matter if proxy status is enabled or disabled, however if you are having issues later on, test disabling it. Now save.

    Next add an SRV record. Set its name to _minecraft._tcp.mc replacing .mc with whatever you want your subdomain to join to be, so if you wanted it to be minecraft.example.com you would set it to _minecraft._tcp.minecraft
    Priority and Weight don’t matter so set them to 0
    Set the port to 25565 and target to the domain you would like people to join, in this case mc.example.com and save.

    Important Note: To check if it is working use a service such as mcstatus.io or get one of your friends to try and join. It may take longer to be able to join from your own network and I had issues.
    Any DNS changes may take up to an hour to propagate, so if it is not working immediately don’t worry, go get a coffee, relax and retry in a few minutes.

    Success! You should now have a working Minecraft server accessible via a domain.


    Updating

    Re run java -jar BuildTools.jar --rev 1.21 replacing 1.21 with your desired game version
    You will next have to re edit your systemd service with nano /etc/systemd/system/startmcserver.service and update the line ExecStart=/bin/bash -c 'java -Xmx1024M -Xms1024M -jar spigot-1.20.6.jar' to change spigot-1.20.6.jar with whatever the freshly downloaded jar file is named, in the case of this update it will be spigot-1.21.jar