> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/di-38-zhang-you-xi-ke-xue-ji-suan-he-zhuan-ye-gong-ju/di-38.2-jie-wo-de-shi-jie-minecraft-fu-wu-qi.md).

# 38.2 我的世界（Minecraft）服务器

Minecraft 是一款由 Java 语言开发的沙盒游戏，本节介绍在 FreeBSD 上 Minecraft 服务器端的部署。搭建服务器需先安装 Java 运行环境，服务器端与客户端对 Java 版本的要求通常保持一致。

## 相关文件结构

```sh
/
├── etc/
│   └── rc.conf # 系统配置文件，包含 minecraft 服务配置
├── usr/
│   └── local/
│       ├── bin/
│       │   └── minecraft-server # Minecraft 服务器可执行文件
│       └── etc/
│           └── minecraft-server/ # Minecraft 服务器配置目录
│               ├── eula.txt # 用户协议文件
│               ├── java-args.txt # Java 参数配置
│               └── server.properties # 服务器配置文件
├── var/
│   ├── log/
│   │   └── minecraft-server/ # 日志和调试输出目录
│   └── db/
│       └── minecraft-server/ # 世界文件目录
```

## 安装 OpenJDK

需注意，过旧的 JDK 版本不受服务器端支持，本节测试使用 JDK 21 可正常运行。

使用 pkg 安装 OpenJDK 21：

```sh
# pkg install openjdk21
```

或者使用 Ports 编译安装 OpenJDK 21，可针对服务器硬件优化：

```sh
# cd /usr/ports/java/openjdk21/
# make install clean
```

## 使用 Ports 或官方服务器程序

搭建 Minecraft 服务器有两种方式：

经过测试，[Minecraft 官方服务器端](https://www.minecraft.net/en-us/download/server)是纯 Java 程序，在 FreeBSD 15.0 上安装 OpenJDK 后即可直接运行。Ports 版本则提供了 FreeBSD 特定的集成配置，包括服务管理脚本和默认配置文件。

也可使用 Ports 中提供的 **games/minecraft-server**：

```sh
# cd /usr/ports/games/minecraft-server/
# make install clean
```

查看配置信息：

```sh
# pkg info -D minecraft-server
```

运行服务器：

```sh
$ /usr/local/bin/minecraft-server

…………省略一部分…………

[15:52:21] [ServerMain/WARN]: Failed to load eula.txt
[15:52:21] [ServerMain/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
```

提示需同意许可协议，将 **/usr/local/etc/minecraft-server/eula.txt** 文件中的 `eula=false` 修改为 `eula=true`。

再次运行已安装的 Minecraft 服务器程序：

```sh
# /usr/local/bin/minecraft-server
Starting net.minecraft.server.Main
[15:54:47] [ServerMain/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD]
[15:54:48] [ServerMain/INFO]: No existing world data, creating new world
[15:54:49] [ServerMain/INFO]: Loaded 1290 recipes
[15:54:49] [ServerMain/INFO]: Loaded 1399 advancements
[15:54:49] [Server thread/INFO]: Starting minecraft server version 1.21.1
[15:54:49] [Server thread/INFO]: Loading properties
[15:54:49] [Server thread/INFO]: Default game type: SURVIVAL
[15:54:49] [Server thread/INFO]: Generating keypair
[15:54:49] [Server thread/INFO]: Starting Minecraft server on *:25565
[15:54:50] [Server thread/INFO]: Using default channel type
[15:54:50] [Server thread/INFO]: Preparing level "world"
[15:54:53] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld
[15:54:53] [Worker-Main-2/INFO]: Preparing spawn area: 2%
[15:54:54] [Worker-Main-2/INFO]: Preparing spawn area: 2%
[15:54:54] [Worker-Main-3/INFO]: Preparing spawn area: 2%
[15:54:55] [Worker-Main-1/INFO]: Preparing spawn area: 2%
[15:54:55] [Worker-Main-2/INFO]: Preparing spawn area: 18%
[15:54:56] [Worker-Main-1/INFO]: Preparing spawn area: 51%
[15:54:56] [Worker-Main-3/INFO]: Preparing spawn area: 51%
[15:54:56] [Server thread/INFO]: Time elapsed: 3317 ms
[15:54:56] [Server thread/INFO]: Done (6.876s)! For help, type "help"
```

按 **Ctrl** + **C** 中断程序运行。

## 关闭正版验证

在当前默认配置下，服务器启用了正版验证机制（`online-mode=true`）。该机制通过与 Mojang 会话服务器和 Microsoft 身份验证服务通信来验证玩家身份，确保：

* 每个玩家拥有 Mojang/Microsoft 分配的唯一 UUID，与购买的账号绑定
* 玩家无法使用他人用户名登录
* 封禁和权限管理基于真实的账号身份

> **警告**
>
> 应仅在完全理解风险且已部署额外保护措施的情况下使用 `online-mode=false` 。

如需在局域网或测试环境中允许未购买游戏的玩家连接，可编辑 **/usr/local/etc/minecraft-server/server.properties** 文件，将 `online-mode=true` 修改为 `online-mode=false`。

随后再次运行已安装的 Minecraft 服务器程序：

```sh
# /usr/local/bin/minecraft-server
Starting net.minecraft.server.Main
[18:47:47] [ServerMain/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD]
[18:47:51] [ServerMain/INFO]: Loaded 1337 recipes
[18:47:51] [ServerMain/INFO]: Loaded 1448 advancements
[18:47:51] [Server thread/INFO]: Starting minecraft server version 1.21.3
[18:47:51] [Server thread/INFO]: Loading properties
[18:47:51] [Server thread/INFO]: Default game type: SURVIVAL
[18:47:51] [Server thread/INFO]: Generating keypair
[18:47:51] [Server thread/INFO]: Starting Minecraft server on *:25565
[18:47:51] [Server thread/INFO]: Using default channel type
[18:47:52] [Server thread/WARN]: **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!
[18:47:52] [Server thread/WARN]: The server will make no attempt to authenticate usernames. Beware.
[18:47:52] [Server thread/WARN]: While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.
[18:47:52] [Server thread/WARN]: To change this, set "online-mode" to "true" in the server.properties file.
[18:47:52] [Server thread/INFO]: Preparing level "world"
[18:47:52] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld
[18:47:53] [Worker-Main-5/INFO]: Preparing spawn area: 0%
[18:47:53] [Worker-Main-5/INFO]: Preparing spawn area: 0%
[18:47:53] [Worker-Main-5/INFO]: Preparing spawn area: 0%
[18:47:53] [Server thread/INFO]: Time elapsed: 1233 ms
[18:47:53] [Server thread/INFO]: Done (1.709s)! For help, type "help"
[18:48:34] [Server thread/INFO]: ykla[/127.0.0.1:37462] logged in with entity id 39 at (-1.5, 63.0, 1.5)
[18:48:34] [Server thread/INFO]: ykla joined the game
```

![FreeBSD 运行 Minecraft](/files/6UfmOjY7OT9prJMTqxmP)

## 关闭正版验证的安全风险

完全禁用 Mojang/Microsoft 账号验证，将带来以下严重安全风险：

1. **管理员账号伪造**：任何人可输入管理员（OP）的用户名直接登录，获得服务器的全部管理权限、物品和领地。由于 UUID 基于用户名本地生成（`OfflinePlayer:用户名`），服务器无法区分真实管理员与冒充者。
2. **封禁完全失效**：被封禁的用户只需更换一个用户名即可重新加入，无需购买新账号，封禁机制形同虚设。
3. **白名单形同虚设**：离线模式下白名单仅检查用户名而非账号身份，无法阻止冒充。
4. **机器人攻击门槛极低**：攻击者无需购买任何 Minecraft 账号即可批量生成随机用户名进行自动化攻击。
5. **玩家数据丢失风险**：离线模式下 UUID 绑定用户名而非账号。玩家更换用户名后，其所有物品、建筑、权限等数据将永久丢失。
6. **违反 Minecraft EULA 的风险**：允许未购买游戏的玩家连接可能违反 Mojang 最终用户许可协议。
7. **皮肤和正版特性不可用**：离线模式下所有玩家外观显示为默认 Steve/Alex 皮肤。

如确实需要使用离线模式（例如局域网封闭环境、使用 BungeeCord/Velocity 代理转发），建议采取以下缓解措施：

* 安装身份验证插件（如 AuthMeReloaded）要求玩家注册密码，防止伪造用户名
* 配合防火墙限制，仅允许可信 IP 段连接
* 使用 CoreProtect 等插件记录所有方块操作，便于回溯与回滚
* 使用 LuckPerms 等权限插件精细控制权限，避免使用通配符 `*`
* 定期备份世界数据


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/di-38-zhang-you-xi-ke-xue-ji-suan-he-zhuan-ye-gong-ju/di-38.2-jie-wo-de-shi-jie-minecraft-fu-wu-qi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
