在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实现对服务器的有效管理,确保服务器的高可用性和安全运行。

相关推荐
星海穿梭者2 分钟前
SQL SERVER 查看锁表
java·服务器·前端
Voyager_45 分钟前
Linux服务器NAS挂载:Truenas
linux·运维·服务器
liujing1023292938 分钟前
Day01_Linux移植基础
linux·运维·服务器
清静诗意1 小时前
在 Ubuntu 上通过 Docker 与 Docker Compose 部署项目的完整指南
linux·ubuntu·docker
boss-dog1 小时前
Ubuntu22.04——配置固定IP
ubuntu·ip
专注VB编程开发20年2 小时前
vb.net编写DDE(Dynamic Data Exchange)服务器
运维·服务器·github·vb.net·dde
Clownseven2 小时前
如何用Fail2ban保护Linux服务器?防止SSH暴力破解教程
linux·服务器·ssh
无敌最俊朗@3 小时前
Linux 进程创建与控制详解
linux·运维·服务器
迎風吹頭髮3 小时前
UNIX下C语言编程与实践8-UNIX 静态库原理与创建:ar 命令的使用与静态库调用全流程
服务器·c语言·unix
jieyu11193 小时前
入侵检测系统(IDS)和入侵防御系统(IPS)
运维·服务器·系统安全