---
title: OpenLM Router をデプロイする
description: 自社ネットワーク内の Linux ホスト上で、OpenLM Platform 用の OpenLM Router を Docker Compose スタックとして実行します。
product: OpenLM Platform
---

Router を自社ネットワークに配置するには、Linux ホスト上に Docker Compose スタックとしてデプロイします。スタックが動作したら、[OpenLM Router を設定する](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/configuration)で Router を OpenLM Platform に接続し、フェイルオーバーペアを定義します。

## はじめに

次の前提条件を確認してください。

- [システム要件](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/system-requirements)を満たし、Docker Engine と Docker Compose v2 プラグインがインストールされた Linux ホスト。
- ホストから OpenLM Platform と、各ライセンスサーバーの `lmgrd` ポートへのネットワークアクセス。
- [システム要件](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/system-requirements#openlm-platform-の前提条件)で説明しているとおり、OpenLM Platform が OpenLM Broker を通じて監視しているライセンスサーバー。
- [システム要件](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/system-requirements)で生成した暗号化キー。

## イメージを取得する

Router のイメージは OpenLM の公開レジストリで公開されており、匿名でプルできるため、`docker login` もプルシークレットも必要ありません。イメージをプルするには、次のコマンドを実行します。

```bash
docker pull public.ecr.aws/r3q3q2f4/olm-routerapi:1.261006.0752
docker pull public.ecr.aws/r3q3q2f4/olm-routerui:1.261008.0932
```

タグは `1.<yymmdd>.<hhmm>` 形式のビルド番号です。レジストリには `latest` などの移動するタグがないため、各イメージに明示的なタグを固定し、デプロイしたビルドを記録してください。OpenLM は 2 つのイメージを別々にリリースするため、タグが異なる場合があります。

### 利用可能なビルドを確認する

このページのタグは、このガイドが対象とするビルドです。レジストリにあるイメージのすべてのビルドを確認するには、そのイメージのタグを一覧表示します。レジストリはアクセストークンを匿名で発行するため、アカウントは必要ありません。

Linux では、`curl` と `jq` を使って次を実行します。

```bash
repo=olm-routerapi   # or olm-routerui
token=$(curl -s "https://public.ecr.aws/token/?service=public.ecr.aws&scope=repository:r3q3q2f4/$repo:pull" | jq -r .token)
curl -s -H "Authorization: Bearer $token" "https://public.ecr.aws/v2/r3q3q2f4/$repo/tags/list" | jq -r '(.tags // [.errors[0].message])[]' | sort
```

PowerShell では、次を実行します。

```powershell
$repo = "olm-routerapi"   # or olm-routerui
$token = (Invoke-RestMethod "https://public.ecr.aws/token/?service=public.ecr.aws&scope=repository:r3q3q2f4/${repo}:pull").token
(Invoke-RestMethod "https://public.ecr.aws/v2/r3q3q2f4/$repo/tags/list" -Headers @{ Authorization = "Bearer $token" }).tags | Sort-Object
```

コマンドは、イメージごとに 1 回ずつ実行します。タグはビルド順に並ぶため、最後の行が最新のビルドです。出力が `Rate exceeded` の場合、または PowerShell が `TOOMANYREQUESTS` を報告した場合は、レジストリが匿名のリクエストを制限しています。5 秒待ってから、もう一度コマンドを実行してください。

## 環境ファイルを作成する

ホスト上の作業ディレクトリ（例: `~/openlm-router/`）に、`.env` という名前のファイルを作成します。

```bash
# The MongoDB account the Compose file creates on the first start.
MONGO_USER=router
MONGO_PASSWORD=<your-generated-password>

# The key protecting the stored Platform client secret. Paste the string that
# `openssl rand -base64 32` printed, exactly as it printed it.
ADMISSION_PLATFORM_ENCRYPTION_KEY=<your-generated-key>
```

MongoDB のパスワードは `openssl rand -hex 16` で生成します。パスワードは接続文字列の一部になるため、`@`、`:`、`/` などの文字を含むパスワードを使うと、Router から MongoDB への接続が壊れます。MongoDB はデータボリュームが空のときにだけアカウントを作成するため、後でパスワードを変更しても、既存のアカウントは変わりません。

サンプルや開発用スタックの暗号化キーは、決して再利用しないでください。[システム要件](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/system-requirements)の説明に従って、独自のキーを生成してください。

## Router UI 用のプロキシファイルを作成する

Router UI は `/router-management/` パスで提供され、前段にリバースプロキシがあることを前提としています。このリバースプロキシが、そのプレフィックスを取り除き、API 呼び出しを Router に転送します。`.env` ファイルと同じ場所に、`router-ui-proxy.conf` を作成します。

```nginx
server {
  listen 8101;

  # The Router UI, with the /router-management prefix stripped.
  location /router-management/ {
    proxy_pass http://127.0.0.1:8102/;
  }

  # API calls from the browser, forwarded to the Router.
  location /api/routerapi/ {
    proxy_pass http://127.0.0.1:8100/api/;
  }
}
```

## Compose ファイルを作成する

同じディレクトリに `docker-compose.yml` を作成します。

```yaml
services:
  mongo:
    image: mongo:7
    ports:
      - "127.0.0.1:27017:27017"
    environment:
      - MONGO_INITDB_ROOT_USERNAME=${MONGO_USER}
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}
    volumes:
      - mongo_data:/data/db
    restart: unless-stopped

  redis:
    image: redis:7
    command:
      - redis-server
      - --appendonly
      - "yes"
      - --appendfsync
      - everysec
      - --maxmemory-policy
      - noeviction
    ports:
      - "127.0.0.1:6379:6379"
    volumes:
      - redis_data:/data
    restart: unless-stopped

  routerapi:
    image: public.ecr.aws/r3q3q2f4/olm-routerapi:1.261006.0752
    depends_on: [mongo, redis]
    # Host networking so each pair's listen port lands on a real host address that
    # workstations can reach, and so the license server sees the Router host as the
    # source. Listen ports are opened at runtime, after a pair is configured, so they
    # cannot be declared under `ports:` ahead of time.
    network_mode: host
    environment:
      - MONGODB__CONNECTIONSTRING=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@localhost:27017/?authSource=admin
      - REDIS__CONNECTIONSTRING=localhost:6379,abortConnect=false
      - ADMISSION_PLATFORM_ENCRYPTION_KEY=${ADMISSION_PLATFORM_ENCRYPTION_KEY}
      # Required. The Router takes its configuration from the OpenLM Platform.
      - licOpsConfiguration__enabled=true
      - LICOPSCONFIGURATION_ENABLED=true
      # Required. Declares a failover Router. Fixed at the first start.
      - ROUTER_CONFIG_BOOTSTRAP_MODE=basic
      - ROUTER_CORRELATION_MODE=Ip
      - ROUTER_PROXY_PROTOCOL_ENABLED=false
      - ROUTER_TRUSTED_CIDR=127.0.0.1/32
      # Keep the background-job dashboard off.
      - hangfire__dashboard__enabled=false
    restart: unless-stopped

  routerui:
    image: public.ecr.aws/r3q3q2f4/olm-routerui:1.261008.0932
    ports:
      - "127.0.0.1:8102:8101"
    environment:
      - LB_FQDN=_
    restart: unless-stopped

  routerui-proxy:
    image: nginx:stable
    depends_on: [routerui]
    network_mode: host
    volumes:
      - ./router-ui-proxy.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped

volumes:
  mongo_data:
  redis_data:
```

Router の設定は、ここに示したとおりに維持してください。

- `licOpsConfiguration__enabled` と `LICOPSCONFIGURATION_ENABLED` は、Router が OpenLM Platform から構成を取得するようにします。これらがないと、Router をフェイルオーバー用に構成できません。
- `ROUTER_CONFIG_BOOTSTRAP_MODE=basic` は、この Router がフェイルオーバーペアを提供することを宣言します。Router が接続すると、OpenLM Platform はその Router 用に空の初期構成を作成します。この設定がないと OpenLM Platform は何も作成せず、構成が存在するまで Router は待機したままになります。

モードは Router の初回起動時に固定されます。変更するには、専用の空の MongoDB データベースを持つ新しい Router をデプロイし、古い Router を停止してください。

:::warning[示したとおりの変数名を使ってください]

`MONGODB__CONNECTIONSTRING` と `REDIS__CONNECTIONSTRING` では、`CONNECTIONSTRING` の前にアンダースコアが 2 つ必要です。Router は起動時にこれらの名前を構成に代入するため、つづりを誤ると単に無視されるだけでは済みません。値が空のまま渡され、コンテナーは起動時に `Mongo ConnectionString cannot be null or empty.` を出力して終了します。

:::

Router はホストネットワークを使うため、接続文字列には `localhost` を使います。MongoDB と Redis は `127.0.0.1` にだけポートを公開するため、Router はホスト上でこれらに到達でき、ホストの外部からは到達できません。すでに運用している MongoDB と Redis のサーバーを使う場合は、2 つの接続文字列をそれらのサーバーに向けて変更してください。Router UI も、ポート `8102` で `127.0.0.1` にポートを公開し、プロキシがそれをポート `8101` でブラウザーに提供します。

## スタックを起動する

スタックを起動し、Router API のログを追跡するには、次のコマンドを実行します。

```bash
docker compose up -d
docker compose logs -f routerapi
```

初回起動時、Router は自身の ID を作成し、OpenLM Platform から構成を取得することをログに出力します。

```text
Bootstrap seed skipped: the Router is service-managed (LicOps configuration enabled); identity RouterId <guid> established.
Router configuration shape: service-managed; ...
```

Router が応答していることを確認します。

```bash
curl http://localhost:8100/api/v1/status
```

```json
{
  "status": "unconfigured",
  "configurationManagement": {
    "shape": "serviceManaged",
    "routerId": "a76db42e-5d48-497d-bbbb-f66dc04d9d5f",
    "lastSync": {
      "lastSuccessfulSync": null,
      "lastFailure": "No Platform connection is configured, so the Router has no address for the LicOps Configuration service"
    }
  }
}
```

新しい Router では、これが正しい結果です。Router は動作していますが、まだ OpenLM Platform に接続されていないため、構成がなく、クライアント用のポートも開いていません。`status` フィールドを確認します。Router を接続すると、構成は OpenLM Platform から届きます。

`routerId` は一度だけ作成され、MongoDB に保存されます。OpenLM Platform はこの ID で、この Router をほかの Router と区別します。データベースを消去すると新しい ID が作成され、OpenLM Platform からは別の Router として扱われます。

インタラクティブな API リファレンスは、`http://<router-host>:8100/swagger` にあります。

## デプロイを検証する

コンテナーが実行中で、Router UI が読み込まれることを確認します。

```bash
docker compose ps
curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8101/router-management/
```

2 つ目のコマンドは `200` を出力します。ブラウザーで `http://<router-host>:8101/router-management/` を開きます。Platform 接続が構成されていないことを示す赤い通知が表示されますが、次の手順を完了するまでは想定どおりの状態です。

Router の準備状態エンドポイントである `/readyz` と `/health/ready` は、Router が OpenLM Platform から構成を取得するまで `503` を返します。新規インストールでは、これは障害ではなく想定どおりの動作です。

:::note[次のステップ]
[OpenLM Router を設定する](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/configuration)に進み、Router を OpenLM Platform に接続して、最初のフェイルオーバーペアを定義します。この環境を後でアップグレードするには、[OpenLM Router の変更、アップグレード、削除](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/manage#openlm-router-をアップグレードする)を参照してください。
:::

## 関連項目

- [システム要件](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/system-requirements)
- [OpenLM Router の変更、アップグレード、削除](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/manage)
- [OpenLM Router のトラブルシューティング](https://www.openlm.com/documentation/ja/cloud/deployment-operations/router/troubleshooting#router-のコンテナーが起動しないのはなぜですか)
