初音ミクの消失

在linux上搭建minecraft java版服务器

字数统计: 3.1k阅读时长: 17 min
2019/06/09 Share

如何在Linux上搭建Minecraft服务器

搭建minecraft服务器并不复杂,只需要一些linux的基础操作知识就行了

灵感来自csdn,教程为自己编写.

购买服务器

我选择的是阿里云学生机,这样的配置能带好几个人加上几个大mod,几个小伙伴一起玩已经足够了

理论上Ubuntu也可以使用,不过这个教程里面的指令都是基于centOS的

Snipaste_2019-06-09_11-39-45.png

配置服务器

查看java版本

java --version

如果提示

[[email protected] /]# java –version
-bash: java: command not found

则说明没有安装java

安装java

sudo yum install java-1.8.0-openjdk

选择目录

然后自己找一个想装mc的目录

cd usr
mkdir minecraft
cd minecraft

获取mc服务器端

根据你玩的mc的版本,可以下载相应的jar包

sudo wget https://s3.amazonaws.com/Minecraft.Download/versions/版本号/minecraft_server.版本号.jar

以我的为例,目前支持mod的最新版本是1.12.2

sudo wget https://s3.amazonaws.com/Minecraft.Download/versions/1.12.2/minecraft_server.1.12.2.jar

开启游戏!

创建启动脚本

在这之前,先创建一个启动脚本,方便后续一键启动

sudo vi start.sh

在start.sh填入如下的内容

sudo java -Xms120m -Xmx160m -jar /usr/minecraft/minecraft_server.1.12.2.jar nogui

其中120m,160m分别是给服务器分配的内存,建议如果是开forege服的话把最大内存调高一点,不然mod带不动


开启

开启服务器

bash start.sh

不要着急,这里一定启动不了的,因为你没有同意用户协议

[04:00:32] [Server thread/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.

打开eula.txt

sudo vi eula.txt

把false改为true

eula=true

安装forge

现在已经可以启动服务器了,无mod需求的可以直接开服,无需进行下面的步骤

但是我们还是无法运行mod,需要安装forge

可以去官网自行下载,也可以用我的指令

sudo wget https://files.minecraftforge.net/maven/net/minecraftforge/forge/1.12.2-14.23.5.2768/forge-1.12.2-14.23.5.2768-installer.jar

接下来是安装forge

java -jar forge-1.12.2-14.23.5.2768-installer.jar nogui --installServer

Extracting: /forge-1.12.2-14.23.5.2768-universal.jar
To: /usr/minecraft/./forge-1.12.2-14.23.5.2768-universal.jar
The server installed successfully, you should now be able to run the file forge-1.12.2-14.23.5.2768-universal.jar
You can delete this installer file now if you wish

这个 forge-1.12.2-14.23.5.2768-universal.jar 就是启动forge服务器的启动端

打开start.sh把原版启动程序换为forge的启动程序

sudo vi start.sh

填入

sudo java -Xms120m -Xmx160m -jar /usr/minecraft/forge-1.12.2-14.23.5.2768-universal.jar nogui

开服

bash start.sh

[04:22:29] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing start region for level 0
[04:22:30] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing spawn area: 2%
[04:22:32] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing spawn area: 4%
[04:22:33] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing spawn area: 7%
[04:22:49] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing spawn area: 50%
[04:22:50] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing spawn area: 52%
[04:22:55] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing spawn area: 64%
[04:23:05] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing spawn area: 97%
[04:23:06] [Server thread/INFO] [minecraft/DedicatedServer]: Done (39.625s)! For help, type “help” or “?”

其他补充

screen

开服之后的服务器其实并不稳定,只要你关闭远程连接,mc便会自动结束

为了解决这个问题 就要用到screen工具

sudo yum install screen

在开服之前,先创建一个screen

screen -S mc

创建好screen之后再开启mc服务器

当然,如果需要切换出来 , 按一下Ctrl+a 再按一下d即可

[[email protected] ~]# screen -S mc
[detached from 7293.mc]
[[email protected] ~]#

下次还需进入该screen,就不需要创建了,直接

screen -r mc

mod

要加载mod,将服务器端使用的mod放入/usr/minecraft/mods文件夹,重启mc服务器即可

server.properties

配置文件修改,具体请参照官方文档

通常是把pvp,正版检测关闭

还可以限制总加入人数,服务器难度,以及最大高度等等

Java Edition
Key Type Default Value Description
allow-flight boolean false Allows users to use flight on your server while in Survival mode, if they have a modthat provides flight installed.With allow-flight enabled, griefers will possibly be more common, because it will make their work easier. In Creative mode this has no effect.false - Flight is not allowed (players in air for at least 5 seconds will be kicked).true - Flight is allowed, and used if the player has a fly mod installed.
allow-nether boolean true Allows players to travel to the Nether.false - Nether portals will not work.true - The server will allow portals to send players to the Nether.
difficulty string easy Defines the difficulty (such as damage dealt by mobs and the way hunger and poison affects players) of the server.If a legacy difficulty number is specified it will be silently converted to a difficulty name.peaceful (0)easy (1)normal (2)hard (3)
enable-command-block boolean false Enables command blocks
enable-query boolean false Enables GameSpy4 protocol server listener. Used to get information about server.
enable-rcon boolean false Enables remote access to the server console.
force-gamemode boolean false Force players to join in the default game mode.false - Players will join in the gamemode they left in.true - Players will always join in the default gamemode.
gamemode string survival Defines the mode of gameplay.If a legacy gamemode number is specified it will be silently converted to a gamemode name.survival (0)creative (1)adventure (2)spectator (3)
generate-structures boolean true Defines whether structures (such as villages) will be generated.false - Structures will not be generated in new chunks.true - Structures will be generated in new chunks.Note: Dungeons will still generate if this is set to false.
generator-settings string blank The settings used to customize world generation. See Superflat and Customized for possible settings and examples.
hardcore boolean false If set to true, server difficulty is ignored and set to hard and players will be set to spectator mode if they die.
level-name string world The “level-name” value will be used as the world name and its folder name. You may also copy your saved game folder here, and change the name to the same as that folder’s to load it instead.Characters such as ‘ (apostrophe) may need to be escaped by adding a backslash before them.
level-seed string blank Add a seed for your world, as in Singleplayer.Some examples are: minecraft, 404, 1a2b3c.
level-type string default Determines the type of map that is generated.default - Standard world with hills, valleys, water, etc.flat - A flat world with no features, can be modified with generator-settings.largebiomes - Same as default but all biomes are larger.amplified - Same as default but world-generation height limit is increased.buffet - Same as default unless generator-settings is set to a preset.
max-build-height integer 256 The maximum height in which building is allowed. Terrain may still naturally generate above a low height limit.
max-players integer (0-2147483647) 20 The maximum number of players that can play on the server at the same time. Note that if more players are on the server it will use more resources. Note also, op player connections are not supposed to count against the max players, but ops currently cannot join a full server. However, this can be changed by going to the file called ops.json in your server directory, opening it, finding the op you want the change, and changing the setting called bypassesPlayerLimit to true (the default is false). This means that that op will not have to wait for a player to leave in order to join. Extremely large values for this field result in the client-side user list being broken.
max-tick-time integer (0–(2^63 - 1)) 60000 The maximum number of milliseconds a single tick may take before the server watchdog stops the server with the message, A single server tick took 60.00 seconds (should be max 0.05); Considering it to be crashed, server will forcibly shutdown. Once this criterion is met, it calls System.exit(1).-1 - disable watchdog entirely (this disable option was added in 14w32a)
max-world-size integer (1-29999984) 29999984 This sets the maximum possible size in blocks, expressed as a radius, that the world border can obtain. Setting the world border bigger causes the commands to complete successfully but the actual border will not move past this block limit. Setting the max-world-size higher than the default doesn’t appear to do anything.Examples:Setting max-world-size to 1000 will allow you to have a 2000x2000 world border.Setting max-world-size to 4000 will give you an 8000 x 8000 world border.
motd string A Minecraft Server This is the message that is displayed in the server list of the client, below the name.The MOTD supports color and formatting codes.The MOTD supports special characters, such as “♥”. However, such characters must be converted to escaped Unicode form. An online converter can be found here.If the MOTD is over 59 characters, the server list will likely report a communication error.
network-compression-threshold integer 256 By default it allows packets that are n-1 bytes big to go normally, but a packet that nbytes or more will be compressed down. So, lower number means more compression but compressing small amounts of bytes might actually end up with a larger result than what went in.-1 - disable compression entirely0 - compress everythingNote: The Ethernet spec requires that packets less than 64 bytes become padded to 64 bytes. Thus, setting a value lower than 64 may not be beneficial. It is also not recommended to exceed the MTU, typically 1500 bytes.
online-mode boolean true Server checks connecting players against Minecraft account database. Only set this to false if your server is not connected to the Internet. Hackers with fake accounts can connect if this is set to false! If minecraft.net is down or inaccessible, no players will be able to connect if this is set to true. Setting this variable to off purposely is called “cracking” a server, and servers that are presently with online mode off are called “cracked” servers, allowing players with unlicensed copies of Minecraft to join.true - Enabled. The server will assume it has an Internet connection and check every connecting player.false - Disabled. The server will not attempt to check connecting players.
op-permission-level integer (1-4) 4 Sets the default permission level for ops when using /op. All levels inherit abilities and commands from levels before them.1 - Ops can bypass spawn protection.2 - Ops can use all singleplayer cheats commands (except /publish, as it is not on servers; along with /debug and /reload) and use command blocks. Command blocks, along with Realms owners/operators, have the same permissions as this level.3 - Ops can use most multiplayer-exclusive commands, including /debug, /reload, and commands that manage players (/ban, /op, etc).4 - Ops can use all commands including /stop, /save-all, /save-on, /save-off, /forceload add, and /forceload remove.
player-idle-timeout integer 0 If non-zero, players are kicked from the server if they are idle for more than that many minutes.Note: Idle time is reset when the server receives one of the following packets:Click WindowEnchant ItemUpdate SignPlayer DiggingPlayer Block PlacementHeld Item ChangeAnimation (swing arm)Entity ActionClient StatusChat MessageUse Entity
prevent-proxy-connections boolean false If the ISP/AS sent from the server is different from the one from Mojang’s authentication server, the player is kickedtrue - Enabled. Server prevents users from using vpns or proxies.false - Disabled. The server doesn’t prevent users from using vpns or proxies.
pvp boolean true Enable PvP on the server. Players shooting themselves with arrows will only receive damage if PvP is enabled.true - Players will be able to kill each other.false - Players cannot kill other players (also known as Player versus Environment (PvE)).Note: Indirect damage sources spawned by players (such as lava, fire, TNT and to some extent water, sand and gravel) will still deal damage to other players.
query.port integer (1-65534) 25565 Sets the port for the query server (see enable-query).
rcon.password string blank Sets the password to rcon.
rcon.port integer (1-65534) 25575 Sets the port to rcon.
resource-pack string blank Optional URI to a resource pack. The player may choose to use it.Note that the “:” and “=” characters need to be escaped with backslash (), e.g. http://somedomain.com/somepack.zip?someparam=somevalueNote download success/failure is logged by the client, not by the server.
resource-pack-sha1 string blank Optional SHA-1 digest of the resource pack, in lowercase hexadecimal. It’s recommended to specify this. This is not yet used to verify the integrity of the resource pack, but improves the effectiveness and reliability of caching.
server-ip string blank Set this if you want the server to bind to a particular IP. It is strongly recommended that you leave server-ip blank!Set to blank, or the IP you want your server to run (listen) on.
server-port integer (1-65534) 25565 Changes the port the server is hosting (listening) on. This port must be forwarded if the server is hosted in a network using NAT (If you have a home router/firewall).
snooper-enabled boolean true Sets whether the server sends snoop data regularly to http://snoop.minecraft.net.false - disable snooping.true - enable snooping.
spawn-animals boolean true Determines if animals will be able to spawn.true - Animals spawn as normal.false - Animals will immediately vanish.Tip: if you have major lag, turn this off/set to false.
spawn-monsters boolean true Determines if monsters will be spawned.true - Enabled. Monsters will appear at night and in the dark.false - Disabled. No monsters.This setting has no effect if difficulty = 0 (peaceful). If difficulty is not = 0, a monster can still spawn from a Monster Spawner.Tip: if you have major lag, turn this off/set to false.
spawn-npcs boolean true Determines whether villagers will be spawned.true - Enabled. Villagers will spawn.false - Disabled. No villagers.
spawn-protection integer 16 Determines the radius of the spawn protection as 2x+1. Setting this to 0 will not disable spawn protection. 0 will protect the single block at the spawn point. 1 will protect a 3x3 area centered on the spawn point. 2 will protect 5x5, 3 will protect 7x7, etc. This option is not generated on the first server start and appears when the first player joins. If there are no ops set on the server, the spawn protection will be disabled automatically.
use-native-transport boolean true Linux server performance improvements: optimized packet sending/receiving on Linuxtrue - Enabled. Enable Linux packet sending/receiving optimizationfalse - Disabled. Disable Linux packet sending/receiving optimization
view-distance integer (2-32) 10 Sets the amount of world data the server sends the client, measured in chunks in each direction of the player (radius, not diameter). It determines the server-side viewing distance. (see Render distance)10 is the default/recommended. If you have major lag, reduce this value.*Note: *A value less than 9 will have big impacts on the mobs’ spawn of your server as it mentionned by the bug MC-2536.
white-list boolean false Enables a whitelist on the server.With a whitelist enabled, users not on the whitelist will be unable to connect. Intended for private servers, such as those for real-life friends or strangers carefully selected via an application process, for example.false - No white list is used.true - The file whitelist.json is used to generate the white list.Note: Ops are automatically white listed, and there is no need to add them to the whitelist.
enforce-whitelist boolean false Enforces the whitelist on the server.When this option is enabled, users who are not present on the whitelist (if it’s enabled) will be kicked from the server after the server reloads the whitelist file.false - No user will be kicked if not on the whitelist.true - Online users not on the whitelist will be kicked.

In versions prior to Java Edition 1.12, the announce-player-achievements boolean property (default true) was used to toggle whether achievementswere broadcasted to all players. This property no longer exists, but if it is set, the announceAdvancements gamerule will automatically be updated to match and the property will be removed.

原文作者:mrh929

原文链接:https://mrh1s.top/posts/6f2d090a/

发表日期:June 9th 2019, 11:36:09 am

更新日期:June 9th 2019, 1:17:14 pm

版权声明:本文采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可

CATALOG
  1. 1. 如何在Linux上搭建Minecraft服务器
    1. 1.1. 购买服务器
    2. 1.2. 配置服务器
      1. 1.2.1. 查看java版本
      2. 1.2.2. 选择目录
      3. 1.2.3. 获取mc服务器端
    3. 1.3. 开启游戏!
      1. 1.3.1. 创建启动脚本
      2. 1.3.2. 开启
      3. 1.3.3. 安装forge
      4. 1.3.4. 开服
    4. 1.4. 其他补充
      1. 1.4.1. screen
      2. 1.4.2. mod
      3. 1.4.3. server.properties
        1. 1.4.3.0.0.1. Java Edition