ラベル Splunk の投稿を表示しています。 すべての投稿を表示
ラベル Splunk の投稿を表示しています。 すべての投稿を表示
2024年8月25日日曜日

Splunk本体とUniversal ForwarderをAlmaLinux 9にインストールする手順

自宅環境にてログ集約と解析ができるようにログ管理基盤を作ることにした。ログ解析にはSplunk を利用する方針とした。本記事では、Splunk本体とUniversal ForwarderをAlmaLinux 9にインストールする手順を記載する。

以下は自宅のログ管理基盤の構成概要図となる。赤枠個所が本記事の範囲となる。

環境

環境は以下の通りとなる。Splunk本体とUniversal Forwarderを導入するサーバーは別サーバーとしている。

  • OS : AlmaLinux 9.4
  • Splunk : 9.0.3
  • Splunk Universal Forwarder : 9.0.3

Splunkのインストール

1. Splunkインストーラのダウンロード

Splunkは以下URLからダウンロードできる。ダウンロードするためにはアカウント作成が必要となる。

https://www.splunk.com/ja_jp/download/splunk-enterprise.html

Linux版は、.deb.rpm.tgzの3点が選べるが、個人的お勧めは.tgzとなる。本手順も.tgzによるインストールを記載する。

2. インストール

ダウンロードしたファイル(本手順ではsplunk-9.3.0-51ccf43db5bd-Linux-x86_64.tgzというファイル名となる)をサーバーに配置し、以下コマンドで展開するのみでインストールは完了する。

tar xvzf splunk-9.3.0-51ccf43db5bd-Linux-x86_64.tgz -C /opt

3. Splunkの初回起動と初期設定

/opt/splunk/binディレクトリにSplunk本体の実行ファイルがあるので、以下の通り実行することで、初回起動時の以下処理が実行される。

  • ライセンス条項に同意
  • 管理ユーザ名の設定 (デフォルトはadmin)
  • 管理ユーザのパスワードの設定
# cd /opt/splunk/bin/
# ./splunk start
SPLUNK GENERAL TERMS

Last Updated: August 12, 2021

These Splunk General Terms ("General Terms") between Splunk Inc., a Delaware
corporation, with its principal place of business at 270 Brannan Street, San
Francisco, California 94107, U.S.A ("Splunk" or "we" or "us" or "our") and you
("Customer" or "you" or "your") apply to the purchase of licenses and
subscriptions for Splunk's Offerings. By clicking on the appropriate button,
or by downloading, installing, accessing or using the Offerings, you agree to
these General Terms. If you are entering into these General Terms on behalf of
Customer, you represent that you have the authority to bind Customer. If you
do not agree to these General Terms, or if you are not authorized to accept
the General Terms on behalf of the Customer, do not download, install, access,
or use any of the Offerings.

~(中略)~

Do you agree with this license? [y/n]: y ←★"y"を入力

This appears to be your first time running this version of Splunk.

Splunk software must create an administrator account during startup. Otherwise, you cannot log in.
Create credentials for the administrator account.
Characters do not appear on the screen when you type in credentials.

Please enter an administrator username: admin ←★管理者ユーザ名を入力
Password must contain at least:
   * 8 total printable ASCII character(s).
Please enter a new password:     ←★パスワードを入力
Please confirm new password:     ←★パスワードを再入力
Copying '/opt/splunk/etc/openldap/ldap.conf.default' to '/opt/splunk/etc/openldap/ldap.conf'.

~(中略)~

The Splunk web interface is at http://example:8000

5. 自動起動設定

.tgzファイルを解凍しただけなので、これだけではサーバ再起動時に自動起動してくれないため、コマンドで自動起動するよう設定する。ただし、AlmaLinux 9などのRHEL 9系においてchkconfigパッケージがインストールされていない場合、以下の通りエラーが発生する。

# /opt/splunk/bin/splunk enable boot-start
Can't create RC file "/etc/init.d/splunk": No such file or directory

そのため、chkconfigパッケージがインストールされていない場合はインストールを事前に行っておく。

# dnf install chkconfig -y

chkconfigインストール後、以下の通り実行し、自動起動設定を行う。

# /opt/splunk/bin/splunk enable boot-start
Init script installed at /etc/init.d/splunk.
Init script is configured to run at boot.

試しに再起動を行ったのちステータスを確認したところ、問題なくSplunkが「running」ステータスとなっていた。

# reboot

# uptime
 10:26:23 up 0 min,  1 user,  load average: 0.14, 0.03, 0.01
# /opt/splunk/bin/splunk status
splunkd is running (PID: 1411).
splunk helpers are running (PIDs: 1412 1565 1570 1799 1864).

6. 管理Web画面にアクセス

以上を実施したのち「http://<インストールしたホスト名 or IPアドレス>:8000」にアクセスすると、管理画面が表示されるはずなので、初回起動時に設定した管理者ユーザとパスワードでログインしてみよう。

ログインに成功すると、以下のようなSplunk の管理画面が表示される。

7. Splunk Universal Forwarderからの受信許可設定

管理画面の右上の「設定」 > 「転送と受信」を選択し、「受信の設定」の「+新規追加」ボタンを押しておく。

受信ポートは9997を設定し、「保存」を選択する。

Splunk Universal Forwarderのインストール

1. Splunk Universal Forwarderインストーラのダウンロード

Splunk Universal Forwarderは以下URLからダウンロードできる。ダウンロードするためにはアカウント作成が必要となる。

https://www.splunk.com/ja_jp/download/universal-forwarder.html

Linux版は、.deb.rpm.tgzの3点が選べるが、個人的お勧めは.tgzとなる。本手順も.tgzによるインストールを記載する。

2. インストール

ダウンロードしたファイル(本手順ではsplunkforwarder-9.3.0-51ccf43db5bd-Linux-x86_64.tgzというファイル名となる)をサーバーに配置し、以下コマンドで展開するのみでインストールは完了する。

# tar xvzf splunkforwarder-9.3.0-51ccf43db5bd-Linux-x86_64.tgz -C /opt/

3. Splunkの初回起動と初期設定

/opt/splunk/binディレクトリにSplunk本体の実行ファイルがあるので、以下の通り実行することで、初回起動時の以下処理が実行される。

  • ライセンス条項に同意
  • 管理ユーザ名の設定 (デフォルトはadmin)
  • 管理ユーザのパスワードの設定
# cd /opt/splunkforwarder/bin/
# ./splunk start
SPLUNK GENERAL TERMS

Last Updated: August 12, 2021

These Splunk General Terms ("General Terms") between Splunk Inc., a Delaware
corporation, with its principal place of business at 270 Brannan Street, San
Francisco, California 94107, U.S.A ("Splunk" or "we" or "us" or "our") and you
("Customer" or "you" or "your") apply to the purchase of licenses and
subscriptions for Splunk's Offerings. By clicking on the appropriate button,
or by downloading, installing, accessing or using the Offerings, you agree to
these General Terms. If you are entering into these General Terms on behalf of
Customer, you represent that you have the authority to bind Customer. If you
do not agree to these General Terms, or if you are not authorized to accept
the General Terms on behalf of the Customer, do not download, install, access,
or use any of the Offerings.

~(中略)~

Do you agree with this license? [y/n]: y ←★"y"を入力

This appears to be your first time running this version of Splunk.

Splunk software must create an administrator account during startup. Otherwise, you cannot log in.
Create credentials for the administrator account.
Characters do not appear on the screen when you type in credentials.

Please enter an administrator username: admin ←★管理者ユーザ名を入力
Password must contain at least:
   * 8 total printable ASCII character(s).
Please enter a new password:      ←★パスワードを入力
Please confirm new password:      ←★パスワードを再入力
Creating unit file...
Initd script /etc/init.d/splunk exists. splunk is currently enabled as init.d bootstart service.
Please run "splunk disable boot-start" first to disable it as init.d boot-start service
Failed to create the unit file. Please do it manually later.

~(中略)~

All preliminary checks passed.

Starting splunk server daemon (splunkd)...  
PYTHONHTTPSVERIFY is set to 0 in splunk-launch.conf disabling certificate validation for the httplib and urllib libraries shipped with the embedded Python interpreter; must be set to "1" for increased security
Done

5. 自動起動設定

.tgzファイルを解凍しただけなので、これだけではサーバ再起動時に自動起動してくれないため、コマンドで自動起動するよう設定する。Splunk本体と異なり、-user rootによる起動時の実行ユーザー指定が必要であり、かつsystemdによる登録となっており、chkconfigパッケージの導入は不要となる。

# /opt/splunkforwarder/bin/splunk stop
# /opt/splunkforwarder/bin/splunk enable boot-start -user root
Systemd unit file installed by user at /etc/systemd/system/SplunkForwarder.service.
Configured as systemd managed service.
# systemctl status SplunkForwarder
○ SplunkForwarder.service - Systemd service file for Splunk, generated by 'splunk enable boot-start'
     Loaded: loaded (/etc/systemd/system/SplunkForwarder.service; enabled; preset: disabled)
     Active: inactive (dead)
# systemctl start SplunkForwarder

6. 送信先のサーバ (インデクサー) を設定

Splunkのログ受信および解析を行う機能を「インデクサー」と呼ぶ。Universal Forwarderのログ送信先としてインデクサーを指定する必要があるため、splunk add forward-server <インデクサーのIPアドレス or ホスト名>:<ポート番号>コマンドにて行う。

# cd /opt/splunkforwarder/bin/
# ./splunk add forward-server 192.168.1.1:9997
Splunk username: admin
Password:
Added forwarding to: 192.168.1.1:9997.
# ./splunk list forward-server
Active forwards:
        None
Configured but inactive forwards:
        192.168.1.1:9997

本設定は、/opt/splunkforwarder/etc/system/local/outputs.confに記述される。

# cat /opt/splunkforwarder/etc/system/local/outputs.conf
[tcpout]
defaultGroup = default-autolb-group

[tcpout:default-autolb-group]
server = 192.168.1.1:9997

[tcpout-server://192.168.1.1:9997]

7. モニター対象のログを追加

今回は例として/var/log配下のログをすべて監視対象として、Splunk本体のインデクサーに送信する。splunk add monitor <モニター対象のファイル or ディレクトリ>コマンドで設定する。なお、本設定は再起動は不要で反映される。

# cd /opt/splunkforwarder/bin/
# ./splunk add monitor /var/log
Added monitor of '/var/log'.

splunk list monitorで設定確認を行う。ディレクトリが登録され、ディレクトリ内の各ファイルが表示されていれば問題ない。

# ./splunk list monitor
Monitored Directories:
	$SPLUNK_HOME/var/log/splunk
		/opt/splunkforwarder/var/log/splunk/audit.log
		/opt/splunkforwarder/var/log/splunk/btool.log
		/opt/splunkforwarder/var/log/splunk/conf.log

~(中略)~
	$SPLUNK_HOME/var/run/splunk/search_telemetry/*search_telemetry.json
	$SPLUNK_HOME/var/spool/splunk/tracker.log*
		/opt/splunkforwarder/var/spool/splunk/tracker.log
	/var/log ←★/var/log配下のログが追加されている。
		/var/log/anaconda
		/var/log/anaconda/anaconda.log
		/var/log/anaconda/dbus.log

~(以下略)~

8. 受信確認

Splunkにログインし「Search & Reporting」にて、index=*にてサーチを行い、ログが表示されることを確認しよう。

以上で、Splunk本体とUniversal ForwarderをAlmaLinux 9にインストールする手順は完了となる。

2021年10月9日土曜日

Splunkのライセンスを評価版からFreeライセンスに変更する手順

Splunkはインストール後60日間は、Splunk Enterpriseの評価版として動作し、すべての機能を制限なく使用することができる。60日経過するとEnterpriseトライアルライセンスの期限切れにより、ログのサーチを含むすべての操作ができなくなるが、Freeライセンスに変更することで、機能制限が加わるもののログのサーチ等の基本的な機能は継続して使用することができる。

EnterpriseライセンスとFreeライセンスの機能差異は、以下URLにて確認いただきたい。

本記事では、インストール後60日が経過したSplunkに対して、Freeライセンスへ変更する手順を記載する。

環境

  • OS : CentOS 7
  • Splunk : 8.1.2

手順

1. 管理Web画面にログイン

評価版のライセンスの期限が切れると、ログイン画面に以下のように「ライセンスが失効しています。管理者としてログインし、ライセンスを更新してください。」のメッセージが表示される。

ログイン自体はできるので、管理者アカウントであるadminユーザでログインを行う。

2. ライセンス画面を表示

管理Web画面上部の[設定]→[ライセンス]を選択し、ライセンス画面を表示させる。

「Trialライセンスグループ」となっていることを確認する。

3. ライセンスグループの変更画面を表示

[ライセンスグループの変更]ボタンを選択する。

4. ライセンスグループを変更

ライセンスグループを「Enterpriseトライアルライセンス」から「フリーライセンス」に変更し、[保存]ボタンを選択する。

5. Splunk再起動

ライセンスグループの変更を有効にする場合は、Splunkの再起動が必要な旨表示されるので、[今すぐ再起動]ボタンを選択する。

6. ライセンスの変更を確認

ログイン画面に戻るので、再度adminユーザにてログインする。

管理Web画面上部の[設定]→[ライセンス]を選択し、ライセンス画面を表示させ、「Freeライセンスグループ」に変更されていることを確認する。

以上で、SplunkのFreeライセンスへの変更作業は完了となる。

2021年4月6日火曜日

Splunkのインデクサをクラスタ構成した環境で新規インデックスを作成する

先日、Splunkにて複数台のインデクサによるクラスタ構成の構築手順やバージョンアップ手順を記載した。

インデクサはログを保存する領域を「インデックス」と呼ぶ。インデクサクラスタ構成では単体のインデクサの構成と異なり、インデックスの情報はManager Nodeが保持している。したがって、インデックスを新規に作成する場合は、まずManager Nodeにて設定したのち、その設定情報を各インデクサに適用するという流れとなる。

今回、2台のインデクサを持つクラスタ構成のSplunk環境にて、新規インデックスをManager Nodeにて設定し、各インデクサに設定の適応する手順を検証した。

環境

今回の検証では、ログ送信元となるUniversal Forwarderのサーバを含めると5台のサーバが必要となる。OSはすべてCentOS 7.8を使用する。インデクサのクラスタ構成のインストール手順は以下記事を参照いただきたい。

ホスト名 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. Manager Nodeにてインデックス設定を実施

インデクサをクラスタ構成している場合は、インデックスの設定ファイルであるindexes.confをManager Nodeにて設定し、その設定情報をPeer Nodeに展開する。

ただし、indexes.confはSplunk Webから設定することはできないため、CLIにて設定ファイルを直接編集し、設定する必要がある。
※Splunk Webで設定できないことは、マニュアルにも以下の通り記載がされている。

Important: You cannot use Splunk Web or the CLI to configure index settings on peer nodes. You must edit indexes.conf directly.
引用元 : Configure the peer indexes in an indexer cluster

従って、SSHなどでOSにログインして、indexes.confを直接編集する。Peer Node用の設定ファイル配置ディレクトリは、/opt/splunk/etc/master-apps/_cluster/local/となる。今回は例としてtest_indexという名前のインデックスを作成することとし、以下のようにindexes.confを作成する。

# vi /opt/splunk/etc/master-apps/_cluster/local/indexes.conf
[test_index]
repFactor = auto
coldPath = $SPLUNK_DB/test_index/colddb
enableDataIntegrityControl = 0
enableTsidxReduction = 0
homePath = $SPLUNK_DB/test_index/db
maxTotalDataSizeMB = 512000
thawedPath = $SPLUNK_DB/test_index/thaweddb

2. 設定バンドルの検証

Manager Nodeが保持しているPeer Nodeへ配布する設定情報を「設定バンドル」と呼ぶ。設定バンドルの展開前にsplunk validate cluster-bundleコマンドを使用して、Peer Node
に対して設定バンドルの更新要否や再起動要否の検証を行う。

設定バンドルが更新されている場合は、下記のようにCreated new bundleと表示される。実際に、Peer Nodeへの適用要否は次の手順にて確認する。

# /opt/splunk/bin/splunk validate cluster-bundle --check-restart -auth admin:my_password
Validating new bundle and checking if its application results in a restart. Please run 'splunk show cluster-bundle-status' to check the status of the bundle validation.
Created new bundle with checksum=FF229E88CDE5C1E8795AC2DDB0E60BD3

3. 設定バンドルの確認

splunk show cluster-bundle-statusコマンドを使って、各Peer Nodeに適用されている設定バンドルと、先ほど検証した設定バンドルの差異を確認する。

出力結果において、確認するポイントは以下となる。

  • active_bundleが適用中の設定バンドルであり、last_validated_bundleが検証した最新の設定バンドルとなる。この2つが異なっている場合は、更新が必要と判断する。
  • last_check_restart_resultは設定バンドルの適用後のSplunkの再起動要否を示す。今回はrestart not requiredと記載されており、再起動は不要であることが確認できる。再起動が必要となる場合はrestart requiredと表示される。
# /opt/splunk/bin/splunk show cluster-bundle-status

master
         cluster_status=None
         active_bundle
                checksum=9D5C0600199B13E786336B83E577576A
                timestamp=1617456895 (in localtime=Sat Apr  3 22:34:55 2021)
         latest_bundle
                checksum=9D5C0600199B13E786336B83E577576A
                timestamp=1617456895 (in localtime=Sat Apr  3 22:34:55 2021)
         last_validated_bundle
                checksum=FF229E88CDE5C1E8795AC2DDB0E60BD3
                last_validation_succeeded=1
                timestamp=1617457038 (in localtime=Sat Apr  3 22:37:18 2021)
         last_check_restart_bundle
                last_check_restart_result=restart not required
                checksum=FF229E88CDE5C1E8795AC2DDB0E60BD3
                timestamp=1617457038 (in localtime=Sat Apr  3 22:37:18 2021)

 t1076spin       AFACC80F-3E52-4B65-9AAC-06E2CEA6575E    default
         active_bundle=9D5C0600199B13E786336B83E577576A
         latest_bundle=9D5C0600199B13E786336B83E577576A
         last_validated_bundle=FF229E88CDE5C1E8795AC2DDB0E60BD3
         last_bundle_validation_status=success
         last_bundle_checked_for_restart=FF229E88CDE5C1E8795AC2DDB0E60BD3
         last_check_restart_result=restart not required
         restart_required_apply_bundle=0
         status=Up

 t1075spin       CDC8B6AA-B56B-471A-A411-36AE8E494A03    default
         active_bundle=9D5C0600199B13E786336B83E577576A
         latest_bundle=9D5C0600199B13E786336B83E577576A
         last_validated_bundle=FF229E88CDE5C1E8795AC2DDB0E60BD3
         last_bundle_validation_status=success
         last_bundle_checked_for_restart=FF229E88CDE5C1E8795AC2DDB0E60BD3
         last_check_restart_result=restart not required
         restart_required_apply_bundle=0
         status=Up

4. 設定バンドルをPeer Nodeに適用

設定バンドルの適用は、splunk apply cluster-bundleにて行う。通常は展開前に確認を求められるが、すべてyesで回答をする場合は、--answer-yesのオプションを付与することでスキップすることができる。

# /opt/splunk/bin/splunk apply cluster-bundle --answer-yes
Created new bundle with checksum=FF229E88CDE5C1E8795AC2DDB0E60BD3
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

もし設定に変更がない場合は、以下の通りNo new bundle will be pushedというメッセージが表示され、設定は更新されない。

# /opt/splunk/bin/splunk apply cluster-bundle --answer-yes

Encountered some errors while applying the bundle.
No new bundle will be pushed. The master and peers already have this bundle with bundle id = 9D5C0600199B13E786336B83E577576A

5. 新規インデックスのログを確認

以上でPeer Nodeに設定が反映されたため、実際にtest_indexのインデックスにログが保管され、Search Headから検索できることを確認する。

Universal Forwarderからインデックスにtest_indexを指定して、/var/log/secureのログを送信する設定を行う。

# ./splunk add monitor "/var/log/secure*" -index test_index
Added monitor of '/var/log/secure*'.

この状態でSearch Headからindex=test_indexをサーチ文として検索をすると、問題なくログが出力された。

また、Manager Nodeにおいても[設定]→[インデクサークラスタリング]の画面にて、test_indexが追加されていることを確認できた。

以上で、インデクサをクラスタ構成にした環境におけるインデックス追加手順は完了となる。

参考

2021年3月23日火曜日

Splunkバージョンアップ手順③ (インデクサをクラスタ構成している場合)

Splunkの各バージョンは、リリース後24か月でサポート終了となるライフサイクルポリシーとなっている。

2021年3月現在、サポート中のバージョンは7.2以降となっており、2021年内に7.2、7.3、8.0がサポート終了となる。

バージョン サポート期限
7.2 2021/4/30
7.3 2021/6/4
8.0 2021/10/22
8.1 2022/10/19

このような状況であるため、以下記事にてSplunkのバージョンアップ手順を記載した。この記事のSplunkは単体構成となっており、1台のサーバに対してバージョンアップすることで対応が完了した。

一方、Splunkは複数のインデクサをクラスタ構成にして負荷分散と冗長化構成とすることが可能であり、そのような構成の場合、バージョンアップ順序が存在し、多少ではあるがバージョンアップ手順が複雑となる。本記事では、Splunkのインデクサをクラスタ構成とした環境におけるバージョンアップ手順の検証結果を記載する。

環境

今回の検証では、ログ送信元となるUniversal Forwarderのサーバを含めると5台のサーバが必要となる。OSはすべてCentOS 7.8を使用する。インデクサのクラスタ構成のインストール手順は以下記事を参照いただきたい。

Splunkは8.0.5で構築済みの状態とし、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に対してログを送信する。

Splunkバージョンアップ手順

1. Splunkのインストーラを配置

Splunkを構成するすべてのサーバに対して、バージョンアップ対象となるインストーラファイル (tgz形式) を配置する。今回は8.1.2にバージョンアップするため、splunk-8.1.2-545206cc9f70-Linux-x86_64.tgzを配置する。

# ls -l
-rw-r--r--. 1 root root 511869044  8月  1  2020 splunk-8.0.5-a1a6394cc5ae-Linux-x86_64.tgz
-rw-r--r--. 1 root root 511782642  3月  3 05:59 splunk-8.1.2-545206cc9f70-Linux-x86_64.tgz

2. Manager Nodeをバージョンアップ

バージョンアップはManager Nodeから実施する。Splunkを停止したのち、tgzファイルを上書きインストールする。その後、Splunkを起動すればバージョンアップの処理が実行されたのち、Splunkが起動する。

なお、初回起動時はライセンス規約への同意とバージョンアップ前確認を求められるので、処理をスキップするために、--accept-license--answer-yesのオプションを付与している。

# /opt/splunk/bin/splunk stop
# tar xvzf splunk-8.1.2-545206cc9f70-Linux-x86_64.tgz -C /opt
# /opt/splunk/bin/splunk start --accept-license --answer-yes

Manager Node起動後、念のためManager NodeのSplunk Webにログインし、[設定]→[インデクサークラスターリング]にて、以下のステータスが「成功」であることを確認しておこう。

  • すべてのデータがサーチ可能
  • サーチ可能データ保持数を満たしています
  • 複製データ保持数を満たしています

Manager Node再起動直後しばらくはエラー表示となるため不安となるものの、数分待機すれば「成功」に変わるはずだ。

▼再起動直後


▼数分後

3. Search Headをバージョンアップ

Manager Nodeがバージョンアップ完了したら、次にSearch Headをバージョンアップする。手順はManager Nodeと同様となる。

# /opt/splunk/bin/splunk stop
# tar xvzf splunk-8.1.2-545206cc9f70-Linux-x86_64.tgz -C /opt
# /opt/splunk/bin/splunk start --accept-license --answer-yes

4. クラスタをメンテナンスモードに変更

次にPeer Nodeをバージョンアップするが、バージョンアップ時はクラスタをメンテナンスモード (保守モード) に変更する必要がある。

メンテナンスモードへの変更はManager Nodeから以下コマンドにて実施する。

# /opt/splunk/bin/splunk show maintenance-mode -auth admin:my_password
  Maintenance mode is : 0,  primaries backup and restore is : 0

# /opt/splunk/bin/splunk enable maintenance-mode --answer-yes
Maintenance mode set

# /opt/splunk/bin/splunk show maintenance-mode
  Maintenance mode is : 1,  primaries backup and restore is : 0

5. Peer Nodeをバージョンアップ

クラスタがメンテナンスモードに変更されたら、Peer Nodeをバージョンアップする。手順はManager Nodeと同様となるが、クラスタのすべてのPeer Nodeで並行して作業を実施する必要があるので注意。

まずは、すべてのPeer NodeにてSplunkを停止する。

# /opt/splunk/bin/splunk stop

次に、すべてのPeer Nodeにてtgzファイルを上書きインストールする。

# tar xvzf splunk-8.1.2-545206cc9f70-Linux-x86_64.tgz -C /opt

最後に、すべてのPeer NodeにてSplunkを起動する。

# /opt/splunk/bin/splunk start --accept-license --answer-yes

6. クラスタのメンテナンスモードを解除

Peer Nodeのバージョンアップが完了したら、Manager Nodeにてメンテナンスモードを解除する。

# /opt/splunk/bin/splunk disable maintenance-mode
No longer in Maintenance mode

# /opt/splunk/bin/splunk show maintenance-mode
  Maintenance mode is : 0,  primaries backup and restore is : 0

最後に、Manager NodeのSplunk Webにて[設定]→[インデクサークラスターリング]を確認し、クラスタの状態が「成功」ステータスとなっていれば問題ない。

以上でSplunkのバージョンアップは完了となる。この後はSplunk Universal Forwarderをバージョンアップすればよい。Universal Forwarderのバージョンアップ手順は以下を参照。

動作確認

最後にバージョンアップ中のログの状態を確認する。今回、Universal Forwarderから1秒間隔でログを送信しながらバージョンアップを行った際にログが欠落していないことを確認してみたところ、一時的にメンテナンスモードにしたことによる影響と想定されるが、一部ログに重複が発生していることを確認した。ただし、ログの欠落はなかったことから、バージョンアップによる停止が発生したとしても、ログの取りこぼしは発生しないことが確認できた。

参考

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分あれば構築することができる。

2021年3月9日火曜日

Splunkバージョンアップ手順② (Universal Forwarderのバージョンアップ)

前回、Splunkの本体のバージョンアップ手順を記載した。

★前回の記事はこちら↓

Splunk本体のバージョンアップが問題なくできたので、今回はUniversal Forwarderのバージョンアップする手順を記載する。

環境

  • OS : CentOS 7
  • Splunk : 8.1.2 ※バージョンアップ済み
  • Splunk Universal Forwarder : 8.0.5から8.1.2へのバージョンアップ
  • Universal Forwarderインストール方法 : tgzファイルを/optに展開

Universal Forwarderバージョンアップ手順

1. Splunkのインストールファイルをダウンロード

インストーラは以下URLからダウンロードできる。ダウンロードするためにはSplunkサイトのユーザ登録が必要となるので注意

ダウンロードしたファイル名はsplunkforwarder-8.1.2-545206cc9f70-Linux-x86_64.tgzとなる。

2. インストールファイルをサーバへアップロード

Tera Termなどのscp機能を使用して、Universal Forwarderのインストールファイルをアップロードする。

今回は/tmpにファイルを配置した。

# ls -l /tmp/splunkforwarder-8.1.2-545206cc9f70-Linux-x86_64.tgz
-rw-r--r--. 1 root root 43433924  3月  3 05:59 /tmp/splunkforwarder-8.1.2-545206cc9f70-Linux-x86_64.tgz

3. Splunkサービス停止

バージョンアップ時は各種ファイルが上書きされるため、Universal Forwarderサービスを停止させる。

# cd /opt/splunkforwarder/bin/
# ./splunk status
splunkd is running (PID: 6480).
splunk helpers are running (PIDs: 6489).

# ./splunk stop
Stopping splunkd...
Shutting down.  Please wait, as this may take a few minutes.
                                                           [  OK  ]
Stopping splunk helpers...
                                                           [  OK  ]
Done.
# ./splunk status
splunkd is not running.

4. ファイルを上書きしてインストール

以下コマンドにて、Universal Forwarderのインストールディレクトリに対して、最新のUniversal Forwarderのファイルを解凍して上書きインストールを行う。

# tar xvzf /tmp/splunkforwarder-8.1.2-545206cc9f70-Linux-x86_64.tgz -C /opt

5. Universal Forwarderを起動

初回起動時はライセンス同意とバージョンアップ前の変更内容確認が求められる。どちらも「y」を入力することでバージョンアップが実行される。

# ./splunk start
~(省略)~

SPLUNK GENERAL TERMS (v1.2020)


Do you agree with this license? [y/n]: y ←★「y」を入力

This appears to be an upgrade of Splunk.
--------------------------------------------------------------------------------)

Splunk has detected an older version of Splunk installed on this machine. To
finish upgrading to the new version, Splunk's installer will automatically
update and alter your current configuration files. Deprecated configuration
files will be renamed with a .deprecated extension.

You can choose to preview the changes that will be made to your configuration
files before proceeding with the migration and upgrade:

If you want to migrate and upgrade without previewing the changes that will be
made to your existing configuration files, choose 'y'.
If you want to see what changes will be made before you proceed with the
upgrade, choose 'n'.


Perform migration and upgrade without previewing configuration changes? [y/n] y
 ↑★「y」を入力
-- Migration information is being logged to '/opt/splunkforwarder/var/log/splunk/migration.log.2021-03-03.07-16-52' --

~(省略)~

All preliminary checks passed.

Starting splunk server daemon (splunkd)...
Done
                                                           [  OK  ]

バージョンアップ後のバージョンを念のため確認しておく。

# ./splunk version
Splunk Universal Forwarder 8.1.2 (build 545206cc9f70)

なお、ライセンス同意やバージョンアップ確認の「y」を選択する作業が面倒な場合は、以下のようにオプションを付与することで、手順をスキップすることができる。

# #ライセンス同意、変更内容確認のみ
# ./splunk start --accept-license --answer-no

# #ライセンス同意、バージョンアップ実施
# ./splunk start --accept-license --answer-yes

6. Splunkにてログが受信できていることを確認

最後にバージョンアップ後にSplunk上でログが受信できていることを検索して確認する。以下の通り、バージョンアップ以降もログ受信ができていることを確認できた。

以上でSplunk本体と同様に、Universal Forwarderのバージョンアップ作業もあっさりと完了となる。

参考

2021年3月4日木曜日

Splunkバージョンアップ手順① (Splunk本体のバージョンアップ)

以前Splunk及びSplunk Universal Forwarderのインストール手順を以下に記載した。

上記記事の中で、Splunkはtgz形式のインストーラの中に必要なモジュールや実行ファイルがすべて含まれており、tgzファイルを所定のディレクトリに解凍するだけでインストールがすぐに完了することを述べた。

さて、Splunkの各バージョンは、リリース後24か月でサポート終了となるライフサイクルポリシーとなっている。

2021年3月現在、サポート中のバージョンは7.2以降となっており、2021年内に7.2、7.3、8.0がサポート終了となるため、該当バージョンを使っている場合はバージョンアップが必要となる。

バージョン サポート期限
7.2 2021/4/30
7.3 2021/6/4
8.0 2021/10/22
8.1 2022/10/19

前回導入したバージョンは8.0.5であり、2021年内にサポート期限を迎えることから、最新の8.1.2にバージョンアップをすることにした。

本記事では2回に分けて①Splunkのバージョンアップ手順と②Universal Forwarderのバージョンアップ手順を記載する。なお、バージョンアップはインストール手順とほぼ同様であり、新しいバージョンのtgzファイルをSplunkのインストールディレクトリに展開するだけですぐに完了することを確認した。

★Splunk Universal Forwarderのバージョンアップ手順はこちら↓

環境

  • OS : CentOS 7
  • Splunk : 8.0.5から8.1.2へのバージョンアップ
  • Splunk Universal Forwarder : 8.0.5 ※本体バージョンアップ後にバージョンアップ実施
  • Splunkインストール方法 : tgzファイルを/optに展開

Splunkバージョンアップ手順

Splunk本体とUniversal Forwarderが存在する場合は、まずSplunk本体 (Indexer) をバージョンアップする。Splunk本体がバージョンアップしたとしても、よほどバージョンが離れていなければ、Universal Forwarderとの互換性が保たれている。互換性の詳細は以下URLにて記載されているが、たとえば本体 (Indexer) が8.xのバージョンであれば、7.x以降のUniversal Forwarderであれば問題なく受信が可能となっている。

1. Splunkのインストールファイルをダウンロード

インストーラは以下URLからダウンロードできる。無料トライアル版もFree版も同じものがダウンロードできる。ダウンロードするためにはSplunkサイトのユーザ登録が必要となるので注意

今回ダウンロードしたファイル名はsplunk-8.1.2-545206cc9f70-Linux-x86_64.tgzとなる。

2. サーバのバックアップを取得

万が一インストールに失敗した場合を想定して、サーバのバックアップを取得する。仮想マシンで構成されている場合は、仮想マシンのスナップショットを取得する。物理サーバの場合は、バックアップソフトなどを利用してバックアップをすること。

3. インストールファイルをサーバへアップロード

Tera Termなどのscp機能を使用して、Splunkのインストールファイルをアップロードする。

今回は/tmpにファイルを配置した。

# ls -l /tmp/splunk-8.1.2-545206cc9f70-Linux-x86_64.tgz
-rw-r--r--. 1 root root 511782642  3月  3 05:59 /tmp/splunk-8.1.2-545206cc9f70-Linux-x86_64.tgz

4. Splunkサービス停止

バージョンアップ時は各種ファイルが上書きされるため、Splunkサービスを停止させる。

# cd /opt/splunk/bin/
# ./splunk status
splunkd is running (PID: 1640).
splunk helpers are running (PIDs: 1642 1659 1795 1857).

# ./splunk stop
Stopping splunkd...
Shutting down.  Please wait, as this may take a few minutes.
..                                                         [  OK  ]
Stopping splunk helpers...
                                                           [  OK  ]
Done.
# ./splunk status
splunkd is not running.

5. ファイルを上書きしてインストール

以下コマンドにて、Splunkのインストールディレクトリに対して、最新のSplunkファイルを解凍して上書きインストールを行う。

# tar xvzf /tmp/splunk-8.1.2-545206cc9f70-Linux-x86_64.tgz -C /opt

6. Splunkを起動

初回起動時はライセンス同意とバージョンアップ前の変更内容確認が求められる。どちらも「y」を入力することでバージョンアップが実行される。

# ./splunk start

SPLUNK GENERAL TERMS

Last updated: February 13, 2020

These Splunk General Terms ("General Terms") between
Splunk Inc., a Delaware corporation, with its principal place
of business at 270 Brannan Street, San Francisco,
California 94107, U.S.A ("Splunk" or "we" or "us" or "our")
and you ("Customer" or "you" or "your") apply to the
purchase of licenses and subscriptions for Splunk's
Offerings. By clicking on the appropriate button, or by
downloading, installing, accessing or using the Offerings,
you agree to these General Terms. If you are entering into
these General Terms on behalf of Customer, you represent
that you have the authority to bind Customer. If you do not
agree to these General Terms, or if you are not authorized
to accept the General Terms on behalf of the Customer, do
not download, install, access, or use any of the Offerings.

See the General Terms Definitions Exhibit attached for
definitions of capitalized terms not defined herein.

1. License Rights

~(省略)~

Do you agree with this license? [y/n]: y ←★「y」を入力

This appears to be an upgrade of Splunk.
--------------------------------------------------------------------------------)

Splunk has detected an older version of Splunk installed on this machine. To
finish upgrading to the new version, Splunk's installer will automatically
update and alter your current configuration files. Deprecated configuration
files will be renamed with a .deprecated extension.

You can choose to preview the changes that will be made to your configuration
files before proceeding with the migration and upgrade:

If you want to migrate and upgrade without previewing the changes that will be
made to your existing configuration files, choose 'y'.
If you want to see what changes will be made before you proceed with the
upgrade, choose 'n'.


Perform migration and upgrade without previewing configuration changes? [y/n] y
 ↑★「y」を入力

-- Migration information is being logged to '/opt/splunk/var/log/splunk/migration.log.2021-03-03.06-20-15' --

~(省略)~

Waiting for web server at http://127.0.0.1:8000 to be available.. Done


If you get stuck, we're here to help.
Look for answers here: http://docs.splunk.com

The Splunk web interface is at http://t1071splk:8000

バージョンアップ後のバージョンを念のため確認しておく。

# ./splunk version
Splunk 8.1.2 (build 545206cc9f70)

なお、ライセンス同意やバージョンアップ確認の「y」を選択する作業が面倒な場合は、以下のようにオプションを付与することで、手順をスキップすることができる。

# #ライセンス同意、変更内容確認のみ
# ./splunk start --accept-license --answer-no

# #ライセンス同意、バージョンアップ実施
# ./splunk start --accept-license --answer-yes

7. 管理Web画面へのアクセスと動作確認

Splunkの管理Web画面 (http://<インストールしたホスト名 or IPアドレス>:8000) にアクセスしログインを行う。管理Web画面からもSplunkのバージョン確認をしたところ問題なく8.1.2になっていることを確認できた。

また、ログのサーチもバージョンアップ以降も問題なく実施できることが確認できた。

以上でSplunkのバージョンアップ作業はあっさりと完了となる。バージョンアップ完了後は、事前に取得したスナップショットやバックアップを削除しておこう。

2020年10月3日土曜日

Splunkでアラートを設定する手順

Splunkでは、ログの検索結果に応じてメール通知やスクリプト実行を行う「アラート」と呼ばれる機能がある。アラート機能を使うことで、例えば、「パスワード失敗のログを検知してメール送信を行う」といったことが実現できる。

今回は、実際にSplunkのアラート機能を使って、「パスワード失敗のログを検知してメール送信を行う」設定をしてみた。なお、アラート設定はSplunkの管理GUIのみを使って設定することができる。

環境

  • Splunk : 8.0.5

Splunkアラート設定手順

1. メール送信設定

アラート機能でメール送信する場合は、事前にメールサーバを設定しておく。管理GUIにて「設定」→「サーバー設定」→「メール設定」にて設定する。

最低限設定する必要がある項目は以下の通り。

設定項目 設定値
メールホスト メールサーバのIPアドレスを指定
リンクホスト名 送信メールに記載されるURL生成時のSplunk本体のホスト名またはIPアドレスを設定
メース送信形式 メール送信元に設定するメールアドレスを設定 (英語では「Send emails as」という設定項目であり、「メール送信形式」という日本語訳がおかしい)

2. ログをサーチ

アラートに使用する検索条件を作るため、「新規サーチ」の画面にてサーチを行う。今回は例として以下をサーチ文として設定した。

index=* Failed Password

3. アラートを作成

検索結果に問題がないことを確認したのち、「名前を付けて保存」→「アラート」を選択、「アラートとして保存」画面を表示させる。

1時間に1回パスワード失敗のログの出力有無を確認し、ログの出力件数が0より大きい場合はメール送信を行う設定を行う。

設定項目 設定値
タイトル Failed password
アラートタイプ スケジュール済み
時間範囲 Last 60 minutes
Cron式 0 * * * *
失効 24時間
次の条件の時にアラートを生成 結果数が0より大きい
生成条件 各結果に対して1回
アクション メール送信
宛先 <アラートの送信先メールアドレスを指定>



4. アラートの動作確認

実際にログイン失敗を発生させ、アラートにてメール送信がされることを確認してみよう。

以下の通り、「Splunk Alert: Failed password」というメール件名でメールが送信されていることがわかる。

「View results」のリンクをクリックすると、Splunkのサーチ画面が表示される。

まとめ

Splunkのアラート機能を使うことで、特定のログ出力条件に応じてメール通知を行うことができた。今回は1台のサーバのログを検索するだけなので単純な設定となっており、正直SplunkでなくてもスクリプトやZabbixなどでも実現できる。

しかしSplunkの場合は、多数の機器から集約したログ情報を用いた複雑なログ検索の結果を用いてアクションを実行することもできるので、そのような場合に有用な機能となるだろう。



2020年9月29日火曜日

Splunk 8.0.5をCentOS 7にインストールしてみた② (Universal Forwarderのインストール)

前回、Splunkの本体のインストール手順を記載した。

★前回の記事はこちら↓

本体のインストールが完了したので、次はログ送信側の設定を行う。Splunkではログ送信を行うエージェントとして、「Universal Forwarder」、「Light Forwarder」、「Heavy Forwarder」の3種類がある。それぞれの違いはSplunkの以下マニュアルにて記載されている。

ログを送信する用途だけであればUniversal Forwarderを、ログ送信の際にログの分析・加工が必要な場合はLight Forwarder、Heavy Forwarderを利用するようだ。なお、Universal Forwarderのインストーラは個別で用意されているが、Light Forwarder、Heavy Forwarderのインストーラは本体と同じインストーラを利用し、Splunk本体の機能の中からログ送信の機能のみ有効にする形で利用する。

今回は、Universal ForwarderをCentOSにインストールし、Splunkの検索画面にてログ検索ができることを確認する。

環境

  • OS : CentOS 7.6
  • インストール状態 : 最小限のインストール

Universal Forwarderインストール手順

1. インストーラのダウンロード

インストーラは以下URLからダウンロードできる。ダウンロードするためにはSplunkサイトのユーザ登録が必要となるので注意

2. 事前準備

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

# systemctl stop firewalld
# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux

3. インストール

Spulunk本体と同様にインストールはtgzファイルを解凍するだけよい。追加でパッケージインストールなども不要であり、インストール自体は極めてシンプルになるよう設計されている。

# tar xvzf splunkforwarder-8.0.5-a1a6394cc5ae-Linux-x86_64.tgz -C /opt

Universal Forwarderは「/opt/splunkforwarder」に解凍される。以下ディレクトリでよく使うものは以下となる。

ディレクトリ 説明
bin 実行ファイルが配置されている。特にsplunkコマンドは起動・停止や設定確認などで頻繁に使用する。
etc Universal Forwarderの設定ファイルとなるconfファイルが配置されている。CLIによる設定を行った内容は、本ディレクトリ配下のconfファイルに反映され保存される。なお、直接confファイルに設定追加することも可能。
# ls -l /opt/splunkforwarder/
合計 156
-r--r--r--.  1 10777 10777   841  7月  8 16:52 README-splunk.txt
drwxr-xr-x.  3 10777 10777  4096  7月  8 17:13 bin
-r--r--r--.  1 10777 10777    57  7月  8 16:49 copyright.txt
drwxr-xr-x. 13 10777 10777  4096  7月  8 17:10 etc
-rw-r--r--.  1 10777 10777     0  7月  8 17:10 ftr
drwxr-xr-x.  2 10777 10777    27  7月  8 17:10 include
drwxr-xr-x.  5 10777 10777  4096  7月  8 17:13 lib
-r--r--r--.  1 10777 10777 85709  7月  8 16:49 license-eula.txt
drwxr-xr-x.  3 10777 10777    58  7月  8 17:10 openssl
drwxr-xr-x.  4 10777 10777    63  7月  8 17:10 share
-r--r--r--.  1 10777 10777 50969  7月  8 17:13 splunkforwarder-8.0.5-a1a6394cc5ae-linux-2.6-x86_64-manifest

4. Universal Forwarderの初回起動と初期設定

「/opt/splunkforwarder/bin」ディレクトリにUniversal Forwarder本体の実行ファイルがあるので、以下の通り実行することで、初回起動時の以下処理が実行される。

  • ライセンス条項に同意
  • 管理ユーザ名の設定 (デフォルトはadmin)
  • 管理ユーザのパスワードの設定
# cd /opt/splunkforwarder/bin/
# ./splunk start

SPLUNK GENERAL TERMS

Last updated: February 13, 2020

These Splunk General Terms ("General Terms") between
Splunk Inc., a Delaware corporation, with its principal place
of business at 270 Brannan Street, San Francisco,
California 94107, U.S.A ("Splunk" or "we" or "us" or "our")
and you ("Customer" or "you" or "your") apply to the
purchase of licenses and subscriptions for Splunk's
Offerings. By clicking on the appropriate button, or by
downloading, installing, accessing or using the Offerings,
you agree to these General Terms. If you are entering into
these General Terms on behalf of Customer, you represent
that you have the authority to bind Customer. If you do not
agree to these General Terms, or if you are not authorized
to accept the General Terms on behalf of the Customer, do
not download, install, access, or use any of the Offerings.

See the General Terms Definitions Exhibit attached for
definitions of capitalized terms not defined herein.

1. License Rights

~(中略)~

"Statement of Work" means the statements of work and/or any all
applicable Orders that describe the specific services to be performed by
Splunk, including any materials and deliverables to be delivered by
Splunk.


SPLUNK GENERAL TERMS (v1.2020)


Do you agree with this license? [y/n]: y   ←★"y"を入力

This appears to be your first time running this version of Splunk.

Splunk software must create an administrator account during startup. Otherwise, you cannot log in.
Create credentials for the administrator account.
Characters do not appear on the screen when you type in credentials.

Please enter an administrator username: admin ←★管理者ユーザ名を入力
Password must contain at least:
   * 8 total printable ASCII character(s).
Please enter a new password:   ←★パスワードを入力
Please confirm new password:   ←★パスワードを再入力

Splunk> All batbelt. No tights.

Checking prerequisites...
        Checking mgmt port [8089]: open
                Creating: /opt/splunkforwarder/var/lib/splunk
                Creating: /opt/splunkforwarder/var/run/splunk
                Creating: /opt/splunkforwarder/var/run/splunk/appserver/i18n
                Creating: /opt/splunkforwarder/var/run/splunk/appserver/modules/static/css
                Creating: /opt/splunkforwarder/var/run/splunk/upload
                Creating: /opt/splunkforwarder/var/run/splunk/search_telemetry
                Creating: /opt/splunkforwarder/var/spool/splunk
                Creating: /opt/splunkforwarder/var/spool/dirmoncache
                Creating: /opt/splunkforwarder/var/lib/splunk/authDb
                Creating: /opt/splunkforwarder/var/lib/splunk/hashDb
New certs have been generated in '/opt/splunkforwarder/etc/auth'.
        Checking conf files for problems...
        Done
        Checking default conf files for edits...
        Validating installed files against hashes from '/opt/splunkforwarder/splunkforwarder-8.0.5-a1a6394cc5ae-linux-2.6-x86_64-manifest'
        All installed files intact.
        Done
All preliminary checks passed.

Starting splunk server daemon (splunkd)...
Done
                                                           [  OK  ]

5. 自動起動設定

tgzファイルを解凍しただけなので、これだけではサーバ再起動時に自動起動してくれないため、以下コマンドで自動起動するよう設定する。

# cd /opt/splunkforwarder/bin/
# ./splunk enable boot-start
Init script installed at /etc/init.d/splunk.
Init script is configured to run at boot.

6. 送信先のサーバ (インデクサー) を設定

Splunkのログ受信および解析を行う機能を「インデクサー」と呼ぶ。Universal Forwarderのログ送信先としてインデクサーを指定する必要があるため、splunk add forward-server <インデクサーのIPアドレス or ホスト名>:<ポート番号>コマンドにて行う。

# cd /opt/splunkforwarder/bin/
# ./splunk add forward-server 192.168.11.71:9997
Splunk username: admin
Password:
Added forwarding to: 192.168.11.71:9997.
# ./splunk list forward-server
Active forwards:
        None
Configured but inactive forwards:
        192.168.11.71:9997

本設定は、「/opt/splunkforwarder/etc/system/local/outputs.conf」に記述される。

# cat /opt/splunkforwarder/etc/system/local/outputs.conf
[tcpout]
defaultGroup = default-autolb-group

[tcpout:default-autolb-group]
server = 192.168.11.71:9997

[tcpout-server://192.168.11.71:9997]

7. Splunk本体 (インデクサー) 側で受信設定を追加

Splunkはデフォルトでは受信設定がされていない。Splunk本体の管理GUIにログインし、「設定」→「転送と受信」→「データの受信」を開いたのち、ポート番号「9997」にて新規作成を行う。

設定後に、Splunk本体で設定したポートでListenしていることを確認しておこう。

# ss -nl | grep 9997
tcp    LISTEN     0      128       *:9997                  *:*

8. モニター対象のログを追加

今回は例として/var/log配下のログをすべて監視対象として、Splunk本体のインデクサーに送信する。splunk add monitor <モニター対象のファイル or ディレクトリ>コマンドで設定する。

# cd /opt/splunkforwarder/bin/
# ./splunk add monitor /var/log
Added monitor of '/var/log'.

splunk list monitorで設定確認を行う。

# ./splunk list monitor
Monitored Directories:
        $SPLUNK_HOME/var/log/splunk
                /opt/splunkforwarder/var/log/splunk/btool.log
                /opt/splunkforwarder/var/log/splunk/first_install.log
                /opt/splunkforwarder/var/log/splunk/splunkd-utility.log
        $SPLUNK_HOME/var/log/splunk/splunkd.log
                /opt/splunkforwarder/var/log/splunk/splunkd.log
        $SPLUNK_HOME/var/log/watchdog/watchdog.log*
        $SPLUNK_HOME/var/run/splunk/search_telemetry/*search_telemetry.json
        $SPLUNK_HOME/var/spool/splunk/...stash_new
Monitored Files:
        $SPLUNK_HOME/etc/splunk.version
        /var/log   ←★対象が追加されている

設定の反映のため、Universal Forwarderをリスタートする。再起動は30秒ほど要したが問題なく完了した。

# ./splunk restart
Stopping splunkd...
Shutting down.  Please wait, as this may take a few minutes.
.............                                              [  OK  ]
Stopping splunk helpers...
                                                           [  OK  ]
Done.

Splunk> All batbelt. No tights.

Checking prerequisites...
        Checking mgmt port [8089]: open
        Checking conf files for problems...
        Done
        Checking default conf files for edits...
        Validating installed files against hashes from '/opt/splunkforwarder/splunkforwarder-8.0.5-a1a6394cc5ae-linux-2.6-x86_64-manifest'
        All installed files intact.
        Done
All preliminary checks passed.

Starting splunk server daemon (splunkd)...
Done
                                                           [  OK  ]

再度splunk list monitorで設定確認を行うと、/var/log配下のログファイルがファイル単位でモニター対象となっていることがわかる。

# ./splunk list monitor
Your session is invalid.  Please login.
Splunk username: admin
Password:
Monitored Directories:

~(中略)~

        /var/log
                /var/log/anaconda
                /var/log/anaconda/anaconda.log
                /var/log/anaconda/ifcfg.log
                /var/log/anaconda/journal.log
                /var/log/anaconda/ks-script-wAP9r2.log
                /var/log/anaconda/packaging.log
                /var/log/anaconda/program.log
                /var/log/anaconda/storage.log
                /var/log/anaconda/syslog
                /var/log/anaconda/X.log
                /var/log/audit
                /var/log/audit/audit.log
                /var/log/boot.log
                /var/log/btmp
                /var/log/chrony
                /var/log/cron
                /var/log/dmesg
                /var/log/dmesg.old
                /var/log/firewalld
                /var/log/grubby_prune_debug
                /var/log/lastlog
                /var/log/maillog
                /var/log/messages
                /var/log/rhsm
                /var/log/secure
                /var/log/spooler
                /var/log/tallylog
                /var/log/tuned
                /var/log/tuned/tuned.log
                /var/log/vmware-network.log
                /var/log/vmware-vgauthsvc.log.0
                /var/log/vmware-vmsvc.log
                /var/log/wtmp
Monitored Files:
        $SPLUNK_HOME/etc/splunk.version

以上で、Universal Forwarderの設定は完了となる。

Splunkにてログを検索してみる

実際に取得したログを検索してみよう。Splunkはログを解析するための設定として、「ソースタイプ」があり、ログの日付フォーマットやログのフィールドの内容 (たとえば、syslogなら日付情報の次にホスト名が来るなど) が定義されている。

以下マニュアルに記載の通り、Splunkはログの内容を分析し、適切なソースタイプが決定されるようだ。

Splunk software next attempts to use automatic source type recognition to match similar-looking files and assign a source type.
たとえば、以下のようにファイルごとにソースタイプが設定される。

実際の環境で確認すると、以下のように/var/log配下のログのソースタイプは、特にソースタイプを指定しなくとも自動的に以下のように適切に設定されていることがわかる。

ログファイル ソースタイプ
/var/log/audit/audit.log linux_audit
/var/log/messages syslog
/var/log/secure linux_secure


Universal Forwarderの起動・停止

インストール自体は完了しているが、Universal Forwarderの起動・停止のコマンドも紹介する。

コマンド 説明
/opt/splunkforwarder/bin/splunk start 起動
/opt/splunkforwarder/bin/splunk stop 停止
/opt/splunkforwarder/bin/splunk restart 再起動
/opt/splunkforwarder/bin/splunk status ステータス確認

以下実行例となる。

まとめ

以上でUniversal Forwarderインストールは完了となる。Splunk本体同様、tgzファイルを解凍して、いくつか設定をするだけですぐに利用することができる。一度設定手順を経験しておけば、次回以降は容易にインストール作業をすることができるだろう。

2020年9月26日土曜日

Splunk 8.0.5をCentOS 7にインストールしてみた① (Splunk本体のインストール)

ログ管理ツール (SIEM : Security Information and Event Management) で有名なソフトウェアである「Splunk Enterprise (以降、Splunk) 」は、インストール後60日間は無料トライアル版による全機能の利用が可能であり、さらに60日後は一部機能限定とはなるものの、そのまま「Splunk Free」として利用することができる (当然ライセンスを購入すれば商用版として利用が可能)。

各製品の機能比較は以下URLに記載がされている。

Splunkは、Windows、Linux、Mac OSと幅広いプラットフォームをサポートしている。今回はCentOS 7環境にSplunkを導入する手順を紹介する。

なお、今回はSplunk本体 (ログ受信側) のインストールまでを記載し、次回以降で「Splunk Universal Forwarder」を利用したログ送信およびSplunk本体にてログ受信を行う設定手順を記載する。

★↓Splunk Universal Forwarderのインストールと設定手順はこちら。

環境

  • OS : CentOS 7.6
  • インストール状態 : 最小限のインストール

Splunkインストール手順

1. インストーラのダウンロード

インストーラは以下URLからダウンロードできる。無料トライアル版もFree版も同じものがダウンロードできる。ダウンロードするためにはSplunkサイトのユーザ登録が必要となるので注意

.deb、.tgz、.rpmの3種類が用意されているが、ディストリビューションが変わっても手順に応用が利くことから、今回は「.tgz版」をダウンロードする。

2. 事前準備

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

# systemctl stop firewalld
# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux

3. インストール

インストールはtgzファイルを解凍するだけよい。追加でパッケージインストールなども不要であり、インストール自体は極めてシンプルになるよう設計されている。

# tar xvzf splunk-8.0.5-a1a6394cc5ae-Linux-x86_64.tgz -C /opt

Splunkは「/opt/splunk」に解凍される。以下ディレクトリでよく使うものは以下となる。

ディレクトリ 説明
bin 実行ファイルが配置されている。特にsplunkコマンドは起動・停止や設定確認などで頻繁に使用する。
etc Splunkの設定ファイルとなるconfファイルが配置されている。今回は詳しくは説明しないが、Web管理画面で設定追加されたものは、すべて本ディレクトリ配下のconfファイルに設定がテキストで書き込まれると考えて差し支えない。直接confファイルに設定追加することも可能。
# ls -l /opt/splunk/
合計 2916
-r--r--r--.  1 10777 10777     841  7月  8 16:52 README-splunk.txt
drwxr-xr-x.  4 10777 10777    4096  7月  8 17:12 bin
-r--r--r--.  1 10777 10777      57  7月  8 16:49 copyright.txt
drwxr-xr-x. 15 10777 10777    4096  7月  8 17:10 etc
-rw-r--r--.  1 10777 10777       0  7月  8 17:10 ftr
drwxr-xr-x.  4 10777 10777      62  7月  8 17:10 include
drwxr-xr-x.  8 10777 10777    4096  7月  8 17:13 lib
-r--r--r--.  1 10777 10777   85709  7月  8 16:49 license-eula.txt
drwxr-xr-x.  3 10777 10777      58  7月  8 17:10 openssl
drwxr-xr-x.  4 10777 10777     108  7月  8 17:10 share
-r--r--r--.  1 10777 10777 2875790  7月  8 17:13 splunk-8.0.5-a1a6394cc5ae-linux-2.6-x86_64-manifest

4. Splunkの初回起動と初期設定

「/opt/splunk/bin」ディレクトリにSplunk本体の実行ファイルがあるので、以下の通り実行することで、初回起動時の以下処理が実行される。

  • ライセンス条項に同意
  • 管理ユーザ名の設定 (デフォルトはadmin)
  • 管理ユーザのパスワードの設定
# cd /opt/splunk/bin/
# ./splunk start

SPLUNK GENERAL TERMS

Last updated: February 13, 2020

These Splunk General Terms ("General Terms") between
Splunk Inc., a Delaware corporation, with its principal place
of business at 270 Brannan Street, San Francisco,
California 94107, U.S.A ("Splunk" or "we" or "us" or "our")
and you ("Customer" or "you" or "your") apply to the
purchase of licenses and subscriptions for Splunk's
Offerings. By clicking on the appropriate button, or by
downloading, installing, accessing or using the Offerings,
you agree to these General Terms. If you are entering into
these General Terms on behalf of Customer, you represent
that you have the authority to bind Customer. If you do not
agree to these General Terms, or if you are not authorized
to accept the General Terms on behalf of the Customer, do
not download, install, access, or use any of the Offerings.

See the General Terms Definitions Exhibit attached for
definitions of capitalized terms not defined herein.

1. License Rights

~(中略)~

"Statement of Work" means the statements of work and/or any all
applicable Orders that describe the specific services to be performed by
Splunk, including any materials and deliverables to be delivered by
Splunk.


SPLUNK GENERAL TERMS (v1.2020)


Do you agree with this license? [y/n]: y   ←★"y"を入力

This appears to be your first time running this version of Splunk.

Splunk software must create an administrator account during startup. Otherwise, you cannot log in.
Create credentials for the administrator account.
Characters do not appear on the screen when you type in credentials.

Please enter an administrator username: admin ←★管理者ユーザ名を入力
Password must contain at least:
   * 8 total printable ASCII character(s).
Please enter a new password:   ←★パスワードを入力
Please confirm new password:   ←★パスワードを再入力
Copying '/opt/splunk/etc/openldap/ldap.conf.default' to '/opt/splunk/etc/openldap/ldap.conf'.
Generating RSA private key, 2048 bit long modulus
.........................................+++++
..............................+++++
e is 65537 (0x10001)
writing RSA key

~(中略)~

If you get stuck, we're here to help.
Look for answers here: http://docs.splunk.com

The Splunk web interface is at http://t1071splk:8000

5. 自動起動設定

tgzファイルを解凍しただけなので、これだけではサーバ再起動時に自動起動してくれないため、以下コマンドで自動起動するよう設定する。

# /opt/splunk/bin/splunk enable boot-start
Init script installed at /etc/init.d/splunk.
Init script is configured to run at boot.

試しに再起動を行ったのちステータスを確認したところ、問題なくSplunkが「running」ステータスとなっていた。

# /opt/splunk/bin/splunk status
splunkd is running (PID: 1616).
splunk helpers are running (PIDs: 1620 1635 1711 1831).

6. 管理Web画面にアクセス

以上を実施したのち「http://<インストールしたホスト名 or IPアドレス>:8000」にアクセスすると、管理画面が表示されるはずなので、初回起動時に設定した管理者ユーザとパスワードでログインしてみよう。

初回ログイン時のみ以下2つの警告が表示されるが、どちらも「了解です!」、「再度表示しない」を選択しておけばよい。


問題なければ以下のようなSplunkの管理画面が表示される。


Splunkの起動・停止

インストール自体は完了しているが、Splunkの起動・停止のコマンドも紹介する。

コマンド 説明
/opt/splunk/bin/splunk start 起動
/opt/splunk/bin/splunk stop 停止
/opt/splunk/bin/splunk restart 再起動
/opt/splunk/bin/splunk status ステータス確認

以下実行例となる。

停止

# /opt/splunk/bin/splunk stop
Stopping splunkd...
Shutting down.  Please wait, as this may take a few minutes.
..                                                         [  OK  ]
Stopping splunk helpers...
                                                           [  OK  ]
Done.

起動

# /opt/splunk/bin/splunk start

Splunk> All batbelt. No tights.

Checking prerequisites...
        Checking http port [8000]: open
        Checking mgmt port [8089]: open
        Checking appserver port [127.0.0.1:8065]: open
        Checking kvstore port [8191]: open
        Checking configuration... Done.
        Checking critical directories...        Done
        Checking indexes...
                Validated: _audit _internal _introspection _metrics _metrics_rollup _telemetry _thefishbucket history main summary
        Done
        Checking filesystem compatibility...  Done
        Checking conf files for problems...
        Done
        Checking default conf files for edits...
        Validating installed files against hashes from '/opt/splunk/splunk-8.0.5-a1a6394cc5ae-linux-2.6-x86_64-manifest'
        All installed files intact.
        Done
All preliminary checks passed.

Starting splunk server daemon (splunkd)...
Done
                                                           [  OK  ]

Waiting for web server at http://127.0.0.1:8000 to be available. Done


If you get stuck, we're here to help.
Look for answers here: http://docs.splunk.com

The Splunk web interface is at http://t1071splk:8000

ステータス確認

# /opt/splunk/bin/splunk status
splunkd is running (PID: 3105).
splunk helpers are running (PIDs: 3112 3126 3254 3308 3418).

まとめ

以上でSplunkインストールは完了となる。この状態からログ受信の設定を少し設定するだけでログ収集が開始できる。実施する前は、Splunkのインストールはもっと手間のかかるものと予想していたが、極めて容易かつ短時間でインストールできてしまうことに驚いた。

次回は「Splunk Universal Forwarder」をインストールし、LinuxのログをSplunkに送信し、ログ検索ができることまでを確認する。

人気の投稿