HAProxy を使用した OpenSearch クラスタのバランシング
概要
This document describes the configuration of a balanced OpenSearch cluster using HAProxy.
このドキュメントでは、HAProxy を使用したバランスの取れた OpenSearch クラスタの設定について説明します。
OpenSearch クラスタのインストールと設定
For the installation and configuration of an OpenSearch cluster, we will follow the official documentation at:
OpenSearch クラスタのインストールと設定については、次の公式ドキュメントに従います。
“Configuring an OpenSearch cluster for Pandora FMS”
“Pandora FMS 用の OpenSearch クラスタの設定”
Once completed, you will have a multi-node architecture with a functional cluster. As an example architecture, we will describe a 3-node cluster, for example:
完了すると、機能的なクラスタを備えたマルチノードアーキテクチャが完成します。 アーキテクチャの例として、3ノードクラスタについて説明します。
os-node1os-node2os-node3
HAProxy のインストールと設定
On another machine, we will install and configure the HAProxy balancer.
In our case, we will do this on the same machine where we have the Pandora FMS node with Rocky Linux 9 OS. However, it can be a separate machine for this purpose.
別のマシンに HAProxy バランサをインストールして設定します。
今回のケースでは、Rocky Linux 9 OS を搭載した Pandora FMS ノードと同じマシンでこれを行いますが、別のマシンでも構いません。
We will install the HAProxy and Vim packages to edit the configuration files (if it is a Pandora FMS node, Vim should already be installed by default).
設定ファイルを編集するために、HAProxy および Vim パッケージをインストールします (Pandora FMS ノードの場合は、Vim はデフォルトですでにインストールされているはずです)。
dnf install -y haproxy vim
Once installed, we will make a copy of the default HAProxy configuration file.
インストールが完了したら、デフォルトの HAProxy 設定ファイルのコピーを作成します。
cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.default
Now we will edit the file /etc/haproxy/haproxy.cfg with the following configuration:
ここで、次の設定でファイル /etc/haproxy/haproxy.cfg を編集します。
global #log /dev/log local0 log /dev/log local1 notice maxconn 4096 user haproxy group haproxy daemon tune.ssl.default-dh-param 2048 defaults log global mode http #option httplog option dontlognull timeout connect 5s timeout client 30s timeout server 30s retries 3 # ==================================== # Frontend -- HTTP # ==================================== frontend opensearch_frontend #bind *:9200 bind *:9200 ssl crt /etc/haproxy/certs/haproxy.pem default_backend opensearch_backend # ==================================== # Backend -- Nodos HTTPS con auth # ==================================== backend opensearch_backend balance roundrobin # Conectar a backends HTTPS server node1 <ip-node1>:9200 ssl verify none check server node2 <ip-node2>:9200 ssl verify none check server node3 <ip-node3>:9200 ssl verify none check # ==================================== # Stats page optional # ==================================== listen stats bind *:8404 mode http stats enable stats uri /haproxy?stats stats refresh 10s stats auth admin:Pandor4!
Replace <ip-nodex> with the IP address of each OpenSearch node in our cluster and add more nodes following the same format if you have a larger cluster.
Save and exit.
<ip-nodex> をクラスター内の各 OpenSearch ノードの IP アドレスに置き換え、クラスターが大きい場合は同じ形式に従ってノードを追加します。
保存して終了します。
This is a reference configuration file, so some options can be configured according to the needs of the environment, such as timeouts, retries, or SSL certificate verification.
これは参考の設定ファイルなので、タイムアウト、再試行、SSL 証明書の検証など、環境のニーズに応じていくつかのオプションを設定できます。
統計ページ
We have added a stats URL to the configuration, which will be useful for monitoring the status of HAProxy. This is optional and can be disabled by deleting the block starting with Stats page optional.
設定に統計 URL を追加します。これは HAProxy の状態監視に役立ちます。これはオプションであり、Stats page optional で始まるブロックを削除することで無効にできます。
It is also possible to restrict access by limiting the exposed IP address, changing the port, or changing the access credentials.
In our case, the statics website will remain at
公開IPアドレスを制限したり、ポートを変更したり、アクセス認証情報を変更したりすることでアクセスを制限することもできます。
この例では、統計情報ウェブサイトは以下の通りです。
http://<nodo.pandorafms>:8404/haproxy?stats
With the credentials admin:Pandor4!.
認証情報 admin:Pandor4! を使用します。
HTTPS HAProxy の証明書
As we can see, we refer to a certificate
ご覧のとおり、以下の証明書を参照が、
bind *:9200 ssl crt /etc/haproxy/certs/haproxy.pem
in the configuration file. In production, it is best to use an official certificate signed by a trusted CA. For lab testing, we will use a self-generated certificate that we will create with the commands:
設定ファイルに記載されています。本番環境では、信頼できる CA によって署名された公式証明書を使用するのが最適です。ラボテストでは、以下のコマンドで作成した自己生成証明書を使用します。
sudo mkdir -p /etc/haproxy/certs # Generate private key and self-signed certificate sudo openssl req -x509 -nodes -days 365 \ -newkey rsa:2048 \ -keyout /etc/haproxy/certs/haproxy.key \ -out /etc/haproxy/certs/haproxy.crt \ -subj "/CN=haproxy.local"
Now we will create a .pem file by concatenating the key and the certificate. If using a valid certificate, the steps will be similar, but using the certificate files.
次に、鍵と証明書を連結して .pem ファイルを作成します。有効な証明書を使用する場合は、証明書ファイルを使用する点を除き、手順は同様です。
# Combine certificate and key into a single file (required by HAProxy) sudo cat /etc/haproxy/certs/haproxy.key /etc/haproxy/certs/haproxy.crt > /etc/haproxy/certs/haproxy.pem
We restarted the HAProxy service.
HAProxy サービスを再起動します。
systemctl restart haproxy
We verify that we can attack the OpenSearch nodes using HTTPS by running from the terminal of the node where we installed HAProxy:
HAProxy をインストールしたノードのターミナルから実行して、HTTPS を使用して OpenSearch ノードにアクセスできることを確認します。
curl -XGET -ku admin:'P4nd0r4!FMS' "https://127.0.0.1:9200/_cat/nodes?v"
If we make a couple of calls to the API root, we can verify that the calls are balanced between nodes.
API ルートに対して数回の呼び出しを行うと、呼び出しがノード間で分散されていることを確認できます。
curl -XGET -ku admin:'P4nd0r4!FMS' "https://127.0.0.1:9200/
Pandora FMS コンソールでの設定
HAProxy can be in any other instance, but to avoid having to add more machines to our cluster, we have installed it directly on the Pandora FMS node itself, so we will use localhost for our configuration. However, if it has been configured on another machine, you must use that machine's IP address.
HAProxy は他のインスタンスにインストールすることも可能ですが、クラスタにマシンを追加する手間を省くため、Pandora FMS ノード自体に直接インストールしました。そのため、設定には localhost を使用します。ただし、別のマシンに HAProxy が設定されている場合は、そのマシンの IP アドレスを使用する必要があります。
Go to the Pandora FMS console, to the settings section Management → Settings → System Settings → Log collector, and fill in the required fields, activating Use HTTPS if you have configured a certificate.
Pandora FMS コンソールの設定セクション 管理(Management) → セットアップ(Settings) → システム設定(System Settings) → ログ収集(Log collector) に移動し、必要なフィールドに入力して、証明書を設定している場合は HTTPS を使用するを有効にします。
We will see the green check mark indicating that we have configured and connected our OpenSearch with Pandora FMS.
OpenSearch が Pandora FMS に設定され接続されたことを示す緑色のチェックマークが表示されます。




