在Ubuntu上搭建并通过systemctl管理Minecraft基岩版服务器

在Ubuntu系统上运行并管理Minecraft基岩版服务器可以通过systemctl实现更高效的服务管理。本文将全面介绍如何从搭建服务器开始到使用systemctl进行管理的整个过程。

第一部分:搭建Minecraft基岩版服务器

1. 下载服务器软件

首先,访问 Minecraft官网 并下载Linux版本的基岩服务器软件。假设下载的文件为bedrock-server.zip

2. 安装和配置

在您的Ubuntu系统上,执行以下命令以解压服务器软件并进入服务器目录:

bash 复制代码
unzip bedrock-server.zip -d minecraft_server
cd minecraft_server
3. 安装运行依赖

安装运行Minecraft服务器所需的依赖:

bash 复制代码
sudo apt-get update
sudo apt-get install -y libcurl4 openssl libssl1.1
4. 修改配置文件

使用文本编辑器打开server.properties文件,根据需要配置服务器,例如设置服务器端口、最大玩家数等。

第二部分:配置Systemd服务

1. 创建服务单元文件

使用文本编辑器创建一个新的systemd服务单元文件:

bash 复制代码
sudo nano /etc/systemd/system/minecraft-server.service

在文件中粘贴以下内容,并根据您的实际情况调整相应的路径和用户信息:

ini 复制代码
[Unit]
Description=Minecraft Bedrock Server
After=network.target

[Service]
User=minecraft
Group=minecraft
WorkingDirectory=/home/minecraft/minecraft_server
ExecStart=/home/minecraft/minecraft_server/bedrock_server
ExecStop=/bin/kill -SIGINT $MAINPID
Restart=on-failure
RestartSec=20
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target
2. 重新加载Systemd配置

更新systemd以识别新的服务:

bash 复制代码
sudo systemctl daemon-reload
3. 启动服务

通过systemctl启动Minecraft服务器:

bash 复制代码
sudo systemctl start minecraft-server.service
4. 设置服务开机自启

使Minecraft服务器在系统启动时自动运行:

bash 复制代码
sudo systemctl enable minecraft-server.service
5. 监控服务状态

检查服务状态:

bash 复制代码
sudo systemctl status minecraft-server.service
6. 停止和重启服务

管理服务的停止和重启:

bash 复制代码
sudo systemctl stop minecraft-server.service
sudo systemctl restart minecraft-server.service

第三部分:创建和配置专用用户

为了安全性和管理方便,建议为Minecraft服务器创建一个专用用户:

bash 复制代码
sudo useradd -r -m -U -d /home/minecraft -s /bin/bash minecraft
sudo passwd minecraft

通过上述步骤,您不仅能搭建一个Minecraft基岩版服务器,还能通过systemctl实现对服务器的有效管理,确保服务器的高可用性和安全运行。

相关推荐
一叶龙洲20 小时前
win11与Ubuntu之间同步配置、插件
linux·运维·ubuntu
CHANG_THE_WORLD21 小时前
12.总结:深入理解 Linux I/O 多路复用:select、poll、epoll 全解析
linux·运维·服务器
风曦Kisaki21 小时前
# Linux笔记:操作系统优化与资源管理
linux·运维·服务器·笔记
初願致夕霞1 天前
C++懒汉单例设计详解
服务器·开发语言·c++
啊哦1111 天前
安装VMware Workstation
linux·运维·服务器
持敬chijing1 天前
Linux基础命令与目录命令
linux·运维·服务器
小张成长计划..1 天前
【Linux】12:进程状态
linux·运维·服务器
农村小镇哥1 天前
C#中的字符串格式化
服务器·开发语言·c#
小秋求学记.1 天前
Linux_Ubuntu的相关问题
linux·运维·ubuntu
在水一缸1 天前
当 AI 拥有了“核按钮”:深入解析 MCP 服务器与命令执行护栏
运维·服务器·人工智能·命令执行·智能体·ai安全·mcp