2021年3月16日火曜日

Splunk 8.1.2を使ってインデクサをクラスタ構成で構築する

以前、Splunkのインストール手順を以下記事にて記載した。

前回は1台のサーバ上にSplunkのすべての機能を持たせる構成としていたが、Splunkは機能単位でサーバを分割し負荷分散と冗長化を実現することができる。

よくある構成として、受信したログを保管する「インデクサ (Indexer)」を複数台のサーバで構成することにより、ログのサーチ時の負荷分散と冗長化を実現することができる。この構成をインデクサのクラスタ構成 (Indexer clusters) と呼ぶ。

本記事では、Splunk 8.1.2を使って2台のインデクサをクラスタ構成として構築する手順を記載する。

環境

インデクサをクラスタ構成にするにあたり、Manager Nodeと呼ばれる管理ノードやSearch Headを個別のサーバに分けて導入する必要がある。

これは、マニュアルにも以下の通り記載されている。

These are the main issues to note:

  • Each cluster node (manager, peer, or search head) must reside on a separate Splunk Enterprise instance.
  • Each node instance must run on a separate machine or virtual machine, and each machine must be running the same operating system and version.
  • All nodes must be connected over a network.
  • There are strict version compatibility requirements between cluster nodes.

引用元 : Managing Indexers and Clusters of Indexers

今回の検証では、ログ送信元となるUniversal Forwarderのサーバを含めると5台のサーバが必要となる。OSはすべてCentOS 7.8、Splunkは8.1.2を使用する。

ホスト名 IPアドレス 種類 台数 説明
t1073spmg 192.168.11.73 Manager Node 1 Splunkの各コンポーネントを管理する。
t1074spsh 192.168.11.74 Search Head 1 Indexerに対して検索を行い結果を表示する。
t1075spin 192.168.11.75 Peer Node (Indexer#1) 1 ログの受信とSearch Headからの検索を受け付ける。Peer Node間でデータがレプリケーションされ冗長化される。
t1076spin 192.168.11.76 Peer Node (Indexer#2) 1 ログの受信とSearch Headからの検索を受け付ける。Peer Node間でデータがレプリケーションされ冗長化される。
t1077spfw 192.168.11.77 Universal Forwarder 1 Peer Nodeに対してログを送信する。

インデクサのクラスタ構成手順

1. CentOS 7構築 (4台)

Splunkは実行に必要なモジュールがインストーラ内にすべて含まれているため、CentOSのインストールは最小限のインストールを選択すれば問題ない。

インストール作業簡略化のため、firewalldとSELinuxは停止しておく。

# systemctl stop firewalld
# systemctl disable firewalld
# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
# setenforce 0

2. 各サーバ (4台) にSplunkインストール

Splunkのインストーラであるtgz形式のファイルを/optに解凍し、初回起動及び自動起動設定を行うことでインストールを完了させる。

初回起動時は、通常ではライセンス規約への同意と管理ユーザのパスワード設定が求められるが、CLIではオプションとして指定することができる。

設定項目 説明
--accept-license ライセンス規約へ同意する。
--answer-yes Yes/Noで回答かのうな質問はすべてYesで回答する。
--seed-passwd <パスワード> 管理ユーザadminのパスワードを設定する。
# tar xvzf splunk-8.1.2-545206cc9f70-Linux-x86_64.tgz -C /opt
# /opt/splunk/bin/splunk start --accept-license --answer-yes --seed-passwd my_password
# /opt/splunk/bin/splunk enable boot-start

3. Manager Node構築

まずはSplunkの各コンポーネントの管理を司るManager Nodeを構築する。今回はPeer Nodeは2台となるためreplication_factorsearch_factorは2で設定する。secretはこの後構成するPeer NodeやSearch Headで同一のものを指定する。

設定項目 (CLI) 設定項目 (GUI) 設定値
mode - manager ※8.1未満の場合はmasterで指定
replication_factor 複製データ保持数 2
search_factor サーチ可能データ保持数 2
secret セキュリティキー P@ssw0rd
cluster_label クラスターラベル Cluster-01

SplunkWebのGUIによる設定できるが、今回はCLIを使って設定する。

[root@t1073spmg ~]# /opt/splunk/bin/splunk edit cluster-config -mode manager -replication_factor 2 -search_factor 2 -secret P@ssw0rd -cluster_label Cluster-01 -auth admin:my_password
The cluster-config property has been edited.
You need to restart the Splunk Server (splunkd) for your changes to take effect.
[root@t1073spmg ~]# /opt/splunk/bin/splunk restart

4. Peer Node構築

Peer Nodeは2台構築する。それぞれのサーバで同じコマンドにて設定することができる。設定項目は以下の通りとなる。

設定項目 (CLI) 設定項目 (GUI) 設定値
mode - peer ※8.1未満の場合はslaveで指定
master_uri マスターURI https://192.168.11.73:8089
replication_port ピア複製用ポート 9887
secret セキュリティキー P@ssw0rd

1台目 : t1075spin

CLIにてPeer Nodeを構成する。

[root@t1075spin ~]# /opt/splunk/bin/splunk edit cluster-config -mode peer -master_uri https://192.168.11.73:8089 -replication_port 9887 -secret P@ssw0rd -auth admin:my_password
The cluster-config property has been edited.
You need to restart the Splunk Server (splunkd) for your changes to take effect.
[root@t1075spin ~]# /opt/splunk/bin/splunk restart

デフォルトでは受信用のポートがないため、9997番ポートを開放する設定を行う。

[root@t1075spin ~]# /opt/splunk/bin/splunk enable listen 9997 -auth admin:my_password
Listening for Splunk data on TCP port 9997.
[root@t1075spin ~]# /opt/splunk/bin/splunk restart

2台目 : t1076spin

CLIにてPeer Nodeを構成する。

[root@t1076spin ~]# /opt/splunk/bin/splunk edit cluster-config -mode peer -master_uri https://192.168.11.73:8089 -replication_port 9887 -secret P@ssw0rd -auth admin:my_password
The cluster-config property has been edited.
You need to restart the Splunk Server (splunkd) for your changes to take effect.
[root@t1076spin ~]# /opt/splunk/bin/splunk restart

デフォルトでは受信用のポートがないため、9997番ポートを開放する設定を行う。

[root@t1076spin ~]# /opt/splunk/bin/splunk enable listen 9997 -auth admin:my_password
Listening for Splunk data on TCP port 9997.
[root@t1076spin ~]# /opt/splunk/bin/splunk restart

5. Search Head構築

CLIにてSearch Headを構成する。

設定項目 (CLI) 設定項目 (GUI) 設定値
mode - searchhead
master_uri マスターURI https://192.168.11.73:8089
secret セキュリティキー P@ssw0rd
[root@t1074spsh ~]# /opt/splunk/bin/splunk edit cluster-config -mode searchhead -master_uri https://192.168.11.73:8089 -secret P@ssw0rd -auth admin:my_password
The cluster-config property has been edited.
You need to restart the Splunk Server (splunkd) for your changes to take effect.
[root@t1074spsh ~]# /opt/splunk/bin/splunk restart

6. Manager NodeのログをPeer Nodeに転送

特に何も設定しない場合、Manager NodeのSplunkの内部ログは、Manager Node内のIndexerに保存されてしまう。この場合、Manager Nodeの内部ログはManager Nodeから検索しなければ表示させることができず管理面で煩雑となることから、Peer Nodeにログを転送することでログを統合しSearch Headから検索できるようにする。

設定はManager Nodeのoutputs.confを直接編集する。

[root@t1073spmg local]# cat << EOF >> /opt/splunk/etc/system/local/outputs.conf
# Turn off indexing on the manager node
[indexAndForward]
index = false

[tcpout]
defaultGroup = my_peers_nodes
forwardedindex.filter.disable = true
indexAndForward = false
 
[tcpout:my_peers_nodes]
server = 192.168.11.75:9997,192.168.11.76:9997
EOF
[root@t1073spmg local]# /opt/splunk/bin/splunk restart -auth admin:my_password

7. Universal ForwarderからPeer Nodeにログ転送

最後にUniversal ForwarderからPeer Nodeにログを転送する設定を行う。設定はoutputs.confを直接編集する。

[root@t1077spfw ~]# cat << EOF >> /opt/splunkforwarder/etc/system/local/outputs.conf
[tcpout]
defaultGroup = my_peers_nodes

[tcpout:my_peers_nodes]
server=192.168.11.75:9997,192.168.11.76:9997
useACK=true
EOF
[root@t1077spfw ~]# /opt/splunkforwarder/bin/splunk restart -auth admin:my_password

splunk list forward-serverコマンドにて転送先のPeer Nodeを確認することができる。Universal Forwarder再起動直後はInactive forwardsと表示されるが、しばらくすると2台のPeer NodeがActive forwardsに表示されるようになるはずだ。

[root@t1077spfw ~]# /opt/splunkforwarder/bin/splunk list forward-server
Active forwards:
        192.168.11.75:9997
        192.168.11.76:9997
Configured but inactive forwards:
        None

動作確認

それでは、実際にUniversal ForwarderからPeer Nodeにログを送信し、Search Headからサーチできることを確認してみよう。

ログの送信はsplunk add oneshot <ログファイル>にて実施する。

[root@t1077spfw local]# /opt/splunkforwarder/bin/splunk add oneshot /var/log/messages -auth admin:my_password
Oneshot '/var/log/messages' added

Search Headでサーチすると、送信したログが表示されることを確認できた。

以上でSplunkのインデクサをクラスタ構成で構築する手順は完了となる。慣れてしまえば、30分あれば構築することができる。

0 件のコメント:

コメントを投稿

人気の投稿