クラスター機能チュートリアル¶
概要¶
このチュートリアルでは、Sora のクラスター機能をひととおり使ってみるところまでを説明します。
前提¶
クラスター特有ではない Sora の設定や起動方法、シグナリングで使用する NGINX の設定等については チュートリアル をご確認ください。
ライセンス¶
ノード数分のライセンスが必要になります。
Sora 3 台でクラスターを構築する場合は通常のライセンスが 3 つ、もしくは 3 ノード以上に対応した 最大ノード数ライセンス が 1 つ必要です。
リレー機能¶
どのノードに繋いでも同一チャネルに接続できるようになるリレー機能を利用する場合は、 最大ノード数ライセンス を利用する必要があります。
最大ノード数ライセンス を利用している場合、リレー機能はデフォルトで有効です。
アフィニティ機能¶
リレー機能を利用した際でも、できるだけ同一セッションは同一ノードへ接続することで、 ノード間の通信を最小限に抑えるアフィニティ機能を利用する場合は、 最大ノード数ライセンス を利用する必要があります。
最大ノード数ライセンス を利用している場合、アフィニティ機能はデフォルトで有効です。
ライセンスで決められた最大同時接続数の合計を維持する機能¶
クラスターのノードで障害が発生した際、 他のノードが同時接続数を引き受けるライセンスで決められた最大同時接続数の合計を維持する機能は、 最大ノード数ライセンス を利用する必要があります。
最大ノード数ライセンス を利用している場合、ライセンスで決められた最大同時接続数の合計を維持する機能はデフォルトで有効です。
テンポラリーノード機能¶
クラスター機能を利用した際に、クラスターの維持を目的とせず、 一時的なスケールアウトを目的にノードを追加するテンポラリーノード機能を利用する場合は、 最大ノード数ライセンス を利用する必要があります。
クラスターの構築¶
まず、ここでは 3 ノードの Sora クラスターを構築する手順を示します。
それぞれのノードのノード名は [email protected], [email protected], [email protected] とします。
external_api_url は HTTP API を叩いたノードにはそのセッションが存在しない場合に、
別のノードに転送するために location ヘッダーに指定する URL です。
そのためプライベートなアドレスでも問題ありません。
ここでのクラスター構築では、3 台のサーバーがそれぞれ TCP/IP で通信できる状態になっていること、
そして Sora の tar.gz が展開されて bin/sora が実行できるようになっていることを前提としています。
- クラスター間の通信に必要な TCP のポートをすべて開放します
- TCP 4369
- ポート番号の変更はできません、必ずこのポートを開放してください
- TCP 49010-49020
sora.confにて変更できますがデフォルトをお勧めします
- TCP 4369
- 最初のノード([email protected])の
sora.confにクラスターの設定をしますnode_name = [email protected] cluster = true external_signaling_url = wss://sora-node1.example.com/signaling external_api_url = http://192.0.2.101:3000/ - 最初のノード([email protected])の Sora を
bin/sora daemonで起動します - 次のノード([email protected])の
sora.confも最初のノードと同様にクラスターの設定をしますnode_name = [email protected] cluster = true external_signaling_url = wss://sora-node2.example.com/signaling external_api_url = http://192.0.2.102:3000/ - 次のノード([email protected])の Sora を
bin/sora daemonで起動します - 最後のノード([email protected])の
sora.confにもクラスターの設定をしますnode_name = [email protected] cluster = true external_signaling_url = wss://sora-node3.example.com/signaling external_api_url = http://192.0.2.103:3000/ - 最後のノード([email protected])の Sora を
bin/sora daemonで起動します - 最初のノード([email protected])の Sora に InitCluster APIを実行し、3 ノードのクラスターとして初期化します
$ http POST 127.0.0.1:3001/ x-sora-target:Sora_20221221.InitCluster \ node_name_list:='["[email protected]", "[email protected]", "[email protected]"]' - 最初のノード([email protected])の Sora に ListClusterNodes APIを実行し、ノード一覧を取得します
$ http POST 127.0.0.1:3001/ x-sora-target:Sora_20211215.ListClusterNodes
結果として、 [email protected] から [email protected] の 3 ノードの一覧が取得できれば、クラスターの構築は完了です。
クラスター構築のトラブルシューティング¶
クラスター構築時に躓きやすいポイントと確認事項を示します。
- ノード間通信ができない場合
- Sora はノード間通信を行うため、ファイアウォールの開放が必要です
- クラスター構成情報ファイル にあるとおりに、EPMD と sora の Listen ポートの開放を確認してください
- ライセンス違反のエラーが出る場合
- 最大ノード数ライセンス ではないライセンスを使っている場合には、すべてのノードで 異なるライセンスが設定されている必要があります
- 最大ノード数ライセンス のライセンスを使っている場合には、指定されたノード数まで 同じライセンスを利用できます
- 最大ノード数ライセンス とそうではないライセンスを混在させて利用することはできません
- RegisterClusterNode API 実行時に
CONTACT-NODE-NOT-INITIALIZEDエラーが出る場合- 未初期化のノードを
contact_node_nameに指定した場合に発生します contact_node_nameに指定するノードは InitCluster で初期化したノードか、 RegisterClusterNode API でクラスターに参加したノードを指定する必要があります
- 未初期化のノードを
クラスター操作¶
上記のクラスターの構築の手順で、クラスターの構築と初期化が完了していることを前提とします。
クラスターのノード一覧の取得¶
構築済みのクラスター内のノード名 [email protected]、 [email protected]、 [email protected] のいずれかで ListClusterNodes API を実行して、 クラスター内のノード一覧を取得します。
$ http POST 127.0.0.1:3000/ x-sora-target:Sora_20211215.ListClusterNodes
HTTP/1.1 200 OK
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, x-sora-target
access-control-allow-methods: POST, OPTIONS
access-control-allow-origin: *
access-control-max-age: 1000
content-length: 1057
content-type: application/json
date: Fri, 08 Dec 2023 07:51:19 GMT
server: Cowboy
[
{
"connected": true,
"external_api_url": "https://sora-node1.example.com/api",
"external_signaling_url": "wss://sora-node1.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
},
{
"connected": true,
"external_api_url": "https://sora-node2.example.com/api",
"external_signaling_url": "wss://sora-node2.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
},
{
"connected": true,
"external_api_url": "https://sora-node3.example.com/api",
"external_signaling_url": "wss://sora-node3.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
}
]
クラスターチャネル割り当て一覧の取得¶
接続済みのチャネルのノードへの割り当てを確認するために、ListClusterChannels API を実行します。
まず、構築済みのクラスターに複数のチャネルで接続しておきます。
次に、クラスター内のいずれかのノードで ListClusterChannels API を実行して、クラスターのチャネル割り当ての一覧を取得し、チャネルと割り当てられているノードを確認します。
$ http POST 127.0.0.1:3000/ x-sora-target:Sora_20211215.ListClusterChannels
HTTP/1.1 200 OK
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, x-sora-target
access-control-allow-methods: POST, OPTIONS
access-control-allow-origin: *
access-control-max-age: 1000
content-length: 342
content-type: application/json
date: Mon, 11 Dec 2023 03:53:49 GMT
server: Cowboy
[
{
"channel_id": "hisui",
"owners": [
{
"connected": true,
"node_name": "[email protected]"
}
]
},
{
"channel_id": "kohaku",
"owners": [
{
"connected": true,
"node_name": "[email protected]"
}
]
},
{
"channel_id": "sora",
"owners": [
{
"connected": true,
"node_name": "[email protected]"
}
]
},
{
"channel_id": "zakuro",
"owners": [
{
"connected": true,
"node_name": "[email protected]"
}
]
}
]
クラスターからノードを消去する¶
構築済みのクラスター内からノードを消去してみます。
ここでは、ノード名 [email protected]、 [email protected]、 [email protected] の 3 ノードで構築されているクラスターから、 [email protected] のノードを消去します。
ノードの消去には PurgeClusterNode API を使用します。
初めに、 [email protected] の Sora を bin/sora stop で停止します。
次に、 [email protected] ノードの data/ ディレクトリを削除します。
[email protected] のノードで ListClusterNodes API を実行して、
[email protected] のノードについて "connected": false になっていることを確認します。
$ http POST 127.0.0.1:3000/ x-sora-target:Sora_20211215.ListClusterNodes
HTTP/1.1 200 OK
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, x-sora-target
access-control-allow-methods: POST, OPTIONS
access-control-allow-origin: *
access-control-max-age: 1000
content-length: 704
content-type: application/json
date: Fri, 08 Dec 2023 08:06:39 GMT
server: Cowboy
[
{
"connected": true,
"external_api_url": "https://sora-node1.example.com/api",
"external_signaling_url": "wss://sora-node1.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
},
{
"connected": true,
"external_api_url": "https://sora-node2.example.com/api",
"external_signaling_url": "wss://sora-node2.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
},
{
"connected": false,
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"node_name": "[email protected]",
"temporary_node": false
}
]
クラスターから [email protected] ノードの情報を消去するために、 [email protected] または [email protected] ノードのいずれかで PurgeClusterNode API を実行します。
この API を実行する際の target_node_name には消去するノード名を指定します。
今回指定するノード名は、 [email protected] です。
$ http POST 127.0.0.1:3000/ x-sora-target:Sora_20220629.PurgeClusterNode [email protected]
HTTP/1.1 200 OK
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, x-sora-target
access-control-allow-methods: POST, OPTIONS
access-control-allow-origin: *
access-control-max-age: 1000
content-length: 40
content-type: application/json
date: Mon, 11 Dec 2023 02:03:09 GMT
server: Cowboy
{
"target_node_name": "[email protected]"
}
再度 [email protected] のノードで ListClusterNodes API を実行して、 クラスターのノードから [email protected] のノードが見えなくなっていることを確認します。
$ http POST 127.0.0.1:3000/ x-sora-target:Sora_20211215.ListClusterNodes
HTTP/1.1 200 OK
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, x-sora-target
access-control-allow-methods: POST, OPTIONS
access-control-allow-origin: *
access-control-max-age: 1000
content-length: 704
content-type: application/json
date: Fri, 08 Dec 2023 08:06:39 GMT
server: Cowboy
[
{
"connected": true,
"external_api_url": "https://sora-node1.example.com/api",
"external_signaling_url": "wss://sora-node1.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
},
{
"connected": true,
"external_api_url": "https://sora-node2.example.com/api",
"external_signaling_url": "wss://sora-node2.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
}
]
クラスターにノードを追加する¶
構築済みのクラスターにノードを追加してみます。
ノード名 [email protected]、 [email protected] の 2 ノードで構築されているクラスターへ、 API を使用して [email protected] ノードを追加します。
ノードの追加には RegisterClusterNode API を使用します。
クラスターに [email protected] ノードを追加するために、 [email protected] ノードで RegisterClusterNode API を実行します。
この API を実行する際の contact_node_name には既存のクラスターのノード名を指定します。
今回指定するノード名は、 [email protected] または [email protected] のいずれかです。
$ http POST 127.0.0.1:3000/ x-sora-target:Sora_20211215.RegisterClusterNode [email protected]
HTTP/1.1 200 OK
content-length: 80
content-type: application/json
date: Mon, 11 Dec 2023 02:33:35 GMT
server: Cowboy
{
"node_name_list": [
"[email protected]",
"[email protected]",
"[email protected]"
]
}
ListClusterNodes API を使用して、クラスターに追加されていることを確認します。
$ http POST 127.0.0.1:3000/ x-sora-target:Sora_20211215.ListClusterNodes
HTTP/1.1 200 OK
content-length: 1057
content-type: application/json
date: Mon, 11 Dec 2023 02:34:04 GMT
server: Cowboy
[
{
"connected": true,
"external_api_url": "https://sora-node1.example.com/api",
"external_signaling_url": "wss://sora-node1.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
},
{
"connected": true,
"external_api_url": "https://sora-node2.example.com/api",
"external_signaling_url": "wss://sora-node2.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
},
{
"connected": true,
"external_api_url": "https://sora-node4.example.com/api",
"external_signaling_url": "wss://sora-node4.example.com/signaling",
"license_max_connections": 100,
"license_max_nodes": 3,
"license_serial_code": "DOC123-SRA-E002-201303-N3-100",
"license_type": "Experimental",
"mode": "normal",
"node_name": "[email protected]",
"temporary_node": false,
"version": "2024.1.0"
}
]