minecraft1.12_如何在Ubuntu 18.04上创建Minecraft服务器

minecraft1.12

The author selected the Tech Education Fund to receive a donation as part of the Write for DOnations program.

作者选择了Tech Education Fund作为“ Write for DOnations”计划的一部分来接受捐赠。

介绍 (Introduction)

Minecraft is a popular sandbox video game. Originally released in 2009, it allows players to build, explore, craft, and survive in a block 3D generated world. As of late 2019, it was the second best-selling video game of all time. In this tutorial, you will create your own Minecraft server so that you and your friends can play together. Specifically, you will install the necessary software packages to run Minecraft, configure the server to run, and then deploy the game.

Minecraft是一款流行的沙盒视频游戏。 它最初于2009年发布,允许玩家在3D生成的方块世界中进行构建,探索,制作和生存。 截至2019年末,它是有史以来第二畅销的视频游戏。 在本教程中,您将创建自己的Minecraft服务器,以便您和您的朋友可以一起玩。 具体来说,您将安装必要的软件包以运行Minecraft,配置服务器以运行,然后部署游戏。

Alternately, you can explore DigitalOcean’s One-Click Minecraft: Java Edition Server as another installation path.

或者,您可以探索DigitalOcean的一键式Minecraft:Java Edition Server作为另一种安装路径。

This tutorial uses the Java version of Minecraft. If you purchased your version of Minecraft through the Microsoft App Store, you will be unable to connect to this server. Most versions of Minecraft purchased on gaming consoles such as the PlayStation 4, Xbox One, or Nintendo Switch are also the Microsoft version of Minecraft. These consoles are also unable to connect to the server built in this tutorial. You can obtain the Java version of Minecraft here.

本教程使用Java版本的Minecraft 。 如果您通过Microsoft App Store购买了Minecraft版本,则将无法连接到该服务器。 在PlayStation 4,Xbox One或Nintendo Switch等游戏机上购买的Minecraft的大多数版本也是Minecraft的Microsoft版本。 这些控制台也无法连接到本教程中构建的服务器。 您可以在此处获得Java版本的Minecraft。

先决条件 (Prerequisites)

In order to follow this guide, you’ll need:

为了遵循本指南,您需要:

  • A server with a fresh installation of Ubuntu 18.04, a non-root user with sudo privileges, and SSH enabled. You can follow this guide to initialize your server and complete these steps. Minecraft can be resource-intensive, so keep that in mind when selecting your server size. If you are using DigitalOcean and need more resources, you can always resize your Droplet to add more CPUs and RAM.

    全新安装Ubuntu 18.04的服务器,具有sudo特权的非root用户,并且已启用SSH。 您可以按照本指南初始化服务器并完成这些步骤 。 Minecraft可能会占用大量资源,因此在选择服务器大小时请记住这一点。 如果您正在使用DigitalOcean并且需要更多资源,则可以随时调整Droplet的大小以添加更多的CPU和RAM。

  • A copy of Minecraft Java Edition installed on a local Mac, Windows, or Linux machine.

    安装在本地Mac,Windows或Linux计算机上的Minecraft Java Edition的副本。

步骤1 —安装必要的软件包并配置防火墙 (Step 1 — Installing the Necessary Software Packages and Configure the Firewall)

With your server initialized, your first step is to install Java; you’ll need it to run Minecraft.

初始化服务器后,第一步是安装Java 。 您将需要它来运行Minecraft。

Update the package index for the APT package manager:

更新APT软件包管理器的软件包索引:

  • sudo apt update

    sudo apt更新

Next, install the OpenJDK version 8 of Java, specifically the headless JRE. This is a minimal version of Java that removes the support for GUI applications. This makes it ideal for running Java applications on a server:

接下来,安装JavaOpenJDK版本8,特别是无头JRE 。 这是Java的最低版本,它删除了对GUI应用程序的支持。 这使其非常适合在服务器上运行Java应用程序:

  • sudo apt install openjdk-8-jre-headless

    sudo apt安装openjdk-8-jre-headless

You also need to use a software called screen to create detachable server sessions. screen allows you to create a terminal session and detach from it, leaving the process started on it running. This is important because if you were to start your server and then close your terminal, this would kill the session and stop your server. Install screen now:

您还需要使用一个名为screen的软件来创建可分离的服务器会话。 screen允许您创建一个终端会话并与之分离,从而使启动过程继续进行。 这很重要,因为如果要启动服务器然后关闭终端,这将终止会话并停止服务器。 立即安装screen

  • sudo apt install screen

    sudo apt安装屏幕

Now that you have the packages installed we need to enable the firewall to allow traffic to come in to our Minecraft server. In the initial server setup that you performed you only allowed traffic from SSH. Now you need to allow for traffic to come in via port 25565, which is the default port that Minecraft uses to allow connections. Add the necessary firewall rule by running the following command:

现在您已经安装了软件包,我们需要启用防火墙以允许流量进入我们的Minecraft服务器。 在执行的初始服务器设置中 ,您仅允许来自SSH的流量。 现在,您需要允许流量通过端口25565 ,这是Minecraft用来允许连接的默认端口。 通过运行以下命令来添加必要的防火墙规则:

  • sudo ufw allow 25565

    sudo ufw允许25565

Now that you have Java installed and your firewall properly configured, you will download the Minecraft server from the Minecraft website.

现在,您已经安装了Java并正确配置了防火墙,您将从Minecraft网站下载Minecraft服务器。

第2步-下载最新版本的Minecraft (Step 2 — Downloading the Latest Version of Minecraft)

Now you need to download the current version of the Minecraft server. You can do this by navigating to Minecraft’s Website and copying the link that says Download minecraft_server.X.X.X.jar, where the X’s are the latest version of the server.

现在,您需要下载Minecraft服务器的当前版本。 您可以通过导航到Minecraft的网站并复制显示下载minecraft_server的链接来实现 XXX .jar ,其中X是服务器的最新版本。

You can now use wget and the copied link to download the server:

现在,您可以使用wget和复制的链接来下载服务器:

  • wget https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar

    wget https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar

If you intend to upgrade your Minecraft server, or if you want to run different versions of Minecraft, rename the downloaded server.jar to minecraft_server_1.15.2.jar, matching the highlighted version numbers to whatever version you just downloaded:

如果要升级您的Minecraft服务器,或者要运行其他版本的Minecraft,请将下载的server.jar重命名为minecraft_server_ 1.15.2 .jar ,将突出显示的版本号与您刚下载的任何版本匹配:

  • mv server.jar minecraft_server_1.15.2.jar

    mv server.jar minecraft_server_ 1.15.2 .jar

If you want to download an older version of Minecraft, you can find them archived at mcversions.net. But this tutorial will focus on the current latest release. Now that you have your download let’s start configuring your Minecraft server.

如果要下载旧版本的Minecraft,可以在mcversions.net找到存档。 但是本教程将重点介绍当前的最新版本。 现在您已经下载了,让我们开始配置Minecraft服务器。

第3步-配置和运行Minecraft服务器 (Step 3 — Configuring and Running the Minecraft Server)

Now that you have the Minecraft jar downloaded, you are ready to run it.

现在您已经下载了Minecraft jar,可以开始运行了。

First, start a screen session by running the screen command:

首先,通过运行screen命令启动屏幕会话:

  • screen

    屏幕

Once you have read the banner that has appeared, press the SPACE bar. screen will present you with a terminal session like normal. This session is now detachable, which means that you’ll be able to start a command here and leave it running.

阅读出现的标语后,请按SPACE键。 screen会像平常一样向您显示一个终端会话。 现在,该会话是可分离的,这意味着您可以在此处启动命令并使它保持运行状态。

You can now perform your initial configuration. Do not be alarmed when this next command throws an error. Minecraft has designed its installation this way so that users must first consent to the company’s licensing agreement. You will do this next:

现在,您可以执行初始配置。 当下一个命令引发错误时,请勿惊慌。 Minecraft以这种方式设计了安装方式,因此用户必须首先同意公司的许可协议。 接下来,您将执行以下操作:

  • java -Xms1024M -Xmx1024M -jar minecraft_server_1.15.2.jar nogui

    Java- Xms1024M - Xmx1024M - jar minecraft_server_1.15.2.jar nogui

Before examining this command’s output, let’s take a closer look at all these command-line arguments, which are tuning your server:

在检查此命令的输出之前,让我们仔细看一下所有这些正在调整服务器的命令行参数:

  • Xms1024M - This configures the server to start running with 1024MB or 1GB of RAM running. You can raise this limit if you want your server to start with more RAM. Both M for megabytes and G for gigabytes are supported options. For example: Xms2G will start the server with 2 gigabytes of RAM.

    Xms1024M这将服务器配置为以1024MB或1GB RAM运行。 如果希望服务器以更多的RAM启动,则可以提高此限制。 支持M(兆字节)和G(千兆字节)选项。 例如: Xms2G将使用2 GB的RAM启动服务器。

  • Xmx1024M - This configures the server to use, at most, 1024M of RAM. You can raise this limit if you want your server to run at a larger size, allow for more players, or if you feel that your server is running slowly.

    Xmx1024M这将服务器配置为最多使用1024M的RAM。 如果您希望服务器以更大的尺寸运行,允许更多玩家使用,或者感觉服务器运行缓慢,则可以提高此限制。

  • jar - This flag specifies which server jar file to run.

    jar此标志指定要运行的服务器jar文件。

  • nogui - This tells the server not to launch a GUI since this is a server, and you don’t have a graphical user interface.

    nogui告诉服务器不要启动GUI,因为这是服务器,并且您没有图形用户界面。

The first time you run this command, which normally starts your server, it will instead generate the following error:

第一次运行此命令(通常会启动服务器)时,它将生成以下错误:


   
   
Output
[22:05:31] [22:05:31] [main/ERROR]: Failed to load properties from file: server.properties [22:05:31] [main/WARN]: Failed to load eula.txt [22:05:31] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.

These errors were generated because the server could not find two necessary files required for execution: the EULA (End User License Agreement), found in eula.txt, and the configuration file server.properties. Fortunately, since the server was unable to find these files, it created them in your current working directory.

之所以产生这些错误,是因为服务器找不到执行所需的两个必需文件: eula.txt的EULA(最终用户许可协议)和配置文件server.properties 。 幸运的是,由于服务器找不到这些文件,因此它在您当前的工作目录中创建了它们。

First, open eula.txt in nano or your favorite text editor:

首先,在nano或您喜欢的文本编辑器中打开eula.txt

  • nano eula.txt

    纳米eula.txt

Inside this file, you will see a link to the Minecraft EULA. Copy the URL:

在此文件内,您将看到指向Minecraft EULA的链接。 复制网址:

~/eula.txt
〜/ eula.txt
#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Tue Mar 24 22:05:31 UTC 2020
eula=false

Open the URL in your web browser and read the agreement. Then return to your text editor and find the last line in eula.txt. Here, change eula=false to eula=true. Now save and close the file.

在Web浏览器中打开URL并阅读协议。 然后返回到文本编辑器,并在eula.txt找到最后一行。 在这里,将eula=false更改为eula= true 。 现在保存并关闭文件。

Now that you’ve accepted the EULA, it is time to configure the server to your specifications.

现在您已经接受了EULA,是时候按照您的规范配置服务器了。

In your current working directory, you will also find the newly created server.properties file. This file contains all of the configuration options for your Minecraft server. You can find a detailed list of all server properties on the Official Minecraft Wiki. You will modify this file with your preferred settings before starting your server. This tutorial will cover the fundamental properties:

在当前工作目录中,您还将找到新创建的server.properties文件。 该文件包含您的Minecraft服务器的所有配置选项。 您可以在Official Minecraft Wiki上找到所有服务器属性的详细列表。 在启动服务器之前,将使用首选设置修改此文件。 本教程将介绍基本属性:

  • nano server.properties

    纳米server.properties

Your file will appear like this:

您的文件将如下所示:

~/server.properties
〜/ server.properties
#Minecraft server properties
#Thu Apr 30 23:42:29 UTC 2020
spawn-protection=16
max-tick-time=60000
query.port=25565
generator-settings=
force-gamemode=false
allow-nether=true
enforce-whitelist=false
gamemode=survival
broadcast-console-to-ops=true
enable-query=false
player-idle-timeout=0
difficulty=easy
spawn-monsters=true
broadcast-rcon-to-ops=true
op-permission-level=4
pvp=true
snooper-enabled=true
level-type=default
hardcore=false
enable-command-block=false
max-players=20
network-compression-threshold=256
resource-pack-sha1=
max-world-size=29999984
function-permission-level=2
rcon.port=25575
server-port=25565
server-ip=
spawn-npcs=true
allow-flight=false
level-name=world
view-distance=10
resource-pack=
spawn-animals=true
white-list=false
rcon.password=
generate-structures=true
online-mode=true
max-build-height=256
level-seed=
prevent-proxy-connections=false
use-native-transport=true
motd=A Minecraft Server
enable-rcon=false

Let’s take a closer look at some of the most important properties in this list:

让我们仔细看看此列表中的一些最重要的属性:

  • difficulty (default easy) - This sets the difficulty of the game, such as how much damage is dealt and how the elements affect your player. The options are peaceful, easy, normal, and hard.

    difficulty (默认为easy )-设置游戏的难度,例如造成多少伤害以及元素如何影响玩家。 选项包括peacefuleasynormalhard

  • gamemode (default survival) - This sets the gameplay mode. The options are survival, creative,adventure, and spectator.

    gamemode (默认survival )-设置游戏模式。 选项包括survivalcreativeadventurespectator

  • level-name (default world) - This sets the name of your server that will appear in the client. Characters such as the apostrophe may need to be escaped with a backslash.

    level-name (默认world )-设置将出现在客户端中的服务器的名称。 诸如撇号之类的字符可能需要用反斜杠转义。

  • motd (default A Minecraft Server) - The message that is displayed in the server list of the Minecraft client.

    motd (默认A Minecraft Server )-Minecraft客户端的服务器列表中显示的消息。

  • pvp (default true) - Enables Player versus Player combat. If set to true, players will be able to engage in combat and damage each other.

    pvp (默认为true )-启用玩家对玩家战斗。 如果设置为true ,则玩家将能够进行战斗并互相伤害。

Once you have set the options that you want, save and close the file.

设置所需的选项后,保存并关闭文件。

Now that you have changed EULA to true and configured your settings, you can successfully start your server.

现在您已将EULA更改为true并配置了设置,就可以成功启动服务器了。

Like last time, let’s start your server with 1024M of RAM. Only now, let’s also grant Minecraft the ability to use up to 4G of RAM if it needs it. Remember, you are welcome to adjust this number to fit your server limitations or user needs:

与上次一样,让我们​​以1024M RAM启动服务器。 直到现在,我们还让Minecraft能够在需要时使用高达4G的RAM。 请记住,欢迎您调整此数字以适合您的服务器限制或用户需求:

  • java -Xms1024M -Xmx4G -jar minecraft_server_1.15.2.jar nogui

    java -Xms1024M -Xmx4G -jar minecraft_server_1.15.2.jar nogui

Give the initialization a few moments. Soon your new Minecraft server will start producing an output similar to this:

给初始化一些时间。 很快,您的新Minecraft服务器将开始产生类似于以下内容的输出:


   
   
Output
[21:08:14] [Server thread/INFO]: Starting minecraft server version 1.15.2 [21:08:14] [Server thread/INFO]: Loading properties [21:08:14] [Server thread/INFO]: Default game type: SURVIVAL [21:08:14] [Server thread/INFO]: Generating keypair [21:08:15] [Server thread/INFO]: Starting minecraft server on *:25565

Once the server is up and running, you will see the following output:

服务器启动并运行后,您将看到以下输出:


   
   
Output
[21:15:37] [Server thread/INFO]: Done (30.762s)! For help, type "help"

Your server is now running, and you have been dropped into the server administrator control panel. Now type help:

您的服务器现在正在运行,并且您已进入服务器管理员控制面板。 现在输入help

  • help

    救命

An output like this will appear:

这样的输出将出现:


   
   
Output
[21:15:37] [Server thread/INFO]: /advancement (grant|revoke) [21:15:37] [Server thread/INFO]: /ban <targets> [<reason>] [21:15:37] [Server thread/INFO]: /ban-ip <target> [<reason>] [21:15:37] [Server thread/INFO]: /banlist [ips|players] ...

From this terminal you can execute administrator commands and control your Minecraft server. Now let’s use screen to keep your new server running, even after you log out. Then you can connect to your Minecraft client and start a new game.

在此终端上,您可以执行管理员命令并控制您的Minecraft服务器。 现在,即使您注销后,也可以使用screen来保持新服务器的运行。 然后,您可以连接到Minecraft客户端并开始新游戏。

第4步-保持服务器运行 (Step 4 — Keeping the Server Running)

Now that you have your server up, you want it to remain running even after you disconnect from your SSH session. Since you used screen earlier, you can detach from this session by pressing Ctrl + A + D. Now you’re back in your original shell.

现在您已经启动了服务器,即使从SSH会话断开连接后,您也希望它保持运行状态。 由于您之前使用过screen ,因此可以通过按Ctrl + A + D脱离此会话。 现在,您回到了原始外壳中。

Run this command to see all of your screen sessions:

运行此命令以查看所有屏幕会话:

  • screen -list

    屏幕列表

You’ll get an output with the ID of your session, which you’ll need to resume that session:

您将获得带有会话ID的输出,您需要恢复该会话:


   
   
Output
There is a screen on: 26653.pts-0.minecraft (03/25/20 21:18:31) (Detached) 1 Socket in /run/screen/S-root.

To resume your session, pass the -r flag to the screen command and then enter your session ID:

要恢复会话,请将-r标志传递给screen命令,然后输入会话ID:

  • screen -r 26653

    屏幕-r 26653

When you are ready to log out of your server, be sure to detach from the session with Ctrl + A + D and then log out.

准备好注销服务器时,请确保使用Ctrl + A + D从会话中分离出来,然后注销。

步骤5 —从Minecraft客户端连接到服务器 (Step 5 — Connecting to Your Server from the Minecraft Client)

Now that your server is up and running, let’s connect to it through the Minecraft client. Then you can play!

现在您的服务器已经启动并正在运行,让我们通过Minecraft客户端连接到它。 那你就可以玩了!

Launch your copy of Minecraft Java Edition and select Multiplayer in the menu.

启动您的Minecraft Java Edition副本,然后在菜单中选择“ 多人游戏 ”。

Next, you will need to add a server to connect to, so click on the Add Server button.

接下来,您将需要添加要连接的服务器,因此单击“ 添加服务器”按钮。

In the Edit Server Info screen that shows up, give your server a name and type in the IP address of your server. This is the same IP address that you used to connect through SSH.

在出现的“ 编辑服务器信息”屏幕中,为您的服务器命名并输入服务器的IP地址。 这是您用于通过SSH连接的IP地址。

Once you have entered your server name and IP address, you’ll be taken back to the Multiplayer screen where your server will now be listed.

输入服务器名称和IP地址后,您将回到“多人游戏”屏幕,现在将在其中列出您的服务器。

From now on, your server will always appear in this list. Select it and click Join Server.

从现在开始,您的服务器将始终显示在此列表中。 选择它,然后单击Join Server

You are in your server and ready to play!

您已经在服务器上,可以玩了!

结论 (Conclusion)

You now have a Minecraft server running on Ubuntu 18.04 for you and all of your friends to play on! Have fun exploring, crafting, and surviving in a crude 3D world. And remember: watch out for griefers.

现在,您已经在Ubuntu 18.04上运行了Minecraft服务器,供您和您的所有朋友一起玩! 在原始的3D世界中探索,制作和生存,玩得开心。 请记住:提防悲痛者。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-create-a-minecraft-server-on-ubuntu-18-04

minecraft1.12

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值