ひとり勉強ログ

ITエンジニアの勉強したことメモ

CentOS7.1にマインクラフトのマルチサーバーをインストールする方法

OS:CentOS Linux release 7.3.1611 (Core)

※OSのバージョンを確認する方法。 [bash] [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [/bash]

javaのインストール

まずroot権限になっておき、【java】のインストール。 [bash] [root@localhost ~]# yum -y install java [/bash]

「-y」は問い合わせがあった際にすべて「y」と答えるという意味。

マインクラフトのインストールにはjavaのバージョンが1.6以上であることが必要なので、バージョンをチェック。

[bash] [root@localhost ~]# java -version java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode) [/bash]

screenのインストール

サーバーをバックグラウンドで動作させるために【screen】をインストール。 [bash] [root@localhost ~]# yum -y install screen [/bash]

wgetのインストール

ファイルをダウンロードするためのコマンド【wget】が利用可能にする。 [bash] [root@localhost ~]# yum -y install wget [/bash]

マインクラフトサーバー専用のユーザを作成

まず「minecraft」というユーザを作成。 [bash] [root@localhost ~]# adduser minecraft [/bash]

パスワードが設定されていないので、設定し。 [bash] [root@localhost ~]# passwd minecraft ユーザ 「minecraft」 のパスワードを変更。 新しいパスワード: [ここに設定したいパスワードを入力] 新しいパスワードを再入力してください: [上記で入力したパスワードを再度入力] passwd: すべての認証トークンが正しく更新できました。 [/bash]

マインクラフトのサーバーのダウンロード

まずはディレクトリを作成。 オプション「-p」は指定したディレクトリをサブディレクトリ含め作成するという意味。 [bash] [root@localhost games]# mkdir -p /usr/local/games/minecraft [/bash]

ディレクトリが作成されたか確認。 [bash] [root@localhost games]# ls /usr/local/games/ minecraft [/bash]

minecraft」というディレクトリが作成されている。 次にディレクトリの権限を変更。 [bash] [root@localhost games]# chown minecraft:minecraft /usr/local/games/minecraft/ [/bash] 「 /usr/local/games/minecraft/ 」ディレクトリの所有者を「minecraft」に、グループを 「minecraft」に変更するという意味。

マインクラフトサーバーのダウンロード

まず「minecraft」ユーザにログイン。

[bash] [root@localhost games]# su - minecraft [/bash]

上記で作成したマインクラフト用のディレクトリに移動

[bash] [minecraft@localhost ~]$ cd /usr/local/games/minecraft/ [/bash]

Minecraft WIKI から起動スクリプトをダウンロード

[bash] [minecraft@localhost ~]$ wget -O minecraft "http://minecraft.gamepedia.com/Tutorials/Server_startup_script/Script?action=raw" [/bash]

minecraft」ファイル内のパスを編集

minecraftディレクトリにある「minecraft」ファイル内のパスを編集。

[bash] [minecraft@localhost minecraft]$ vi minecraft [/bash]

開いたら「i」で「編集モード」に。 パスの記載がある以下の部分を修正

修正前 [bash] MCPATH='/home/minecraft/minecraft' [/bash]

修正後 [bash] MCPATH='/home/local/games/minecraft' [/bash]

編集を終えたら「Esc」キーで編集モードを抜けて、 [bash] :wq [/bash] で保存して終了。 これでviの画面から通常のコマンド画面に戻る。

minecraft」ファイルに実行権限を付与

[bash] [minecraft@localhost minecraft]$ chmod +x minecraft [/bash]

root権限に戻る

minecraft」ユーザから「root」権限に戻る。

[bash] [minecraft@localhost minecraft]$ exit ログアウト [root@localhost ~]# [/bash]

「/etc/init.d」ディレクトリに移動する

[bash] [root@localhost ~]# cd /etc/init.d [/bash]

シンボリックリンクのを作成

[bash] [root@localhost init.d]# ln -s /usr/local/minecraft/minecraft /etc/init.d/ [/bash]

これで起動スクリプトの準備は終了。

マインクラフトサーバーを立てる

minecraft」ユーザにログイン。

[bash] [root@localhost init.d]# su - minecraft 最終ログイン: 2017/01/17 (火) 07:11:25 JST日時 pts/0 [/bash]

minecraftディレクトリに移動

[bash] [minecraft@localhost ~]$ cd /usr/local/games/minecraft/ [/bash]

jarのダウンロード

Minecraftの公式サイトからjarファイルを「wget」コマンドでダウンロード。 [bash] [minecraft@localhost minecraft]$ wget https://s3.amazonaws.com/Minecraft.Download/versions/1.11.2/minecraft_server.1.11.2.jar --2017-01-17 07:32:11-- https://s3.amazonaws.com/Minecraft.Download/versions/1.11.2/minecraft_server.1.11.2.jar s3.amazonaws.com (s3.amazonaws.com) をDNSに問いあわせています... 54.231.115.2 s3.amazonaws.com (s3.amazonaws.com)|54.231.115.2|:443 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 200 OK 長さ: 9720835 (9.3M) [application/octet-stream] `minecraft_server.1.11.2.jar' に保存中

100%[======================================>] 9,720,835 2.11MB/s 時間 7.4s

2017-01-17 07:32:19 (1.26 MB/s) - `minecraft_server.1.11.2.jar' へ保存完了 [9720835/9720835] [/bash] ※2017年1月17日現在では上記バージョン。  ディレクトリ名及びファイル名の「1.11.2」を他のバージョンに変えればそのバージョンのファイルをダウンロードすることが可能。

minecraft」を起動

サーバを起動してみる。

[bash] [root@localhost minecraft]# /etc/init.d/minecraft start Starting minecraft_server.1.8.8.jar... [/bash]

数秒後以下のように表示される。 [bash] Error! Could not start minecraft_server.1.8.8.jar! [/bash]

eula.txt」ファイルを編集

eula.txt」ファイルを開き、 [bash] [minecraft@localhost ~]$ vi /usr/local/minecraft/eula.txt [/bash]

eula=false」とあるところを下記のように書き換える。 「i」キーで編集モードになり、下記のように修正。

変更前 [bash] eula=false [/bash]

変更後 [bash] eula=true [/bash] 変更後は「Esc」キーで編集モードを抜け、「:wq」で保存して終了。

「exit」コマンドで「minecraft」ユーザからログアウト、「root」に戻る。

minecraftを起動

[bash] [root@localhost minecraft]# /etc/init.d/minecraft start Starting minecraft_server.1.8.8.jar... [/bash]

数秒後以下のように表示されればOK。 [bash] minecraft_server.1.8.8.jar is now running. [/bash]

minecraft」を停止

[bash] [root@localhost minecraft]# /etc/init.d/minecraft stop Stopping minecraft_server.1.8.8.jar minecraft_server.1.8.8.jar is stopped. [/bash]

firewalldの設定

Minecraft用の「25565」番ポートの開放

下記コマンドでマインクラフトサーバーで使用する「25565」番ポートでの通信を許可する設定をする。

[bash] [root@localhost ~]# firewall-cmd --permanent --add-port=25565/tcp [/bash]

以下のように表示されればOK。 [bash] success [/bash]

firewall設定の反映

[bash] [root@localhost ~]# firewall-cmd --reload [/bash]

以下のように表示されればOK。 [bash] success [/bash]

SELinuxの無効化

「/etc/sysconfig/selinux」ファイルで設定。ファイル編集する前にバックアップをとる。

[bash] [root@localhost ~] # cp -p /etc/sysconfig/selinux /etc/sysconfig/selinux_2017-05-29 [/bash]

ファイルを開いて、 [bash] [root@localhost network-scripts]# vi /etc/sysconfig/selinux [/bash] 6行目あたりを変更。

変更前 [bash] SELINUX=enforcing [/bash]

変更後 [bash] SELINUX=disabled [/bash]

「:wq」コマンドでファイルを保存して閉じる。

サーバーの再起動

サーバーを再起動して動作確認。

[bash] [root@localhost ~] #reboot [/bash]

firewalldの設定内容の確認

下記コマンドを実行して、設定内容を確認。

[bash] [root@localhost ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: em1 sources: services: dhcpv6-client ftp ssh ports: 4000-4005/tcp 25565/tcp protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules: [/bash]

下記3点が確認できればOK。 ・ public (active) ・ interfaces: em1 ・ ports: 25565/tcp

SElinux無効化の確認

[bash] [root@localhost ~]# getenforce [/bash]

以下のように表示されればOK。 [bash] Disabled [/bash]

マインクラフトサーバーへの接続

minecraftを起動

[bash] [root@localhost ~]# /etc/init.d/minecraft start Starting minecraft_server.1.8.8.jar... minecraft_server.1.8.8.jar is now running.

[/bash]

minecraftディレクトリに移動し、起動

[bash] [minecraft@localhost ~]$ cd /usr/local/games/minecraft/ [minecraft@localhost minecraft]$ java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui [09:16:10] [Server thread/INFO]: Starting minecraft server version 1.11.2 [09:16:10] [Server thread/INFO]: Loading properties [09:16:11] [Server thread/INFO]: Default game type: SURVIVAL [09:16:11] [Server thread/INFO]: Generating keypair [09:16:11] [Server thread/INFO]: Starting Minecraft server on *:25565 [09:16:11] [Server thread/INFO]: Using epoll channel type [09:16:11] [Server thread/INFO]: Preparing level "world" [09:16:12] [Server thread/INFO]: Preparing start region for level 0 [09:16:13] [Server thread/INFO]: Preparing spawn area: 2% [09:16:14] [Server thread/INFO]: Preparing spawn area: 40% [09:16:15] [Server thread/INFO]: Done (3.271s)! For help, type "help" or "?" [/bash]

minecraft」ユーザにログイン

[bash] [root@localhost ~]# su - minecraft 最終ログイン: 2017/05/29 (月) 22:03:48 JST日時 pts/4 [/bash]

===========

ダウンロードしたjarファイルをリネーム

[bash] [minecraft@localhost minecraft]$ mv minecraft_server.1.11.2.jar minecraft_server.jar [/bash] ※「mv」の後の「 minecraft_server.1.11.2.jar 」の部分は実際にダウンロードしたファイル名に合わせてください。

minecraft_server.jar」を実行

[bash] [minecraft@localhost minecraft]$ java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui [07:42:31] [Server thread/INFO]: Starting minecraft server version 1.11.2 [07:42:31] [Server thread/INFO]: Loading properties [07:42:31] [Server thread/WARN]: server.properties does not exist [07:42:31] [Server thread/INFO]: Generating new properties file [07:42:31] [Server thread/WARN]: Failed to load eula.txt [07:42:31] [Server thread/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info. [07:42:31] [Server thread/INFO]: Stopping server [07:42:31] [Server Shutdown Thread/INFO]: Stopping server [/bash]

Minecraftサーバーを起動

[bash] [minecraft@localhost minecraft]$ java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui [/bash]

下記のようにダダーッと表示される。 [bash] [07:49:51] [Server thread/INFO]: Starting minecraft server version 1.11.2 [07:49:51] [Server thread/INFO]: Loading properties [07:49:51] [Server thread/INFO]: Default game type: SURVIVAL [07:49:51] [Server thread/INFO]: Generating keypair [07:49:51] [Server thread/INFO]: Starting Minecraft server on *:25565 [07:49:52] [Server thread/INFO]: Using epoll channel type [07:49:52] [Server thread/WARN]: Failed to load user banlist: java.io.FileNotFoundException: banned-players.json (そのようなファイルやディレクトリはありません) at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_111] at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_111] at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_111] at com.google.common.io.Files.newReader(Files.java:86) ~[minecraft_server.jar:?] at mx.g(SourceFile:136) ~[minecraft_server.jar:?] at lg.z(SourceFile:99) [minecraft_server.jar:?] at lg.<init>(SourceFile:25) [minecraft_server.jar:?] at lh.j(SourceFile:186) [minecraft_server.jar:?] at net.minecraft.server.MinecraftServer.run(SourceFile:436) [minecraft_server.jar:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111] [07:49:52] [Server thread/WARN]: Failed to load ip banlist: java.io.FileNotFoundException: banned-ips.json (そのようなファイルやディレクトリはありません) at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_111] at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_111] at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_111] at com.google.common.io.Files.newReader(Files.java:86) ~[minecraft_server.jar:?] at mx.g(SourceFile:136) ~[minecraft_server.jar:?] at lg.y(SourceFile:91) [minecraft_server.jar:?] at lg.<init>(SourceFile:27) [minecraft_server.jar:?] at lh.j(SourceFile:186) [minecraft_server.jar:?] at net.minecraft.server.MinecraftServer.run(SourceFile:436) [minecraft_server.jar:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111] [07:49:52] [Server thread/WARN]: Failed to load operators list: java.io.FileNotFoundException: ops.json (そのようなファイルやディレクトリはあり ません) at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_111] at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_111] at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_111] at com.google.common.io.Files.newReader(Files.java:86) ~[minecraft_server.jar:?] at mx.g(SourceFile:136) ~[minecraft_server.jar:?] at lg.A(SourceFile:107) [minecraft_server.jar:?] at lg.<init>(SourceFile:29) [minecraft_server.jar:?] at lh.j(SourceFile:186) [minecraft_server.jar:?] at net.minecraft.server.MinecraftServer.run(SourceFile:436) [minecraft_server.jar:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111] [07:49:52] [Server thread/WARN]: Failed to load white-list: java.io.FileNotFoundException: whitelist.json (そのようなファイルやディレクトリ はありません) at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_111] at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_111] at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_111] at com.google.common.io.Files.newReader(Files.java:86) ~[minecraft_server.jar:?] at mx.g(SourceFile:136) ~[minecraft_server.jar:?] at lg.C(SourceFile:123) [minecraft_server.jar:?] at lg.<init>(SourceFile:30) [minecraft_server.jar:?] at lh.j(SourceFile:186) [minecraft_server.jar:?] at net.minecraft.server.MinecraftServer.run(SourceFile:436) [minecraft_server.jar:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111] [07:49:52] [Server thread/INFO]: Preparing level "world" [07:49:53] [Server thread/INFO]: Preparing start region for level 0 [07:49:54] [Server thread/INFO]: Preparing spawn area: 5% [07:49:55] [Server thread/INFO]: Preparing spawn area: 7% [07:49:56] [Server thread/INFO]: Preparing spawn area: 9% [07:49:57] [Server thread/INFO]: Preparing spawn area: 10% [07:49:58] [Server thread/INFO]: Preparing spawn area: 13% [07:49:59] [Server thread/INFO]: Preparing spawn area: 17% [07:50:00] [Server thread/INFO]: Preparing spawn area: 20% [07:50:01] [Server thread/INFO]: Preparing spawn area: 23% [07:50:02] [Server thread/INFO]: Preparing spawn area: 26% [07:50:03] [Server thread/INFO]: Preparing spawn area: 30% [07:50:04] [Server thread/INFO]: Preparing spawn area: 33% [07:50:05] [Server thread/INFO]: Preparing spawn area: 35% [07:50:06] [Server thread/INFO]: Preparing spawn area: 38% [07:50:08] [Server thread/INFO]: Preparing spawn area: 42% [07:50:09] [Server thread/INFO]: Preparing spawn area: 46% [07:50:10] [Server thread/INFO]: Preparing spawn area: 51% [07:50:11] [Server thread/INFO]: Preparing spawn area: 55% [07:50:12] [Server thread/INFO]: Preparing spawn area: 60% [07:50:13] [Server thread/INFO]: Preparing spawn area: 64% [07:50:14] [Server thread/INFO]: Preparing spawn area: 69% [07:50:15] [Server thread/INFO]: Preparing spawn area: 74% [07:50:16] [Server thread/INFO]: Preparing spawn area: 79% [07:50:17] [Server thread/INFO]: Preparing spawn area: 85% [07:50:18] [Server thread/INFO]: Preparing spawn area: 90% [07:50:19] [Server thread/INFO]: Preparing spawn area: 96% [07:50:19] [Server thread/INFO]: Done (27.435s)! For help, type "help" or "?" [/bash]

ここで下記のように表示されたら、 [bash] [07:50:22] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2218ms behind, skipping 44 tick(s) [/bash]

一旦「Ctrl+c」で終了し、再度下記の起動コマンドを実行。 [bash] [minecraft@localhost minecraft]$ java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui [/bash]

サーバーを終了する

ここで「Ctrl+c」で一旦サーバーを終了。 [bash] [08:17:50] [Server Shutdown Thread/INFO]: Stopping server [08:17:50] [Server Shutdown Thread/INFO]: Saving players [08:17:50] [Server Shutdown Thread/INFO]: Saving worlds [08:17:50] [Server Shutdown Thread/INFO]: Saving chunks for level 'world'/Overworld [/bash]

ここからはサーバーに接続可能にするための設定を行う。

サーバー時刻同期設定

「ntpupdate」をインストール

時刻同期に必要な「ntpupdate」をインストール。 [bash] [root@localhost ~]# yum -y install ntpdate [/bash]

「ntpupdate」 の実行

インストール完了後に実行 [bash] [root@localhost ~]# ntpdate ntp1.jst.mfeed.ad.jp 18 Jan 09:08:39 ntpdate[2742]: adjust time server 210.173.160.27 offset -0.001978 sec [/bash]

「chronyd」の設定

定期的に時刻を同期する 「chronyd」の設定。「/etc/chrony.conf」をバックアップして編集。

クライアント側でMinecraftを起動

「Profile」をサーバーで起動しているMinecraftのバージョンに合わせて作成し、「Play」ボタンを押下。 サーバーのバージョンは上記で起動コマンドを実行した後、最初に表示される。 [bash] [09:16:10] [Server thread/INFO]: Starting minecraft server version 1.11.2 [/bash]

起動中...

マルチプレイ」を押下。

「編集」を押下。 「サーバー名」は自分が判別できればなんでもOK。 「サーバーアドレス」はMinecraftを起動しているサーバーのIPアドレス。 入力したら「完了」を押下。

ワールドが追加されている。 右側の緑の電波が立っていれば接続可能。

サーバーを選択して「サーバーに接続」を押下すると下記のようにワールドに入ることができる。

サーバーを停止

[bash] stop [10:34:45] [Server thread/INFO]: Stopping the server [10:34:45] [Server thread/INFO]: Stopping server [10:34:45] [Server thread/INFO]: Saving players [10:34:45] [Server thread/INFO]: Saving worlds [10:34:45] [Server thread/INFO]: Saving chunks for level 'world'/Overworld [10:34:45] [Server thread/INFO]: Saving chunks for level 'world'/Nether [10:34:45] [Server thread/INFO]: Saving chunks for level 'world'/The End [10:34:46] [Server Shutdown Thread/INFO]: Stopping server [10:34:46] [Server Shutdown Thread/INFO]: Saving players [10:34:46] [Server Shutdown Thread/INFO]: Saving worlds [10:34:46] [Server Shutdown Thread/INFO]: Saving chunks for level 'world'/Overworld [/bash]

起動スクリプトの設定

マインクラフトサーバーを「systemd」で管理する。

起動スクリプトの作成

[bash] [minecraft@localhost ~]$ vi mc_start.sh [/bash] 下記のように記載、「:wq」で保存して閉じる。 [bash]

!/bin/bash

USERNAME='minecraft' SERVICE='minecraft_server.jar' SCNAME='minecraft' MC_PATH='/usr/local/games/minecraft'

XMX="1024M" XMS="1024M"

cd $MC_PATH

ME=whoami

if [ $ME == $USERNAME ] ; then if pgrep -u $USERNAME -f $SERVICE > /dev/null then echo "$SERVICE is already running!" else echo "Starting $SERVICE..." screen -AmdS $SCNAME java -Xmx$XMX -Xms$XMS -jar $SERVICE nogui fi else echo "Please run the minecraft user." fi [/bash]

パーミッションの変更

作成した起動スクリプトパーミッションを変更。 [bash] [minecraft@localhost minecraft]$ chmod 744 mc_start.sh [/bash] パーミッションを確認してみると、「minecraft」ユーザのみが実行可能になっている。 [bash] [minecraft@localhost minecraft]$ ls -la mc_start.sh -rwxr--r-- 1 minecraft minecraft 422 1月 18 10:43 mc_start.sh [/bash]

停止スクリプトの作成

[bash] [minecraft@localhost ~]$ vi mc_stop.sh [/bash] 下記のように記載、「:wq」で保存して閉じる。 [bash]

!/bin/bash

USERNAME='minecraft' SERVICE='minecraft_server.jar' SCNAME='minecraft' MC_PATH='/usr/local/games/minecraft'

cd $MC_PATH

ME=whoami

if [ $ME == $USERNAME ] ; then if pgrep -u $USERNAME -f $SERVICE > /dev/null then echo "Stopping $SERVICE" screen -p 0 -S $SCNAME -X eval 'stuff "say SERVER SHUTTING DOWN IN 10 SECONDS. Saving map..."\015' screen -p 0 -S $SCNAME -X eval 'stuff "save-all"\015' sleep 10 screen -p 0 -S $SCNAME -X eval 'stuff "stop"\015' sleep 10 echo "Stopped minecraftserver" else echo "$SERVICE was not runnning." fi else echo "Please run the minecraft user." fi [/bash]

パーミッションの変更

作成した停止スクリプトパーミッションを変更。 [bash] [minecraft@localhost minecraft]$ chmod 744 mc_stop.sh [/bash] パーミッションを確認してみると、「minecraft」ユーザのみが実行可能になっている。 [bash] [minecraft@localhost minecraft]$ ls -la mc_stop.sh -rwxr--r-- 1 minecraft minecraft 642 1月 18 10:49 mc_stop.sh [/bash]

起動スクリプトの実行

[bash] [minecraft@localhost minecraft]$ ./mc_start.sh Starting minecraft_server.jar... [/bash]

screenの確認

screen上で実行されているMinecraftサーバーの確認。 [bash] [minecraft@localhost minecraft]$ screen -ls There is a screen on: 4246.minecraft (Detached) 1 Socket in /var/run/screen/S-minecraft. [/bash]

minecraft screenへの接続

下記を実行すると [bash] [minecraft@localhost minecraft]$ screen -r minecraft [/bash] screenの画面に入る。 [bash] [/bash] screenから抜ける場合は「Ctrl」+「a」を押下→「d」を押下・

Minecraftサーバーの停止

停止スクリプトを実行する。 [bash] [minecraft@localhost minecraft]$ ./mc_stop.sh Stopping minecraft_server.jar [/bash] 10秒程度経過後に下記が表示される。 [bash] Stopped minecraftserver [/bash]

Minecraft自動起動設定

CentOSを起動した際に、自動的にMinecraftサーバーも起動させる設定。

systemdファイルの作成

root権限になって [bash] [minecraft@localhost minecraft]$ su - パスワード: 最終ログイン: 2017/01/18 (水) 09:06:36 JST日時 pts/0 [/bash]

下記のファイルを作成。 [bash] [root@localhost ~]# /etc/systemd/system/minecraft.service [/bash]

下記のように記載、「:wq」で保存して閉じる。 [bash] [Unit] Description=Minecraft Server After=network.target local-fs.target

[Service] Type=forking User=minecraft ExecStart=/usr/local/games/minecraft/mc_start.sh ExecStop=/usr/local/games/minecraft/mc_stop.sh

[Install] WantedBy=multi-user.target [/bash]

「systemctl」 コマンドで自動起動設定

「systemctl」コマンドで、「minecraft.service」の自動起動を設定。 [bash]

systemctl enable minecraft

ln -s '/etc/systemd/system/minecraft.service' '/etc/systemd/system/multi-user.target.wants/minecraft.service' [/bash]

minecraft」ユーザの設定

minecraft」ユーザの環境設定ファイル「/home/minecraft/.bash_profile」で、「/usr/local/games/minecraft/」へのパスを通す。 [bash] [root@localhost ~]# su - minecraft 最終ログイン: 2017/01/18 (水) 11:08:15 JST日時 pts/0 [/bash]

編集するファイル「.bash_profile」のバックアップを取り、

[bash] [minecraft@localhost ~]$ cp -p .bash_profile .bash_profile_20170118 [/bash]

ファイルを開いて下記のように編集。 [bash] [minecraft@localhost ~]$ vi /home/minecraft/.bash_profile [/bash] ファイル内容が表示される。 [bash]

.bash_profile

Get the aliases and functions

if [ -f ~/.bashrc ]; then . ~/.bashrc fi

User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH [/bash]

ファイルの下の方の「PATH」の部分を下記のように編集する。 編集前 [bash] PATH=$PATH:$HOME/.local/bin:$HOME/bin [/bash]

編集後 [bash] PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/games/minecraft/ [/bash]

サーバー再起動

サーバーを再起動し、minecraftサーバーが自動的に起動しているか確認。 [bash] [minecraft@localhost ~]$ su - パスワード: 最終ログイン: 2017/01/18 (水) 11:57:49 JST日時 pts/0 [root@localhost ~]# reboot [/bash]