splunkでIndex Clusterを構成して、データを冗長化する。
Splunkでは、データの冗長を行うためにClusterが構成できるようになっています。
Clusteに必要なコンポーネントして
- Searchhead
- Indexer (最低2台以上 / 基本は3台から )
- Cluster Master (searchhead / indexerとは同居させない)
基本的な動作
公式ドキュメントを参照してもらうのが良き。
https://docs.splunk.com/Documentation/Splunk/7.2.4/Indexer/Aboutclusters
-
Searcheadから見た場合(検索)
検索実行時には、SeachheadはCluster Masterに問い合わせを行い、どのノードがどのデータを持っているかの問い合わせを行って
検索を行う -
Indexerの場合(データ取り込み)
データを取り込む際は、設定されたRF(生データ)/SF(RFから生成される検索用のデータ)に従い、indexerのノード間で
データのレプリケーションを行う。
デフォルトではRF:3 / SF:2の状態となり、各ノード間でそれぞれデータを保持する形となる。
また、primaryのデータを持つNodeがダウンした場合は、他のNodeにデータをreplicationし、上記のSF/RFを保つように動作する。
設定方法
設定方法はGUIもしくはCLIから実行可能。
設定順番は、Clustermaster → Indexer → SearchHeadの順番。
ClusterMasterの場合
# cluster master構成 (secret keyは指定必須)
[root@suda-cm01 ec2-user]# /opt/splunk/bin/splunk edit cluster-config -mode master -replication_factor 2 -search_factor 2 -secret abc12345 -cluster_label cluster1
Your session is invalid. Please login.
Splunk username: admin
Password:
The cluster-config property has been edited.
You need to restart the Splunk Server (splunkd) for your changes to take effect.
[root@suda-cm01 ec2-user]#
# Splunk restart
[root@suda-cm01 ec2-user]# /opt/splunk/bin/splunk restart
Indexerの場合(各Indexerで実施)
# indexer構成
[root@suda-idx01 ec2-user]# /opt/splunk/bin/splunk edit cluster-config -mode slave -master_uri https://172.31.20.62:8089 -replication_port 9200 -secret abc12345
Your session is invalid. Please login.
Splunk username: admin
Password:
The cluster-config property has been edited.
You need to restart the Splunk Server (splunkd) for your changes to take effect.
[root@suda-idx01 ec2-user]#
# Splunk restart
[root@suda-idx01 ec2-user]# /opt/splunk/bin/splunk restart
SearchHeadの場合
# searchhead構成
[root@suda-sh01 ec2-user]# /opt/splunk/bin/splunk edit cluster-config -mode searchhead -master_uri https://172.31.20.62:8089 -secret abc12345
Your session is invalid. Please login.
Splunk username: admin
Password:
The cluster-config property has been edited.
You need to restart the Splunk Server (splunkd) for your changes to take effect.
[root@suda-sh01 ec2-user]#
# splunk restart
/opt/splunk/bin/splunk restart
設定後の確認
Search Headからノードが確認できること。
※SearchHead / ClusterMasterに下記の設定をoutputs.confに入れておくことで、Indexer側にログを転送かつStoreできるので便利。
# Turn off indexing on the search head
[indexAndForward]
index = false
[tcpout]
defaultGroup = my_search_peers
forwardedindex.filter.disable = true
indexAndForward = false
[tcpout:my_search_peers]
server=xxx.xxx.xxx.xxx:9997,xxx.xxx.xxx.xxx:9997,xxx.xxx.xxx.xxx:9997
Cluster Masterからの確認
GUIでログイン後、右上menuのSetting→ IndexClusteringに移動して
- All Data is Searchable
- Search Factor is Met
- Replication Factor is Me
になっていることを確認する。
Indexclusterへの設定配布方法
IndexCluster環境の場合、Cluster Masterから各種設定を配布しなければならない。
ClusterMasterにSSHでログイン後、下記パスに展開したいファイルを格納
[root@suda-cm01 ec2-user]# cd /opt/splunk/etc/master-apps/
[root@suda-cm01 master-apps]# ls
_cluster
[root@suda-cm01 master-apps]#
# _cluster/local配下にファイルを配置してみる。
## Appなどの場合は、master-apps配下でOK
[root@suda-cm01 local]# cat indexes.conf
# Without repFactor = auto (or a number, dictating the number of copies),
# indexes won't be replicated from one peer to another. This setting applies
# a global setting of "auto". Without this, the default repFactor is zero (0).
[default]
repFactor = auto
[root@suda-cm01 local]# pwd
/opt/splunk/etc/master-apps/_cluster/local
[root@suda-cm01 local]# ls
README indexes.conf
ファイルを各indexerに展開してみる
展開するファイル、パラメータによってindexerの再起動がかかる場合があるので注意。
[root@suda-cm01 local]# /opt/splunk/bin/splunk apply cluster-bundle
Warning: Under some circumstances, this command will initiate a rolling restart of all peers. This depends on the contents of the configuration bundle. For details, refer to the documentation. Do you wish to continue? [y/n]: y
Your session is invalid. Please login.
Splunk username: admin
Password:
Created new bundle with checksum=F461378D14579C4214E2FE83C946429F
Applying new bundle. The peers may restart depending on the configurations in applied bundle.
Please run 'splunk show cluster-bundle-status' for checking the status of the applied bundle.
OK
[root@suda-cm01 local]#
展開状態確認
active_bundleが各ノードで一致してること、statusがupなこと、last_bundle_validation_status=successなどを確認する。
[root@suda-cm01 local]# /opt/splunk/bin/splunk show cluster-bundle-status
master
cluster_status=None
active_bundle
checksum=F461378D14579C4214E2FE83C946429F
timestamp=1553334028 (in localtime=Sat Mar 23 09:40:28 2019)
latest_bundle
checksum=F461378D14579C4214E2FE83C946429F
timestamp=1553334028 (in localtime=Sat Mar 23 09:40:28 2019)
last_validated_bundle
checksum=F461378D14579C4214E2FE83C946429F
last_validation_succeeded=1
timestamp=1553334028 (in localtime=Sat Mar 23 09:40:28 2019)
last_check_restart_bundle
last_check_restart_result=restart not required
checksum=
timestamp=0 (in localtime=Thu Jan 1 00:00:00 1970)
suda-idx02 0311CB54-DD8B-4A03-B4FE-BF4D2CABF37C default
active_bundle=F461378D14579C4214E2FE83C946429F
latest_bundle=F461378D14579C4214E2FE83C946429F
last_validated_bundle=F461378D14579C4214E2FE83C946429F
last_bundle_validation_status=success
restart_required_apply_bundle=0
status=Up
suda-idx01 61E6F06F-82B2-4455-9376-6053896DD120 default
active_bundle=F461378D14579C4214E2FE83C946429F
latest_bundle=F461378D14579C4214E2FE83C946429F
last_validated_bundle=F461378D14579C4214E2FE83C946429F
last_bundle_validation_status=success
restart_required_apply_bundle=0
status=Up
[root@suda-cm01 local]#
indexer側は、$SPLUNK_HOME/etc/slave_apps配下にファイルが展開されていればOK
[root@suda-idx01 ec2-user]# cat /opt/splunk/etc/slave-apps/_cluster/local/indexes.conf
# Without repFactor = auto (or a number, dictating the number of copies),
# indexes won't be replicated from one peer to another. This setting applies
# a global setting of "auto". Without this, the default repFactor is zero (0).
[default]
repFactor = auto
[root@suda-idx01 ec2-user]#