标签归档:Minecraft

Windows后台运行Minecraft服务器

官网提供的服务器启动命令是

java -Xmx1024M -Xms1024M -jar server.jar nogui

在Linux下,我们后台启动服务器非常简单,只需要在命令后加上&即可

nohup java -Xmx1024M -Xms1024M -jar server.jar nogui &

但是,在Windows下,直接在命令行中启动的话,将会关联到cmd这个父进程。也就是说,cmd窗口一关,java服务也会停止。这显然是我们不喜欢的,所以需要后台运行。于是我们用javaw完成:

@echo off 
start javaw -Xmx1024M -Xms1024M -jar server.jar nogui

将上面内容保存为bat文件执行即可。

Ubuntu 16.04部署minecraft服务器

更新系统软件

apt update && apt upgrade

安装jre(java运行环境)

apt install default-jre

安装screen

apt install screen

创建新用户minecraft用于运行minecraft服务

sudo adduser minecraft

如果设置了iptable,请加入以下规则开放25565端口

-A INPUT -p tcp --dport 25565 -j ACCEPT

现在,退出当前ssh连接,并使用minecraft用户重新登录。(注意:此处请退出ssh,而不是直接使用su minecraft命令切换用户。否则执行screen命令的时候将报错,具体原因和解决方法看 此贴 )。以下步骤使用minecraft用户进行。

创建minecraft目录,从 官网 下载jar包放入目录。

mkdir minecraft
cd minecraft
wget https://s3.amazonaws.com/Minecraft.Download/versions/1.xx.xx/minecraft_server.1.xx.xx.jar

创建一个脚本以运行server

脚本:/home/minecraft/minecraft/run.sh

#!/bin/sh
BINDIR=$(dirname "$(readlink -fn "$0")")
cd "$BINDIR"

java -Xms1024M -Xmx1536M -jar minecraft_server.1.xx.xx.jar -o true

赋予权限:

chmod +x run.sh

尝试执行

$ ./run.sh
[21:39:43] [Server thread/INFO]: Starting minecraft server version 1.8.8
[21:39:43] [Server thread/INFO]: Loading properties
[21:39:43] [Server thread/WARN]: server.properties does not exist
[21:39:43] [Server thread/INFO]: Generating new properties file
[21:39:43] [Server thread/WARN]: Failed to load eula.txt
[21:39:43] [Server thread/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
[21:39:43] [Server thread/INFO]: Stopping server

提示需要统一EULA协议。很简单,修改minecraft目录下生成的eula.txt文件,将eula置为true即可。

文件:/home/minecraft/minecraft/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 Jan 27 21:40:00 UTC 2015
eula=true

* 如果有需要,可以禁用掉minecraft的用户在线校验,打开 server.properties, 修改:

online-mod=false

创建一个screen以运行minecraft

screen -S minecraft

此操作相当于重新开了一个console。

在这个screen中运行minecraft服务器

./run.sh

此时,如果看到类似以下提示,服务器便已经正常运行了

[22:00:06] [Server thread/INFO]: Starting minecraft server version 1.8.8
[22:00:06] [Server thread/INFO]: Loading properties
[22:00:06] [Server thread/INFO]: Default game type: SURVIVAL
[22:00:06] [Server thread/INFO]: Generating keypair
[22:00:07] [Server thread/INFO]: Starting Minecraft server on *:25565
 
....
 
[22:00:07] [Server thread/INFO]: Preparing level "world"
[22:00:08] [Server thread/INFO]: Preparing start region for level 0
[22:00:09] [Server thread/INFO]: Preparing spawn area: 3%
 
....
 
[22:00:21] [Server thread/INFO]: Preparing spawn area: 96%
[22:00:22] [Server thread/INFO]: Done (14.737s)! For help, type "help" or "?"

附,screen的一些操作

可以使用-ls查询当前正在使用的screen

screen -ls

可以使用-x [screenname] 回到指定的screen

screen -x minecraft

参考:https://www.linode.com/docs/applications/game-servers/minecraft-on-debian-and-ubuntu

启动器:http://teamshiginima.com/