{"id":33,"date":"2022-11-28T22:02:51","date_gmt":"2022-11-28T14:02:51","guid":{"rendered":"https:\/\/panxiaoyi.ml\/?p=33"},"modified":"2022-11-29T19:47:25","modified_gmt":"2022-11-29T11:47:25","slug":"mc","status":"publish","type":"post","link":"https:\/\/panxiaoyi.top\/index.php\/2022\/11\/28\/mc\/","title":{"rendered":"MC\u670d\u52a1\u5668\u642d\u5efa\u6559\u7a0b"},"content":{"rendered":"\n<p>\u9996\u5148\u662f\u767b\u9646\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u4e91\u670d\u52a1\u63d0\u4f9b\u5546\u63a7\u5236\u53f0\u5185\u7684\u7ec8\u7aef\uff0c\u6216\u8005\u901a\u8fc7SSH\u8fde\u63a5\u5230\u4e91\u670d\u52a1\u5668\u3002\u8fd9\u4e9b\u5728\u591a\u5904\u5747\u6709\u8be6\u7ec6\u6559\u7a0b\uff0c\u5728\u6b64\u4e0d\u505a\u8d58\u8ff0\u3002<\/p>\n\n\n\n<p>\u6211\u79df\u8d41\u7684\u670d\u52a1\u5668\u7cfb\u7edf\u4e3aubuntu server 20.04\uff0c\u64cd\u4f5c\u4e0a\u548c\u5e38\u89c4\u7684linux\u5927\u540c\u5c0f\u5f02\u3002<\/p>\n\n\n\n<p>\u767b\u9646\u670d\u52a1\u5668\u540e\uff0c\u9700\u8981\u5148\u4e0b\u8f7dMC\u6240\u9700\u8981\u7684java\u8fd0\u884c\u73af\u5883\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u5982\u4e0b\u4ee3\u7801\u5373\u53ef\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-sitebg-background-color has-text-color has-background\"><code>sudo apt install openjdk-8-jre-headless<\/code><\/pre>\n\n\n\n<p>\u8fd0\u884c\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u65b0\u5efa\u4e00\u4e2a\u7528\u6237\uff0c\u547d\u540d\u4e3aminecraft\uff0c\u907f\u514dMC\u670d\u52a1\u5668\u76f4\u63a5\u8fd0\u884c\u5728root\u8d26\u6237\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> sudo useradd -r -m -U -d \/opt\/minecraft -s \/bin\/bash minecraft<\/code><\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u9700\u8981\u5b89\u88c5\u83b7\u53d6mcrcon\u6240\u9700\u7684git\u8f6f\u4ef6\u5305\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> sudo apt-get install git build-essential<\/code><\/pre>\n\n\n\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5207\u6362\u5230minecraft\u8d26\u6237\uff0c\u521b\u5efa\u6e38\u620f\u76ee\u5f55\uff0c\u5e76\u901a\u8fc7git\u6307\u4ee4\u83b7\u53d6github\u4e0a\u7684mcrcon\u5de5\u5177\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> sudo su minecraft\n mkdir -p ~\/{backups,tools,server}<\/code><\/pre>\n\n\n\n<p class=\"has-extra-small-font-size\" style=\"line-height:1\">\u00b7backups\u7528\u4e8e\u5b58\u653e\u5907\u4efd<\/p>\n\n\n\n<p class=\"has-extra-small-font-size\" style=\"line-height:1\">\u00b7tools\u7528\u4e8e\u5b58\u653emcrcon\u7ba1\u7406\u5de5\u5177<\/p>\n\n\n\n<p class=\"has-extra-small-font-size\" style=\"line-height:1\">\u00b7server\u5219\u4e3a\u670d\u52a1\u5668\u8fd0\u884c\u76ee\u5f55<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-white-color\"> <\/mark>cd ~\/tools &amp;&amp; git clone https:\/\/github.com\/Tiiffi\/mcrcon.git\n cd ~\/tools\/mcrcon\n gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c<\/code><\/pre>\n\n\n\n<p>\u8be5\u6b65\u9aa4\u5b8c\u6210\u540e\uff0c\u5373\u4e0b\u8f7d\u5e76\u7f16\u8bd1\u4e86mcrcon\uff0c\u82e5\u4e0d\u653e\u5fc3\u53ef\u4ee5\u7528\u5982\u4e0b\u4ee3\u7801\u6d4b\u8bd5\u7f16\u8bd1\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> .\/mcrcon -h<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u7f16\u8bd1\u6210\u529f\uff0c\u5e94\u8be5\u4f1a\u8fd4\u56de\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>Usage: mcrcon &#91;OPTIONS] &#91;COMMANDS]\n\nSend rcon commands to Minecraft server.\n\nOptions:\n  -H\t\tServer address (default: localhost)\n  -P\t\tPort (default: 25575)\n  -p\t\tRcon password\n  -t\t\tTerminal mode\n  -s\t\tSilent mode\n  -c\t\tDisable colors\n  -r\t\tOutput raw packets\n  -w\t\tWait for specified duration (seconds) between each command (1 - 600s)\n  -h\t\tPrint usage\n  -v\t\tVersion information\n\nServer address, port and password can be set with following environment variables:\n  MCRCON_HOST\n  MCRCON_PORT\n  MCRCON_PASS\n\n- mcrcon will start in terminal mode if no commands are given\n- Command-line options will override environment variables\n- Rcon commands with spaces must be enclosed in quotes\n\nExample:\n\tmcrcon -H my.minecraft.server -p password -w 5 \"say Server is restarting!\" save-all stop\n<\/code><\/pre>\n\n\n\n<p>\u7f16\u8bd1\u6210\u529f\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u4e0b\u8f7d\u5e76\u914d\u7f6eMC\u670d\u52a1\u5668\u4e86\uff0c\u672c\u4eba\u4e0b\u8f7d\u7684MC\u670d\u52a1\u5668\u7248\u672c\u4e3a1.16.1\uff0c\u4e0b\u8f7d\u5730\u5740\u4e3a\uff1ahttps:\/\/launcher.mojang.com\/v1\/objects\/a412fd69db1f81db3f511c1463fd304675244077\/server.jar<\/p>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7wget\u6307\u4ee4\u5c06\u5176\u4e0b\u8f7d\u5230\u521a\u521b\u5efa\u7684server\u6587\u4ef6\u5939\u4e2d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> wget https:\/\/launcher.mojang.com\/v1\/objects\/a412fd69db1f81db3f511c1463fd304675244077\/server.jar -P ~\/server<\/code><\/pre>\n\n\n\n<p>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u6253\u5f00server.jar<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> cd ~\/server\n java -jar server.jar nogui<\/code><\/pre>\n\n\n\n<p>\u521d\u6b21\u8fd0\u884c\u65f6\uff0c\u5b83\u5c06\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\u5e76\u521b\u5efaserver.properties\u548ceula.txt\u6587\u4ef6\u540e\u505c\u6b62\u8fd0\u884c\u3002\u6b64\u65f6\u9700\u8981\u6253\u5f00eula.txt\u6587\u4ef6\uff0c\u5e76\u5c06false\u6539\u4e3atrue<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> nano ~\/server\/eula.txt<\/code><\/pre>\n\n\n\n<p>\u66f4\u6539\u5185\u5bb9\u4e3a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> eula=true<\/code><\/pre>\n\n\n\n<p>\u66f4\u6539\u5b8c\u6210\u540e\uff0c\u7ee7\u7eed\u914d\u7f6eserver.properties\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> nano ~\/server\/server.properties<\/code><\/pre>\n\n\n\n<p>\u627e\u5230\u4ee5\u4e0b\u5185\u5bb9\u5e76\u4fee\u6539<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> rcon.password=strong-password  # rcon\u8fde\u63a5\u5bc6\u7801\u81ea\u884c\u66f4\u6539\u8bbe\u7f6e\n enable-rcon=true               # \u5141\u8bb8rcon\u8fde\u63a5\n op-permission-level=4          # op\u64cd\u4f5c\u6743\u9650\u4e3a\u6700\u9ad8\uff0c\u7ea7\u522b\u4e3a1-4\n online-mode=false              # \u4e0d\u9a8c\u8bc1\u8fde\u63a5Minecraft<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\u9700\u8981\u5728\u670d\u52a1\u5668\u4f9b\u5e94\u5546\u7684\u9632\u706b\u5899\u9009\u9879\u4e2d\u5f00\u653e25565\u548c25575\u7aef\u53e3\uff0c\u5426\u5219\u5c06\u65e0\u6cd5\u8fde\u63a5\u5230\u670d\u52a1\u5668\u3002<\/p>\n\n\n\n<p>\u5e76\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>sudo ufw allow 25565\/tcp\nsudo ufw allow 25575\/tcp<\/code><\/pre>\n\n\n\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\u5df2\u7ecf\u505a\u597d\u4e86\u670d\u52a1\u5668\u642d\u5efa\u7684\u524d\u671f\u51c6\u5907\u5de5\u4f5c\uff0c\u63a5\u4e0b\u6765\u5373\u53ef\u542f\u52a8\u670d\u52a1\u5668\u3002<\/p>\n\n\n\n<p>\u521b\u5efasystemd\u670d\u52a1\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>sudo su    \nsudo nano \/etc\/systemd\/system\/minecraft.service<\/code><\/pre>\n\n\n\n<p>\u7c98\u8d34\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>&#91;Unit]\nDescription=Minecraft Server\nAfter=network.target\n\n&#91;Service]\nUser=minecraft\nNice=1\nKillMode=none\nSuccessExitStatus=0 1\nProtectHome=true\nProtectSystem=full\nPrivateDevices=true\nNoNewPrivileges=true\nWorkingDirectory=\/opt\/minecraft\/server\nExecStart=\/usr\/bin\/java -Xmx3072M -Xms1024M -jar server.jar nogui\nExecStop=\/opt\/minecraft\/tools\/mcrcon\/mcrcon -H 127.0.0.1 -P 25575 -p strong-password stop\n\n&#91;Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d3072M\u548c1024M\u5206\u522b\u4ee3\u8868MC\u670d\u52a1\u5668\u6700\u5927\u548c\u6700\u5c0f\u5360\u7528\u5185\u5b58\uff0c\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u670d\u52a1\u5668\u914d\u7f6e\u66f4\u6539\uff0cstrong-password\u5219\u9700\u8981\u6539\u4e3a\u4e4b\u524dserver.properties\u4e2d\u81ea\u5df1\u4fee\u6539\u7684\u5bc6\u7801\u3002<\/p>\n\n\n\n<p>\u91cd\u65b0\u52a0\u8f7dsystemed\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>sudo systemctl daemon-reload<\/code><\/pre>\n\n\n\n<p>\u542f\u52a8MC\u670d\u52a1\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>sudo systemctl start minecraft<\/code><\/pre>\n\n\n\n<p>\u67e5\u770bMC\u670d\u52a1\u5668\u72b6\u6001\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>sudo systemctl status minecraft<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u6b63\u786e\u8fd0\u884c\uff0c\u5e94\u6709\u5982\u4e0b\u8fd4\u56de\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>\u25cf minecraft.service - Minecraft Server\n     Loaded: loaded (\/etc\/systemd\/system\/minecraft.service; disabled; vendor preset: enabled)\n     Active: active (running) since Tue 2021-12-07 17:54:58 CST; 2h 12min ago\n   Main PID: 31521 (java)\n      Tasks: 22 (limit: 4612)\n     Memory: 1.3G\n     CGroup: \/system.slice\/minecraft.service\n             \u2514\u250031521 \/usr\/bin\/java -Xmx3072M -Xms1024M -jar server.jar nogui<\/code><\/pre>\n\n\n\n<p>\u8bbe\u7f6eMC\u670d\u52a1\u5668\u81ea\u542f\u52a8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>sudo systemctl enable minecraft<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u9700\u8981\u5173\u95edMC\u670d\u52a1\u5668\uff0c\u5219\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6307\u4ee4\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>sudo systemctl stop minecraft<\/code><\/pre>\n\n\n\n<p>\u540c\u65f6\u4e3a\u4e86\u670d\u52a1\u5668\u5b89\u5168\uff0c\u9632\u6b62\u88ab\u4eba\u70b8\u670d\uff0c\u5907\u4efd\u529f\u80fd\u5fc5\u4e0d\u53ef\u5c11\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>sudo su minecraft\nnano ~\/tools\/backup.sh<\/code><\/pre>\n\n\n\n<p>\u7c98\u8d34\u4ee5\u4e0b\u5185\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>#!\/bin\/bash\n\nfunction rcon {\n  \/opt\/minecraft\/tools\/mcrcon\/mcrcon -H 127.0.0.1 -P 25575 -p strong-password \"$1\"\n}\n\nrcon \"save-off\"\nrcon \"save-all\"\ntar -cvpzf \/opt\/minecraft\/backups\/server-$(date +%F_%R).tar.gz \/opt\/minecraft\/server\nrcon \"save-on\"\n\n## Delete older backups\n find \/opt\/minecraft\/backups\/ -type f -mtime +7 -name '*.gz' -delete<\/code><\/pre>\n\n\n\n<p>\u8d4b\u4e88\u6267\u884c\u6743\u9650<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>chmod +x \/opt\/minecraft\/tools\/backup.sh<\/code><\/pre>\n\n\n\n<p>\u521b\u5efacron\u4f5c\u4e1a\uff0c\u6bcf\u592923:00\u5907\u4efd<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>crontab -e<\/code><\/pre>\n\n\n\n<p>\u5728\u6253\u5f00\u7684\u6587\u6863\u7ed3\u5c3e\u5904\u7c98\u8d34\u5982\u4e0b\u5185\u5bb9\u540e\u4fdd\u5b58<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code>0 23 * * * \/opt\/minecraft\/tools\/backup.sh<\/code><\/pre>\n\n\n\n<p>\u5982\u4e0a\u8bbe\u7f6e\u5b8c\u6210\u540e\uff0cMC\u670d\u52a1\u5668\u5c31\u4f1a\u5728\u6bcf\u592923:00\u81ea\u52a8\u5907\u4efd\uff0c\u540c\u65f6\u5220\u9664\u4e00\u5468\u524d\u7684\u5907\u4efd\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">\u6d4b\u8bd5MC\u8fde\u63a5<\/p>\n\n\n\n<p>\u542f\u52a8MC\u5ba2\u6237\u7aef\uff0c\u5728\u591a\u4eba\u6e38\u620f\u4e2d\u9009\u62e9\u6dfb\u52a0\u670d\u52a1\u5668\uff0c\u5728\u670d\u52a1\u5668\u5730\u5740\u680f\u5185\u8f93\u5165\u670d\u52a1\u5668IP\u53ca\u7aef\u53e3\uff0c\u683c\u5f0f\u4e3aXXX.XXX.XXX.XXX:25565\uff0c\u7136\u540e\u6dfb\u52a0\u670d\u52a1\u5668\uff0c\u5982\u679c\u80fd\u591f\u6210\u529f\u8fde\u63a5\u5c31\u8bf4\u660e\u670d\u52a1\u5668\u642d\u5efa\u6210\u529f\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">\u6253\u5f00\u670d\u52a1\u5668\u63a7\u5236\u53f0<\/p>\n\n\n\n<pre class=\"wp-block-code has-headings-color has-text-color\"><code> ~\/tools\/mcrcon\/mcrcon -H 127.0.0.1 -P 25575 -p strong-password -t<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2dstrong-password\u9700\u8981\u6539\u4e3a\u4e0a\u6587\u5728server.properties\u4e2d\u4fee\u6539\u7684\u5bc6\u7801\u3002<\/p>\n\n\n\n<p>\u56de\u8f66\u540e\u5373\u53ef\u4ee5\u8fdb\u5165MC\u670d\u52a1\u5668\u7684\u63a7\u5236\u53f0\uff0c\u8fd9\u4e0e\u4e2a\u4eba\u6a21\u5f0f\u4e0b\u7684\u63a7\u5236\u53f0\u5927\u540c\u5c0f\u5f02\uff0c\u591a\u4e86\u4e00\u4e9b\u8bf8\u5982op\u3001save\u8fd9\u7c7b\u670d\u52a1\u5668\u6307\u4ee4\uff0c\u8be6\u60c5\u53ef\u4ee5\u53c2\u770b<a rel=\"noreferrer noopener\" href=\"https:\/\/minecraft.fandom.com\/wiki\" target=\"_blank\">MC wiki<\/a><\/p>\n\n\n\n<p>\u4e0a\u8ff0\u5c31\u662f\u6211\u4e2a\u4eba\u5b66\u4e60\u5230\u7684ubuntu\u4e0b\u642d\u5efaMC\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u5e0c\u671b\u80fd\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u662f\u767b\u9646\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u4e91\u670d\u52a1\u63d0\u4f9b\u5546\u63a7\u5236\u53f0\u5185\u7684\u7ec8\u7aef\uff0c\u6216\u8005\u901a\u8fc7SS &hellip;<\/p>\n","protected":false},"author":1,"featured_media":46,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,9],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-daily","category-technical"],"_links":{"self":[{"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":2,"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":36,"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions\/36"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/media\/46"}],"wp:attachment":[{"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/panxiaoyi.top\/index.php\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}