Quoridorn-mark2の雑な導入手順

注意!!2020/09/03に公開された「client:Ver.2.0.0a80」「server:Ver1.0.0a50」では本手順ではビルドできません。手順や設定内容が変わっています。

必要なもの



  • Linuxが動くサーバー(物理でも仮想でもクラウドでも可)

  • mongodb

  • nginx

  • nodejs-12.x.x(nvmがあれば便利)

  • certbotまたはSSL証明書(HTTPS使うなら必須)

  • minio

  • bcdice-apiサーバー(どどんとふ公式鯖とか公開API鯖使うなら不要)


前提色々


mongodb


mongodbのセットアップ方法は、mongodbのサイトなどを参照してセットアップしてください。debianとかCentOSならリポジトリ追加したらaptなりdnfですんなり導入可能。
4.xと3.xで動作確認済み。特にデフォルトのセットアップでOK。可用性高めたければレプリケーション構成なりに。quoridorn用に好きな名前でDBを作成。

S3


AWSのS3でもwasabiでもIBM Cloud Object Storageでもさくらのオブジェクトストレージでも動くはずですが、当サーバーはminioのstandalone構成。
minioのサイトを見て導入しよう。基本的には適当なユーザーとファイルシステムを作成して、バイナリをダウンロードして、systemdのserviceを作成して起動して終わり。動作確認はmcなどで。
AWSでもさくらでもminioでもOK。適当な名称でbucketを作成し、Quoridorn用のAPIとSecretキーを生成、デフォルトのポリシーはREAD-ONLYにする。
minioをそのまま外部公開するのはおすすめしない。こちらでは127.0.0.1で待ち受けてnginxがReverseProxyでminioに渡すようにした。
APIキーは絶対nginxのdocument root以下には置かないように。
minioのsystemdのunitファイル例(/etc/systemd/system/minio.service)

[Unit]
Description=minio Object Storage Service Inst1
After=network.target

[Service]
Type=simple
User=minio
EnvironmentFile=/srv/minio/inst1/env
ExecStart=/usr/local/sbin/minio server –address 0.0.0.0:9000 –config-dir /srv/minio/inst1/config /srv/minio/inst1/data
Restart=on-abort
WorkingDirectory=/srv/minio/inst1

[Install]
WantedBy=multi-user.target


Quoridorn-serverセットアップ


nvmでnodejsを設定

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
$ . ~/.bashrc
$ nvm install v12.18.3
$ nvm alias default v12.18.3

quoridornサーバーを実行するユーザーでpullしてREADME通りにビルド(npm installで、READMEに書かれている前提のExpressやsocket.ioやnekostoreは導入されます)

$ git clone https://github.com/HillTopTRPG/quoridorn-server
$ npm install
$ npm run build

config/server.yamlを編集(コメントは省略してます

port: 8180
storeType: mongodb
secretCollectionSuffix: コメントに書かれているUUID生成サイトなどで生成した任意の固有なUUIDを入力
roomNum: 100
roomAutoRemove: 4320
mongodbConnectionStrings: mongodb://127.0.0.1:27017/DB名

config/stoprage.yamlを編集

bucket: quoridorn
accessUrl: ‘https://quoridorn-test.onlinesession.app/s3/’
endPoint: localhost
port: 9000
accessKey: ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’
secretKey: ‘xxxxxxxxxxxxxxxxxxxxxxxxxxx’
useSSL: false

ここまで設定したら、「npm run node-server」を実行して起動に成功するか確認。成功したらsystemdのunitファイルを作成してシステム起動時に自動起動するよう設定
/etc/systemd/system/quoridorn.serviceみたいな名前でunitファイルを作成

[Unit]
Description=quoridornserver
After=network.target mongod.service minio.service

[Service]
Type=simple
User=quoridorn
WorkingDirectory=/srv/quoridorn/quoridorn-server
Environment=NODE_VERSION=stable
Environment=ENV=production
ExecStart=/home/quoridorn/.nvm/nvm-exec npm run node-server
TimeoutSec=120
Restart=always

[Install]
WantedBy=multi-user.target


quoridornのクライアントをビルドして設置


nodejsが使えるならローカルPCでも可。ビルドにはメモリーを2GBぐらい使うのでしょぼいVPSだとメモリが足りなくてビルドに失敗します。

$ git clone https://github.com/HillTopTRPG/quoridorn-mark2
$ cd quoridorn-mark2
$ npm install
$ vi .env
で、ドメイン直下ならBASE_URLをブランクにそうでなければ相対パスを設定
$ npm run build

ビルドに成功したら、dist/config/static/connect.yamlを編集し、quoridorn-serverの接続先URLとbcdice-apiのサーバーを設定。(skywayは2.0.0a77時点では使っていないので設定不要)
distディレクトリ以下をnginxのdocumentorootなりコンテンツディレクトリにコピー

nginxの設定



map $http_upgrade $connection_upgrade {

default upgrade;

” close;

}

server {

listen 80;

listen [::]:80;
root /home/quoridorn/dist;

server_name quoridorn-test.onlinesession.app;

location / {
try_files $uri $uri/ @express;
}

location @express {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Proxy “”;
proxy_pass_header Server;

proxy_pass http://127.0.0.1:8180;
proxy_buffering off;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

tcp_nodelay on;
}

location /s3/ {
# minio settings
proxy_set_header Host $http_host;
proxy_pass http://localhost:9000/quoridorn/;
}
}


ざっくり説明すると、ブラウザが要求したリクエストでクライアントファイル以外は、/s3/以下はminioに、それ以外はquoridorn-serverにproxyしています。

最後に


かなりざっくり説明で、nginxのHTTPS設定のやり方とか、firewalldの穴開け方法、HTTP→HTTPSへのリダイレクト設定、certbot設定、そもそものmongodbセットアップなどかなりを端折っていますし、2.0.0a77時点の情報なので普通にビルド成功しても色々不具合や未実装の機能がたくさんあるので、人柱上等でこのざっくり説明をちゃんとかみ砕いて自分用に理解して設定できないと自鯖運営は無理だと思います。
はっきりいって、自鯖作るのはどどんとふよりかなり導入難易度は高めです。ガバガバ設定にすると加害者になることもありえるので構築は慎重にご検討ください。