搭建本地服务器
下载对应版本jar包
根据自己MC版本,在mcversions.net网站下载对应的jar包
这里从左到右分别是稳定版,快照版,贝塔版和阿尔法版,这里下载最左边稳定版的jar包,我是1.19.3版本的,所以这里直接下载1.19.3的Server包。
上传jar包到本地Linux
使用xshell连接Linux
[D:\~]$ ssh root@192.168.98.130
Connecting to 192.168.98.130:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Wed Feb 22 22:54:22 2023 from 192.168.98.1
[root@KATANA ~]#
使用rz命令上传Windows本机文件
安装Java环境
因为是Java版游戏,所以需要安装Java环境
[root@KATANA ~]# yum install java-17-openjdk.x86_64 -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:1:14:59 前,执行于 2023年02月22日 星期三 23时04分14秒。
Package java-17-openjdk-1:17.0.1.0.12-2.el8_5.x86_64 is already installed.
依赖关系解决。
无需任何处理。
完毕!
[root@KATANA ~]#
这边因为我以前安装过了,所以没有下载安装过程
创建安装目录
创建本地安装目录
[root@KATANA ~]# mkdir /opt/minecraft/instances/ -p
[root@KATANA ~]# mkdir /opt/minecraft/jars
[root@KATANA ~]# mkdir /opt/minecraft/instances/survival/
[root@KATANA ~]#
将下好的服务jar包移动到/opt/minecraft/jars目录下
[root@KATANA ~]# mv s
server.jar shell_code/
[root@KATANA ~]# mv server.jar /opt/minecraft/jars/
创建库文件
在/lib/systemd/system/下创建minecraft-survival.service
[root@KATANA ~]# vim /lib/systemd/system/minecraft-survival.service
将下面代码粘贴进minecraft-survival.service文件
[Unit]
Description=Minecraft Server
Wants=network.target
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/minecraft/instances/survival
ExecStart=/usr/bin/java -Xms2G -Xmx4G -jar /opt/minecraft/jars/server.jar nogui
RestartSec=10
Restart=on-failure
KillMode=process
KillSignal=SIGINT
SuccessExitStatus=130
StandardInput=null
[Install]
WantedBy=default.taget
保存并推出(vim编辑文件后按esc进入正常模式后,按:进入底行模式,输入:wq保存并退出)
创建最终用户许可协议
[root@KATANA ~]# echo "eula=true" > /opt/minecraft/instances/survival/eula.txt
启动服务
启动minecraft-survival.service服务
[root@KATANA ~]# systemctl start minecraft-survival.service
[root@KATANA ~]# systemctl status minecraft-survival.service
● minecraft-survival.service - Minecraft Server
Loaded: loaded (/usr/lib/systemd/system/minecraft-survival.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2023-02-23 00:52:46 CST; 3s ago
Main PID: 10798 (java)
Tasks: 28 (limit: 23862)
Memory: 433.7M
CGroup: /system.slice/minecraft-survival.service
└─10798 /usr/bin/java -Xms2G -Xmx4G -jar /opt/minecraft/jars/server.jar nogui
2月 23 00:52:46 KATANA systemd[1]: Started Minecraft Server.
2月 23 00:52:47 KATANA java[10798]: Starting net.minecraft.server.Main
2月 23 00:52:50 KATANA java[10798]: [00:52:50] [ServerMain/INFO]: Building unoptimized datafixer
测试本地服务
使用本机Java版我的世界,连接linux服务器
选择,添加服务器,名称随便起,地址为linux的ip地址(注意关闭linux和Windows防火墙)
可以连接进入游戏,测试成功
检测实时日志
[root@KATANA ~]# journalctl -f
-- Logs begin at Wed 2023-02-22 22:16:46 CST. --
2月 23 01:01:43 KATANA NetworkManager[967]: <info> [1677085303.9413] dhcp4 (ens160): nameserver '192.168.98.2'
2月 23 01:01:43 KATANA NetworkManager[967]: <info> [1677085303.9413] dhcp4 (ens160): domain name 'localdomain'
2月 23 01:01:43 KATANA NetworkManager[967]: <info> [1677085303.9413] dhcp4 (ens160): gateway 192.168.98.2
2月 23 01:01:43 KATANA NetworkManager[967]: <info> [1677085303.9416] dhcp4 (ens160): state changed bound -> bound
2月 23 01:01:43 KATANA dbus-daemon[966]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.11' (uid=0 pid=967 comm="/usr/sbin/NetworkManager --no-daemon " label="system_u:system_r:NetworkManager_t:s0")
2月 23 01:01:43 KATANA systemd[1]: Starting Network Manager Script Dispatcher Service...
2月 23 01:01:43 KATANA dbus-daemon[966]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
2月 23 01:01:43 KATANA systemd[1]: Started Network Manager Script Dispatcher Service.
2月 23 01:01:43 KATANA nm-dispatcher[10986]: req:1 'dhcp4-change' [ens160]: new request (5 scripts)
2月 23 01:01:43 KATANA nm-dispatcher[10986]: req:1 'dhcp4-change' [ens160]: start running ordered scripts...
2月 23 01:02:48 KATANA java[10798]: [01:02:48] [Server thread/INFO]: KATANA2333 lost connection: Disconnected
2月 23 01:02:48 KATANA java[10798]: [01:02:48] [Server thread/INFO]: KATANA2333 left the game
2月 23 01:02:51 KATANA java[10798]: [01:02:51] [User Authenticator #2/INFO]: UUID of player KATANA2333 is 71d48eb3-f860-4e7b-b2eb-32adb635baac
2月 23 01:02:51 KATANA java[10798]: [01:02:51] [Server thread/INFO]: KATANA2333[/192.168.98.1:54450] logged in with entity id 800 at (-18.412531135228814, 63.0, -111.69999998807907)
2月 23 01:02:51 KATANA java[10798]: [01:02:51] [Server thread/INFO]: KATANA2333 joined the game
内网穿透
利用内网穿透,将内网服务映射到公网中去,实现远程联机,这里内网穿透利用花生壳软件
下载安装linux花生壳
在花生壳官网hsk.oray.com/download下载对应平台的安装包
下载好后同上面上传jar包,将rpm安装包上传到linux上
安装linux端花生壳
安装花生壳
[root@KATANA ~]# rpm -ivh phddns_5.2.0_amd64.rpm
Verifying... ################################# [100%]
准备中... ################################# [100%]
软件包 phddns-5.2.0-1.amd64 已经安装
[root@KATANA ~]#
启动花生壳服务
[root@KATANA ~]# systemctl start phddns_mini_httpd.service
[root@KATANA ~]# systemctl status ph
phddns_mini_httpd.service php-fpm.service phtunnel.service
[root@KATANA ~]# systemctl status phddns_mini_httpd.service
● phddns_mini_httpd.service - phddns mini httpd
Loaded: loaded (/usr/lib/systemd/system/phddns_mini_httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2023-02-23 01:07:41 CST; 13s ago
Main PID: 11102 (phddns_mini_htt)
Tasks: 1 (limit: 23862)
Memory: 652.0K
CGroup: /system.slice/phddns_mini_httpd.service
└─11102 /usr/bin/phddns_mini_httpd -p 11011 -h 127.0.0.1 -d /usr/share/phtunnel/www -c phtunnel_control/* -u root
2月 23 01:07:41 KATANA systemd[1]: Started phddns mini httpd.
2月 23 01:07:41 KATANA phddns_mini_httpd[11102]: started as root without requesting chroot(), warning only
2月 23 01:07:41 KATANA phddns_mini_httpd[11102]: mini_httpd/1.30 26Oct2018 starting on 127.0.0.1, port 11011
2月 23 01:07:41 KATANA phddns_mini_httpd[11102]: /usr/bin/phddns_mini_httpd: started as root without requesting chroot(), warning only
查看花生壳服务状态和SN码
[root@KATANA ~]# phddns status
+--------------------------------------------------+
| Oray PeanutHull Linux 5.2.0 |
+--------------------------------------------------+
| Runstatus: ONLINE |
+--------------------------------------------------+
| SN: 自己的SN码 |
+--------------------------------------------------+
| Remote Management Address http://b.oray.com |
+--------------------------------------------------+
[root@KATANA ~]#
记住自己的SN码
映射内网
在花生壳console.hsk.oray.com/passport/login 选择地下SN登录
账号为自己的SN码,密码默认是admin,登陆后选择新建映射
映射类型选择TCP,外网域名花生壳可以免费注册,内网主机填写自己linux的ip,MC服务内网端口默认25565
最后确定启动映射
进行诊断测试
记下外网IP地址和映射外网的端口
如果这里域名IP与转发服务器IP不一致,需要刷新本机DNS
Windos下按win+r 输入cmd打开命令终端,输入
ipconfig /flushdns
公网联机测试
添加服务器,名称随便填,服务器地址填写外网地址后面用:接端口号
加入游戏
查看日志
测试成功
和小伙伴们联机,只需要在他们游戏里添加服务器,IP填写你外网IP加端口号就可以一起远程游玩了。