loader image

Concurrent インスタンスの構築方法 (without Docker)

※こちらは古い内容の記事です。記事公開時点の内容で更新は行っておりませんので、ご承知おき下さい。

絶対に Docker 使いたくないマンによる without Docker で構築した Concurrent インスタンスを建てました。
今回は、without Docker での構築方法をメモしていきたいと思います。

※弊環境は特殊すぎるため、この手順は全く参考にならないかと思われます。

サーバ構成

DB Server

  • 192.168.10.10
  • PostgreSQL、Redis、Memcached、Minio

GW Server

  • 192.168.10.11
  • Reverse Proxy (H2O)

Apps Server

  • 192.168.10.14
  • 各種アプリケーションはこれで動かす

手順

※ユーザーをつくるところまでは割愛

Git リポジトリを clone する

git clone https://github.com/totegamma/concurrent.git

設定ファイルの用意

/etc/concrnt フォルダを作成し、concurrent/_docs/etc フォルダの中身を /etc/concrnt フォルダにコピーする。
gateway や api は、このフォルダの中にあるファイルを読みに行きます。

gateway.yaml ファイルを修正する。

services:
  - name: concrnt
    host: 192.168.10.14
    port: 8010
    path: /api/v1
    injectCors: true
  - name: webui
    host: webui
    port: 80
    path: /web
    preservePath: true
  - name: url-summary
    host: 192.168.10.14
    port: 8090
    path: /summary
# - name: activitypub
#   host: apbridge
#   port: 8000
#   path: /ap
#   preservePath: true
#   injectCors: true
# - name: webfinger
#   host: apbridge
#   port: 8000
#   path: /.well-known
#   preservePath: true
#   injectCors: true
  - name: mediaserver
    host: 192.168.10.14
    port: 8070
    path: /storage

config.yaml ファイルを修正する。

  • captchaSitekey と captchaSecret は Google reCaptcha から取得してくる。
  • repositoryPath はお好きな場所にフォルダを作成し、そこを指定する。
  • dsn は PostgreSQL の場所を、redisAddr は Redis の場所を (index 指定不可、0 番になる)、memcachedAddr は Memcached の場所をそれぞれ指定する。
  • it is handy to generate these info with~ の欄は、concurrent.world/devtool へアクセスして生成する。
  • profile の欄は、ご自由にどうぞ。(nickname と description、logo は探索画面で表示される項目になる)

gateway のビルド

Concurrent は Go で動くプログラムのため、事前に Go Lang をインストールしておく。(インストール手順は割愛)
インストールが終わったら ~/concurrent へ移動し、下記コマンドを実行する。

go mod download
go mod verify

cmd/gateway へアクセスし、main.go ファイルを開く。378 行目にある e.Start(“:8080”) を e.Start(“192.168.10.14:8080”) のように修正する。
※Concurrent は Docker で動かすことを前提につくられているため、同一マシンで動かす場合はポート番号の変更が必要。IPアドレスを追加しているのは、ただの気分によるもの。

修正が終わったら、go build コマンドを実行しビルドを行う。

api のビルド

cmd/api へアクセスし、main.go ファイルを開く。424 行目にある e.Logger.Fatal(e.Start(port)) を e.Logger.Fatal(e.Start(“192.168.10.14:8010”)) のように修正する。
修正が終わったら、go build コマンドを実行しビルドを行う。

web-ui のビルド

web-ui は Vite で構築されているようで、Node.js を使いビルドする。
Node.js 18 系を使うようなので、予め nvm 等を用いて環境を用意しておく。
web ディレクトリへ移動し、下記コマンドを実行しビルド。

pnpm install
pnpm build

ビルドを行ったら、web ディレクトリを GW Server へ移動する。

url-summary のビルド

url-summary は別リポジトリのため、まずは GitHub より git clone を実施する。その後モジュールのインストールをする。

cd ~
git clone https://github.com/rassi0429/url-summary.git
cd url-summary
npm install

cc-media-server のビルド

cc-media-server も別リポジトリのため、まずは GitHub より git clone を実施する。

cd ~
git clone https://github.com/totegamma/cc-media-server.git
cd cc-media-server

main.go ファイルを開き、最終行にある panic(e.Start(“:8000”)) を panic(e.Start(“192.168.10.14:8070”)) のように修正する。
修正が終わったら、下記コマンドを実行しビルドを行う。

go mod download
go build -o mediaserver

動作確認

./cmd/gateway/gateway、./cmd/api/api を実行しエラーが発生しないことを確認する。
※(確か) 最初に gateway が実行されると、DB の初期化が行われ各種テーブルが作成されたと思う。

サービスとして動かす

サービス起動用ファイルを作成する。
作成したらサービスとして問題なく動作することを確認する。

concurrent-api.service

[Unit]
Description=Concurrent (API)
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=concurrent
WorkingDirectory=/home/concurrent/concurrent
ExecStart=/home/concurrent/concurrent/cmd/api/api
ExecReload=/bin/kill -SIGUSR1 $MAINPID
TimeoutSec=10
Restart=always

[Install]
WantedBy=multi-user.target

concurrent-gateway.service

[Unit]
Description=Concurrent (Gateway)
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=concurrent
WorkingDirectory=/home/concurrent/concurrent
ExecStart=/home/concurrent/concurrent/cmd/gateway/gateway
ExecReload=/bin/kill -SIGUSR1 $MAINPID
TimeoutSec=10
Restart=always

[Install]
WantedBy=multi-user.target

concurrent-storage.service

公式のマニュアル を参照し、環境変数を適切に設定すること。

[Unit]
Description=Concurrent (Media Storage)
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=concurrent
WorkingDirectory=/home/concurrent/cc-media-server
ExecStart=/home/concurrent/cc-media-server/mediaserver
ExecReload=/bin/kill -SIGUSR1 $MAINPID
TimeoutSec=10
Restart=always

[Install]
WantedBy=multi-user.target

concurrent-summary.service

[Unit]
Description=Concurrent (URL Summary)
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=concurrent
WorkingDirectory=/home/concurrent/url-summary
Environment="PATH=/home/concurrent/.nvm/versions/node/v18.20.3/bin:/home/concurrent/.local/bin:/home/concurrent/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
Environment="NODE_ENV=production"
Environment="PORT=8090"
ExecStart=/home/concurrent/.nvm/versions/node/v18.20.3/bin/node main.mjs
ExecReload=/bin/kill -SIGUSR1 $MAINPID
TimeoutSec=10
Restart=always

[Install]
WantedBy=multi-user.target

Webサーバを動かす

弊環境はリバースプロキシとして H2O を採用している。
H2O を使用した設定例を記載しておく。

# concrnt.h3z.jp
    "concrnt.h3z.jp:80":
        listen:
            port: 80
        header.set: "Access-Control-Allow-Headers: *"
        header.set: "Access-Control-Allow-Methods: *"
        header.set: "Access-Control-Allow-Origin: *"
        paths:
            "/web/index.html":
                file.file: /mnt/wwwroot/concrnt/dist/index.html
            "/web":
                file.index: ['index.html']
                file.dir: /mnt/wwwroot/concrnt/dist
                redirect:
                    url: /web/index.html
                    internal: YES
                    status: 307
            "/favicon.ico":
                file.file: /mnt/wwwroot/proxy-data/favicon_concrnt.h3z.jp.ico
            "/robots.txt":
                file.file: /mnt/wwwroot/proxy-data/robots_concrnt.h3z.jp.txt
            "/":
                proxy.tunnel: ON
                proxy.preserve-host: ON
                proxy.reverse.url: http://192.168.10.14:8080