如何在 VPS 或专用服务器上创建 Minecraft 服务器
本指南介绍如何在您的 VPS 或专用 Linux 服务器上安装和配置 Minecraft Java 版服务器。
订购服务器
要托管您的 Minecraft 服务器,HostMyServers 提供多种游戏优化选择:
- Performance VPS - 适合游戏服务器
- NVMe VPS - 极佳性价比
- 经济型专用服务器 - 适合多玩家服务器
- 性能专用服务器 - 大型服务器的最佳性能
前提条件
- 以 root 或具有 sudo 权限的用户进行 SSH 访问
- 已更新的 Debian/Ubuntu 系统
- 最少 2 GB 内存(10+ 玩家建议 4 GB)
- 端口 25565 可访问(TCP)
- 稳定的网络连接
配置要求
| 玩家数量 | 最低内存 | 推荐内存 |
|---|---|---|
| 1-5 | 1 GB | 2 GB |
| 5-10 | 2 GB | 4 GB |
| 10-20 | 4 GB | 6 GB |
| 20+ | 6 GB | 8 GB+ |
系统更新
sudo apt update && sudo apt upgrade -y
安装 Java
Minecraft 1.17+ 至少需要 Java 17。对于最新版本(1.20+),推荐使用 Java 21。
安装 Java 21(推荐)
sudo apt install -y openjdk-21-jdk
验证安装
java --version
您应该看到类似以下的输出:
openjdk 21.0.x 2024-xx-xx
OpenJDK Runtime Environment (build 21.0.x+xx-xx)
OpenJDK 64-Bit Server VM (build 21.0.x+xx-xx, mixed mode, sharing)
创建专用用户
出于安全考虑,永远不要以 root 身份运行服务器。创建专用用户:
sudo adduser --system --home /opt/minecraft --shell /bin/bash minecraft
安装必要工具
sudo apt install -y screen wget curl unzip
- screen:在 SSH 断开后保持服务器运行
- wget/curl:用于下载文件
- unzip:用于解压文件
下载 Minecraft 服务器
以 minecraft 用户身份连接
sudo -u minecraft bash
cd /opt/minecraft
mkdir server
cd server
下载官方服务器
从 minecraft.net/download/server 获取最新版本的链接,然后:
wget -O server.jar https://piston-data.mojang.com/v1/objects/XXXXXXX/server.jar
注意
请将 URL 替换为所需版本的官方链接。
接受 EULA
您必须接受 Minecraft 许可协议:
echo "eula=true" > eula.txt
首次启动
首次启动服务器以生成配置文件:
java -Xms1G -Xmx2G -jar server.jar nogui
内存参数:
-Xms1G:初始内存(1 GB)-Xmx2G:最大内存(2 GB)nogui:禁用图形界面
首次启动后使用 stop 或 Ctrl+C 停止服务器。
服务器配置
根据您的需求编辑 server.properties 文件:
nano server.properties
重要设置
# 服务器端口(默认:25565)
server-port=25565
# 最大玩家数量
max-players=20
# 游戏模式(survival, creative, adventure, spectator)
gamemode=survival
# 难度(peaceful, easy, normal, hard)
difficulty=normal
# 服务器列表中显示的消息
motd=我的 Minecraft 服务器
# 渲染距离(如有卡顿请降低)
view-distance=10
# 启用白名单
white-list=false
# 在线模式(Mojang 账户验证)
online-mode=true
# 启用 PvP
pvp=true
# 出生点保护(方块半径)
spawn-protection=16
防火墙配置
在防火墙中开放 Minecraft 端口:
使用 UFW
sudo ufw allow 25565/tcp
sudo ufw reload
使用 iptables
sudo iptables -A INPUT -p tcp --dport 25565 -j ACCEPT
sudo iptables-save | sudo tee /etc/iptables/rules.v4
使用 screen 运行
在 SSH 断开后保持服务器运行:
在 screen 中启动服务器
screen -S minecraft
cd /opt/minecraft/server
java -Xms1G -Xmx2G -jar server.jar nogui
分离会话
按 Ctrl+A 然后 D 分离会话。
返回会话
screen -r minecraft