5.8 KiB
Setting up a scalable, secure, and modular Minecraft server system is no easy feat.
In this post we will look into how to deploy a Minecraft cluster using Docker, orchestrate the servers with PM2, and manage secure peer-to-peer connections with Holesail.
Whether you're a hobbyist or managing servers for a community, this system provides everything you need to run a robust setup.
Cluster Source Code:
https://git.ssh.surf/snxraven/mc-cluster
Why Build a Minecraft Cluster:
Running a single Minecraft server can be sufficient for small groups, but as player numbers grow, or if you want to offer different experiences (e.g., creative, survival, or modded servers), a clustered setup becomes invaluable. The key benefits include:
- Scalability: Add or remove servers based on demand.
- Flexibility: Host different game modes or mods on separate servers.
- Performance: Distribute player loads across multiple servers.
- Security: Use Holesail for end-to-end encrypted peer-to-peer communication.
Overview of the System
This system consists of three major components:
- Minecraft Server Cluster: A group of Minecraft servers running FabricMC for mod support, deployed with Docker Compose and orchestrated using PM2.
- Velocity Proxy: A lightweight proxy that routes player connections to the appropriate Minecraft server.
- Holesail Networking: Secure peer-to-peer networking for managing connections between servers and the proxy.
Here’s a simplified architecture:
Players → Velocity Proxy (JUMP Node) → Minecraft Cluster (MC Host Node)
Component Breakdown
1. Minecraft Cluster
The cluster is built using Docker Compose, allowing multiple Minecraft servers to run in isolated containers. Each server has:
- FabricMC: For modding support.
- PM2: Process manager to ensure stability and logs.
- Holesail Integration: Secure connections using predefined connection strings.
How It Works:
- The
docker-compose.yml
defines the services (servers) in the cluster. - Each server is configured with its own Holesail connection string and port.
- PM2 ensures the servers restart automatically if they crash.
2. Velocity Proxy
Velocity is a Minecraft proxy designed for performance and flexibility. It routes player traffic to the appropriate backend Minecraft servers.
Features:
- Customizable MOTD: Tailor the server’s welcome message.
- Player Forwarding: Seamlessly switch players between servers.
- Holesail Integration: Secure backend connections.
How It Works:
- The
velocity.toml
configuration file specifies backend servers and ports. - Players connect to the Velocity proxy, which uses Holesail to route traffic to the appropriate server in the cluster.
3. Holesail Networking
Holesail provides secure peer-to-peer networking using connection strings. This ensures encrypted communication between the Velocity proxy and Minecraft servers.
Key Points:
- Each server is assigned a unique connection string and port.
- The
pm2-setup.sh
script initializes Holesail connections. - Holesail manages end-to-end encryption, ensuring secure traffic.
Step-by-Step Deployment Guide
Step 1: Set Up the Minecraft Host Node
This node hosts the Minecraft server cluster.
-
Clone the Repository:
git clone https://git.ssh.surf/snxraven/mc-cluster.git cd mc-cluster/mc-cluster-image
-
Build the Minecraft Cluster Image:
docker build . -t mc:cluster
-
Navigate Back to the Main Directory:
cd ..
-
Start the Cluster:
docker-compose up -d
This command deploys a cluster of Minecraft servers, each with its own connection string and port defined in pm2-setup.sh
.
Step 2: Set Up the JUMP Node
The JUMP node hosts the Velocity proxy, managing player connections and routing traffic to the Minecraft cluster. The docker compose also starts up the holesail connections to bind the remote Minecraft servers to the local JUMP Server. All connections within velocity are configured within localhost.
-
Clone the Repository:
git clone https://git.ssh.surf/snxraven/mc-cluster.git cd mc-cluster/velocity-image
-
Build the Velocity Proxy Image:
docker build . -t velocity:proxy
-
Start the Proxy:
docker-compose up -d
Customization and Advanced Configuration
Minecraft Cluster Customization
-
Add/Remove Servers: Edit the
docker-compose.yml
file and modify theservices
section.Example:
services: mc-server-1: image: mc:cluster environment: CONNECTION_STRING: "mc-server-1" PORT: "5000" mc-server-2: image: mc:cluster environment: CONNECTION_STRING: "mc-server-2" PORT: "5001"
Velocity Proxy Customization
-
MOTD and Server List: Modify
velocity.toml
to change the MOTD and backend server settings.Example:
motd = "&aWelcome to our Minecraft Cluster!" [servers] lobby = "mc-server-1" survival = "mc-server-2"
-
Secure Player Forwarding: Update the
forwarding.secret
file for secure player forwarding.
Troubleshooting
Common Issues
-
Holesail Connection Error:
- Ensure the
CONNECTION_STRING
andPORT
values are correctly set.
- Ensure the
-
Velocity Not Forwarding Players:
- Ensure the
velocity.toml
file has the correct backend server configurations.
- Ensure the
Future Enhancements
- Auto-Scaling: Add or remove Minecraft servers dynamically based on player load.
- Integrated Monitoring: Use tools like Netdata to monitor server performance and health.
- Web Dashboard: Develop a web interface for managing the cluster, viewing logs, and deploying updates.