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にインストールする手順は完了となる。

0 件のコメント:

コメントを投稿