在这个教程中,我们将通过手把手的方式,一步步地帮助你建立属于你自己的Minecraft服务器。在该教程中,我们使用Mojang发布的供玩家免费下载的服务器端程序,该程序在大部分操作系统(比如Windows,Mac OS以及Linux等)上都可以运行。
根据你所使用的操作系统,你必须前往官方的下载页面,下载所需的Minecraft服务器端程序。我们建议你新建一个文件夹用于保存服务器端文件。(下载后请确认下载的服务器端文件是否是 minecraft_server.jar 或者 minecraft_server.exe,因为有时你的浏览器会将可执行文件重命名。)
注意:网上也有许多Minecraft的第三方服务器端程序,不过它们都是不受Mojang技术支持的。
Windows 操作指导
需求:确认你的操作系统安装了最新版本的Java环境
- 确保你安装了Java 6。除非Sun公司官方发布,否则不要安装Java 7,除非你想做软件调试。为了检查当前的Java环境,我们可以打开一个命令提示符(CMD)窗口。
- Windows Vista/7 系统下,点「开始菜单」,在搜索框中输入 cmd,回车。
- Windows XP 系统下,点「开始菜单」-> 「运行」,然后输入 cmd 并回车。你也可以使用「运行」的快捷键:Windows键 + R。
- 在命令提示符窗口,输入命令
java -version并回车。 - 窗口中应该会显示当前你的电脑的Java版本,应该为 "Java version 1.6"。
- 如果你得到了无效的命令错误提示, "
'Java' 不是内部或外部命令,也不是可运行的程序或批处理文件",那么你的电脑上运行的可能是早期Java版本(比1.6早)或者根本就没有Java环境。- 对于32位系统的用户,可以到此处下载最新版本的Java。如果你的系统是64位的,确保你下载的是Windows x64 Java包。
- 在你安装了最新版的Java之后,你可以尝试在命令提示符窗口再次输入
java -version并回车。- 如果你依旧得到错误提示,请尝试以下步骤,将Java添加到你的系统环境变量中去。
- 右键点击「我的电脑」。
- 点「属性」。
- 点「高级系统设置」。
- 点「环境变量」。
- 在「系统变量下」,选中「Path」变量。
- 点编辑,在内容的结尾处加上
;"c:\Program Files\Java\jre6\bin"。如果你在64位系统上使用32位Java,则使用;"c:\Program Files (x86)\Java\jre6\bin"。 - 重启电脑。
- 再次打开命令提示符输入
java -version并回车,验证。
启动Minecraft服务器端程序 (.exe 版)
- 双击「Minecraft_Server.exe」文件。服务器程序将会以默认配置启动。
- 第一次启动时,会显示一些「file not found」(文件无法找到)的错误提示。这是正常的,这些文件正在创建当中。
- 第一次启动之后,我们可以开始配置服务器文件了。首先将打开的服务器程序关闭:在命令窗口里输入
stop。之后我们开始按照下面的指导进行服务器配置。
增加Minecraft服务器端程序所占用的内存
如果你想让你的服务器端程序占用更多的内存,你就需要创建一个批处理文件。没关系,这比听起来容易。
- 打开「记事本」(不是「写字板」哟),新建一个文本文件。
- 确认下你的Windows系统是32位的还是64位的,可以在控制面板里面查看。并且确认下你的Java版本是32位的还是64位的。
- 根据你的系统以及Java版本……
- 如果Windows系统是32位的或者是64位且安装的是64位的Java,复制下面的内容到你的文本文件中(只占一行。如果使用Java 6,请根据命令中的目录):
"C:\Program Files\Java\jre7\bin\javaw.exe" -Xmx2048M -Xms2048M -jar "Minecraft_Server.exe"
- 如果你因为一些奇怪的原因,正在64位系统上运行32位的Java,升级你的Java。并且,如果你把Java装载其他目录里了,或者你重命名了Minecaft服务器程序文件,见下:
- 如果你在64位系统上有32位的Java,Java.com会通过浏览器判别你的版本,对于一些32位的浏览器,会推荐给你下载32位的Java。在这样情况下,为确保万无一失,请把32位和64位的Java都下载并安装了吧。
- 文本文件这一行到底是什么意思呢? 这条可执行命令(
"C:\Program Files\Java\jre7\bin\javaw.exe"))是一个文件地址,指向你系统最新的javaw.exe。如果你的Java版本是8,你应该把命令中的'jre7'改成'jre8',如果你把Java安装在了其他地址下,你就需要找到那个地址,复制粘贴过来,替换到上面这个错误地址。 下一部分(-Xmx2048M -Xms2048M)表示你分配的内存大小。以MB(MegaBytes,兆)计算。默认情况下,你服务器只会使用100MB内存,这对于Minecraft服务器来说太小了。大部分用户会分配给服务器程序1024MB(也就是1GB),或者2048MB(2GB)也是一般推荐的。 下一个,参数-jar,是用来表示Minecraft_Server.exe是Java架构程序的。 - 在这条可执行命令的最后是我们的.exe文件的名字(
Minecraft_Server.exe)。一般来说,名字是Minecraft_Server.exe. 大小写不区分,不一样没关系,如果你的.恩建已经改名,就把这条命令里的文件名也改成你相应的名字。最后,点 文件->另存为...,将文件取名为run.bat,并且确保在窗口的文件类型那,选中为所有文件(*.*)。 然后保存到和你服务器端程序所在相同的目录下。双击刚建立的run.bat文件。如果一切都按照正确步骤坐下来,你就会注意到现在你的服务器程序申请到更多的内存了!
- 如果Windows系统是32位的或者是64位且安装的是64位的Java,复制下面的内容到你的文本文件中(只占一行。如果使用Java 6,请根据命令中的目录):
如果Windows没有识别出文件类型(你可能会被提示选择用什么程序来打开),这也许是因为Minecraft_Server缺少了.exe文件名后缀。我们可以通过重命名Minecraft_Server为Minecraft_Server.exe来修正这个问题。如果问题解决,程序的图标就会变成Minecraft的图标(方块)。 如果还是没解决,你需要打开命令提示符窗口,点「运行」,输入cmd回车。然后你需要将命令提示符窗口当前地址定位到你创建的文件夹地址去。
按照以下步骤来:
- 确保你在正确的盘符(一般是C盘)。输入
C:然后回车来进入C盘。 - 现在你需要打开你的目录。输入
cd \"folder name"然后回车,要包含引号部分。 - 确认你在正确的目录下了,输入
dir然后回车你会看到你当前所在目录下的所有文件和目录。如果正确的话,你应该可以看到minecraft_server在其中。 - 重命名Minecraft。输入
rename minecraft_server minecraft_server.exe然后回车,这么做会将.exe后缀添加到文件名上,使文件变成可执行文件。之后就应该可以正确的打开运行了。
启动Minecraft服务器端程序 (.jar 版)
- 如果你用的是.jar版的服务器端程序,你需要在环境变量中添加正确的Java地址。要完成这一操作,请回到前面的「确认你的操作系统安装了最新版本的Java环境」指导章节。
- To start the jar version of Minecraft on Windows, create a new file in Notepad, and paste in
java -Xms512M -Xmx1024M -jar minecraft_server.jar
- Save the file as startserver.bat, and place the file in the same folder as minecraft_server.jar. The .bat extension saves the file as a batch file.
- Double click startserver.bat, and the Minecraft server will run.
Starting the jar version without altering your system path
To start minecraft.jar server without having to change your system path variable you need to instead express the path variable for Java in the "start.bat" file. This is handy because it allows you to still run commands from command prompt using the default system path, without having to constantly edit the system path.
- To do this open your start.bat file (or whatever you've named it) with Notepad
- On the very first line add the command
@echo off
so that a command window isn't opened to show the output from our start file - On the next line, make sure the system can find Java (also called the Java Runtime Environment or JRE) by adding it to the Path Environment Variable. On a current Windows PC Java will be most commonly located at "C:\Program Files (x86)\Java\jre7\bin\java.exe", so what you would then write is
path=%PATH%;%ProgramFiles(x86)%\Java\jre7\bin\java.exe
where%PATH%contains the existing Path values and%ProgramFiles(x86)%contains the location of your 32bit Program Files - usually "C:\Program Files (x86)" (adjust this if you are using Java 6) - Finally, make sure on the last line you have the command that starts the Minecraft server itself:
java -Xms512M -Xmx1024M -jar minecraft_server.jar - If you prefer not to use the server's Graphical User Interface (GUI) to enter administration commands, simply add the option
noguito the end of the last command above, so that it reads:
java -Xms512M -Xmx1024M -jar minecraft_server.jar nogui
Mac OS X 设置指南
在Mac OSX上设置Minecraft服务器,相比Windows上要"跟复杂",原因是一个官方并没提供简单的Mac OSX支持的应用程序。我们在此提供了一个完整的视频教程点此播放。须知服务器端在OSX 10.4 老虎 上无法正确运行并且可能使电脑崩溃。
下载
确保你有最新的服务器端应用软件。去上面 看指导。
安装Java环境
Mac OS X 已经包含了它自带的Java,并且会通过系统的软件更新功能保持为最新版本。(苹果菜单 > 软件更新)
架设Minecraft服务器
确保你根据已经完成了上面的下载步骤,然后开始接下来的操作:
- 创建一个文件夹,将minecraft_server.jar放入其中。比如,在桌面上创建一个名为「minecraft_server」的文件夹,然后把.jar文件拖进去。
- 打开「文本编辑」,设定格式为纯文本(格式 > 制作纯文本),然后复制下面的内容到编辑器中:
#!/bin/bash
cd "$(dirname "$0")"
exec java -Xmx1G -Xms1G -jar minecraft_server.jar
- 保存文件到.jar所在的目录并重命名为"start.command"。
- 这个就可以给服务器端足够的内存来运行。占用内存总数可以通过改变文本中的
1G来实现,比如把它改成2G,那么你的服务器就会用2G的内存来运行。
- 这个就可以给服务器端足够的内存来运行。占用内存总数可以通过改变文本中的
- 打开「终端」(在/应用程序/实用工具/终端)。
- 给予该可执行文件运行权限给用户,组和公共。来完成这部,在终端中输入
chmod a+x,别忘了后面有个空格;然后拖 start.command 文件到终端窗口中,然后按下回车键。 (这就给了该脚本运行权限。) - 双击start.command来运行服务器端程序。
- 一个新的终端窗口会打开,但你第一次运行该脚本时,会出现很多错误信息,提示你一些文件(files/directories)无法找到。这是正常的。现在你可以开始配置你的服务器了。
作为后台进程运行
你也可以让服务器程序在系统开机后自动后台运行。
创建Mac OSX开机自动后台运行程序
Linux Instructions
This tutorial for how to set up a Minecraft server on Linux was designed for people who don't have a lot of experience with Linux. There is a more advanced tutorial in the forums. This tutorial was tested on Ubuntu 9.10 32-bit but should work with the descendants of Debian.
Downloading
Ensure you have the latest server application software. Look above for instructions.
Installing Java
If you get java: command not found (which may be followed by more text) or if you do have another Java version than 1.6 then you need to install or update java.
The official Sun Java is recommended. Quite a few individuals have experienced issues with OpenJDK. If OpenJDK is installed, remove it before installing the official Sun Java.
Debian
Ensure that the non-free repository is being scanned by apt. You do this by adding non-free to your /etc/apt/sources.list file. e.g:
deb http://ftp.uk.debian.org/debian/ squeeze main non-free
Update your sources list: apt-get update as root
Then to install Java, simply type this in terminal and press enter:
apt-get install sun-java6-jre as root
Ubuntu
For Ubuntu 10.04 LTS and on, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. You must add these sources:
- For Ubuntu 10.04 LTS (Lucid Lynx):
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
- For Ubuntu 10.10 (Maverick Meerkat):
sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
- For Ubuntu 11.04 (Natty Narwhal):
Some distros have the command "add-apt-repository" removed. If this is the case, you will need to add the python properties by running the following command:
sudo apt-get install python-software-properties
Then you can proceed to add the source:
sudo add-apt-repository "deb http://archive.canonical.com/ubuntu natty partner"
- For Ubuntu 11.10 (Oneiric Ocelot):
sudo add-apt-repository ppa:ferramroberto/java
- Then install the packages:
sudo apt-get update
sudo apt-get install sun-java6-jre
sudo update-alternatives --config java
openSUSE
Use zypper in java-1_6_0-sun
Arch Linux
Open a terminal and run pacman -Syu openjdk6 as root.
Other Distros
Alternatively, you can visit Java's website directly to download the Java package for Linux. Most distros work with this (either 32 or 64-bit). Instructions for the installation of those different packages are given on the site.
If during installation, it asks for a password, enter your password. If you get asked "Is this OK [Y/N]" Enter Y and press enter if required. Java should now be installed.
Start the Minecraft server
Open the terminal again Applications > Accessories > Terminal
Enter the following commands:
cd 'minecraft_server'
change minecraft_server to the same name of the folder you extracted the server to
java -Xms1024M -Xmx1024M -jar minecraft_server.jar nogui
Less than 1GB free RAM
If you have less than 1024MB RAM, the above line may cause problems with swapping and out of memory conditions, which makes the game hard to play
cd 'minecraft_server'
java-Xms1024M-Xmx1024M-jar minecraft_server.jar nogui
Measure your current free RAM:
free -m
It may look like this: File:ram left.png You are interested in the last number in the third line, 2163 in this case
free-m
Subtract some RAM as safety
On this computer, the server may use up to 1536 MB RAM
Now, replace the 1024 in the above example with the calculated number:
java -Xms1536M -Xmx1536M -jar minecraft_server.jar nogui
if minecraft_server.exe is being used you use:
java -Xms1536M -Xmx1536M -jar minecraft_server.exe nogui
Voila, it should run smoothly now
Tip: If you want to spare more memory, you may set the -Xms parameter even lower, say:
java -Xms32M -Xmx512M -jar minecraft_server.jar nogui
The parameter controls how much memory is reserved on startup
Your server will start with 32MB RAM and whenever it needs more memory it will allocate some until it reaches the maximum of 512 MB
However, this will result in a little slowdown whenever the allocation is done.
Startup and maintenance script
Alternatively you can automate the startup of the Minecraft server.
Server startup script
M3tal_Warrior Server Startup Script
Configure and connect
Now it is time to configure and connect.
Configuring the Minecraft Server
- Configure the server by editing the server.properties file, the format for which is explained here. Be certain to edit the file with a text editor that does not add formatting (e.g., for italics). Additional configuration may not be necessary as many servers run fine from the default values.
- Add your username to the admin.txt and/or ops.txt (newer Minecraft versions may not have an admin.txt file).
- Ops.txt and admin.txt determine who may execute server commands. In other words, operator ("op") privileges allow you to control certain aspects of the game (e.g., teleporting players).
- Op privileges may also be granted from the server GUI: type "op <username>" and it will automatically add <username> to the ops.txt file.
Connect to the Minecraft Server
- If you are playing on the same machine on which the server is running, select the "Multiplayer" option in the game client and type in "localhost" instead of an IP address.
- This is not recommended unless you have a powerful computer, with more than 4 gigabytes of ram (.5 for the server, 1 for the client, and remainder for system).
- Users within your network can connect with your internal IP address. (You do not need to port forward for connections that are within your local network.)
- People connecting from the Internet (i.e., outside of your local network) must connect using your external IP address. You must port forward for someone outside your network to connect to the server.
IP address notes
- Unless you set a static IP for the computer that is hosting the game, the internal IP address can change. This affects port forwarding rules, and can make them invalid. Each modem or router has a different way of setting a static IP address. You should refer to the manual for your device(s) or online documentation for further instruction.
- If you are having players connect to your external IP, your external IP can change if you do not have a static IP from your internet service provider. Use a tool such as MyWANIP to periodically check on the external IP address. You may also search "my ip address" on Google and it will show your IP address. Alternatively, you can look into a DNS service that will allow you to have a name, rather than an IP address, that will remain the same. The name will point to your external IP address, regardless of whether or not it changes (the DNS is updated when changes occur).
Firewalling, NATs and external IP addresses
- You must open the TCP port (default is 25565) on the firewall.
- If the server in question is not reachable via a globally routable IP address, you will need to add appropriate address and/or port number translation rules to the gateway — usually your router has the global IP address.
- For help with address translation, opening the firewall and routing (these three make up what people call port mapping/forwarding), portforward.com is a good source. Select your router from that list, skip the ad that comes after selecting the device, and you will see instructions for setting up port forwarding. Alternatively, you can read the documentation supplied with your router, modem, or other ISP related hardware.
- Verify the port is open, and note your external IP by using a port checker tool, such as You Get Signal. The default port you should test is 25565, unless you specified something else. Have the Minecraft server running when you test the port.
- You can obtain your external IP address from YouGetSignal.
Local Network Dedicated Servers
This only applies to Classic (v0.30) servers.
A common problem for server administrators is the inability to connect to your own server via another machine on your local network. A typical scenario for this is that you have a Classic server running on a dedicated machine, and you have your own machine which you play on. They're both connected to the same router/switch, and have internal IP's with the octets '192.168.x.x'. Normally, connecting via the URL generated for your server will result in an error message claiming that the server is offline.
To correct this, you must add a function to the end of your URL, bookmarks, or whatever else you connect by. The function is: ?override=true
Example: http://www.minecraft.net/classic/play/4c3bebb1a01816acbe31c5ece1570da5?override=true
Previously, (before the 1.8 beta and website update) this was &override=true. This caused much confusion since the change was not announced by Mojang, and wasn't announced on the website applet pages either. Before the update, connecting to your own URL via the website resulted in red text under the applet window saying "If you can't connect, try this link instead." The link returned the same thing, with the &override=true affixed to the end.
Note: This situation does not effect Beta servers, and you should be able to connect via an internal or external IP.
Setting Up a VPN (Hamachi)
An easy way to set up a server between you and your friends is to set up a VPN (virtual private network). A free software utility that can be used to set this up is Hamachi by LogMeIn. Don't use this for public servers. Many users will not take the extra time to install the client and such.
Advantage of doing this saves you configuring ports on your router and if you have a dynamic IP address using Hamachi will provide you with a static IP.
- Install software on you and your friend's computers https://secure.logmein.com/products/hamachi2/ or https://secure.logmein.com/US/labs/?wt.ac=73-516-440 for Linux (32-bit and 64-bit .deb and .rpm packages are available, you can install it on Gentoo by emerging "net-misc/logmein-hamachi")
- One person sign up for admin via logmein website
- Create new network
- Pass these details onto every person concerned and get them to login
- One person set up a server.
- Everyone else connect via their Hamachi ip address and use port number 25565 (default)
- Operating system
- What you were trying to do
- What you did so far
- Any errors you encountered
- Screenshots of the problem (if possible)
FAQ (Frequently Asked Questions)
Q: When I try to connect to my server this is what it says:
Connection lost
The server responded with an invalid server key
A: Wait a minute then try again. It should work, but if it doesn't connect within a few tries, you have a problem. Update the server to 1.0.1 (aka 1.1) (this should fix it)
Q: On a Windows computer, when I double click the batch file it opens a command prompt window, but quickly disappears and the server does not start. What should I do?
A: This is probably due to an incorrect path for javaw.exe. You may just need to change /jre7/ to /jre6/ . Or search your system for javaw.exe and adjust the path accordingly. (It's probably under c:\program files or c:\program files (x86).) Also, you must have the offline version of Java installed--not just the Java plug-in for your browser.
Q:whenever i try to get the server up, it says "Failed to Bind to Port."
A: This usually means that Port Forwarding/Triggering is not configured correctly on your router. Check your routers manual and make sure the port for Minecraft (Default is 25565) is forwarded to the internal IP address of your server. If your server is not behind a router then check with your ISP to see if that port is available for use and if not try a different port by changing it in your server.properties file in this line: server-port=25565.
Note: You should not use the following ports for your server as most ISP's block these ports for security reasons:
- 21 (Used by most FTP Servers)
- 22 (Used by Secure Shell daemon)
- 25 (Used by Mail Servers for SMTP)
- 53 (Used by DNS Servers)
- 80 (Used by most Web Servers)
- 110 (Used by most Mail Servers for POP3)
- 115 (Used by FTP Servers for SSL)
- 143 (Used by Mail Servers for IMAP)
- 443 (SSL port for Web Servers)
- 3306 (Used by most MySQL Servers)
Generally avoid any port below number 1024, since those ports are generally referred as well-known ports and are registered with the IANA for important services.
Q: I tried to run the server with Solaris/OpenSolaris and got the following error:
java.io.InterruptedIOException: Operation interrupted at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:129) at java.net.SocketInputStream.read(SocketInputStream.java:182) at java.io.FilterInputStream.read(FilterInputStream.java:66) at gq.a(SourceFile:131) at ji.g(SourceFile:197) at ji.c(SourceFile:17) at oq.run(SourceFile:84) 2011-05-31 16:57:26 [INFO] /:44673 lost connection
A: For whatever reason, out of all of the operating systems, only Solaris throws that exception when a thread interrupts a connection. A workaround is to change the default behaviour on the command line:
java -Xmx1024M -Xms32M -XX:-UseVMInterruptibleIO -XX:+UseConcMarkSweepGC \ -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts\ -jar minecraft.jar nogui
This instructs Java to use an interruptible IO stack instead of the default IO that is sensitive to interrupted threads.
Q: I cannot break/place any blocks!?
A: Walk away from your spawn area. You cannot break or place blocks near spawn (unless you are operator on the server).
Other Tutorials
Here are some other tutorials on how to set up a Minecraft server.
- Mac OS
- Linux
- Windows
- Others