ログ分析ソリューションSplunk Enterpriseをパッケージを使って構築してみた

統合ログ分析ソリューションSplunk Enterpriseを構築したいと思います。構築方法は、セットアップ済みのMarketPlaceの利用や、クイックスタート等ありますが、今回は手動で構築してみたいと思います。
2019.11.28

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

統合ログ分析ソリューションSplunk Enterprise をAWS上に構築してみたいと思います。

Splunk Enterpriseの構築方法は複数あり、MarketPlaceにあるセットアップ済みAMIの利用や、クイックスタートがありますが、今回はパッケージを使い手動で構築してみたいと思います。

その後、AWSと連携させるためのプラグイン(Splunk App for AWS)を導入し、AWSから取得したデータをSplunk上で表示してみたいと思います。

Splunkを使うとどんな事ができるの?という方は以下の記事を参照してください。

検証環境

本エントリでは以下の環境を利用しています。

  • OS:RHEL-8.0.0_HVM-20190618-x86_64-1-Hourly2-GP2 (ami-09f31cc5d5eecca1a)
  • Splunk Enterprise:8.0.0
  • Splunk App for AWS version:5.1.0
  • Splunk Add-on for Amazon Web Services version:4.4.0

前提

  • インストール対象のEC2が構築済みであること
  • Splunkアカウントが発行済みであること(フリートライアル版のダウンロードに利用)

Splunk Enterprise構築

Splunk Enterpriseダウンロード

ダウンロードページより「Splunk Enterprise」をクリックします。(Splunk Accountでログインが必要です)

「Linux」を選択し「Download Now」をクリックします。ここではrpmパッケージを利用したいと思います。

ダウンロードが完了したら任意の方法で、インストール対象サーバにパッケージを配置します。

[ec2-user@ip-172-31-40-35 ~]$ ls -l
total 457756
-rw-rw-r--. 1 ec2-user ec2-user 468738833 Nov 27 01:42 splunk-8.0.0-1357bef0a7f6-linux-2.6-x86_64.rpm
[ec2-user@ip-172-31-40-35 ~]$

Splunk Enterpriseのインストール

インストールコマンドはrpm -i <パッケージ名>となります。パッケージを配置したディレクトリにてコマンドを実行します。

[ec2-user@ip-172-31-40-35 ~]$ sudo rpm -i splunk-8.0.0-1357bef0a7f6-linux-2.6-x86_64.rpm
warning: splunk-8.0.0-1357bef0a7f6-linux-2.6-x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID b3cd4420: NOKEY
useradd: cannot create directory /opt/splunk
complete
[ec2-user@ip-172-31-40-35 ~]$ ls -l /opt/splunk
total 2896
drwxr-xr-x.  4 splunk splunk    4096 Nov 27 01:43 bin
-r--r--r--.  1 splunk splunk      57 Oct 19 02:20 copyright.txt
drwxr-xr-x. 15 splunk splunk    4096 Nov 27 01:44 etc
-rw-r--r--.  1 splunk splunk     467 Nov 27 01:44 ftr
drwxr-xr-x.  4 splunk splunk      62 Nov 27 01:43 include
drwxr-xr-x.  8 splunk splunk    4096 Nov 27 01:43 lib
-r--r--r--.  1 splunk splunk   56043 Oct 19 02:20 license-eula.txt
drwxr-xr-x.  3 splunk splunk      58 Nov 27 01:43 openssl
-r--r--r--.  1 splunk splunk     844 Oct 19 02:23 README-splunk.txt
drwxr-xr-x.  4 splunk splunk     108 Nov 27 01:43 share
-r--r--r--.  1 splunk splunk 2879058 Oct 19 03:16 splunk-8.0.0-1357bef0a7f6-linux-2.6-x86_64-manifest
[ec2-user@ip-172-31-40-35 ~]$

ここでは、インストール先は未指定なので、デフォルトのディレクトリ(/opt/splunk)にインストールされます。

Splunk Enterprise起動

Splunkのbinディレクトリ(ここでは/opt/splunk/bin)に移動後、Splunkを起動します。初回起動時はライセンス規約が表示されるので内容を確認し同意します。

[ec2-user@ip-172-31-40-35 ~]$ cd /opt/splunk/bin
[ec2-user@ip-172-31-40-35 bin]$ sudo ./splunk start

SPLUNK SOFTWARE LICENSE AGREEMENT

This Splunk Software License Agreement ("Agreement") governs your use of
Splunk software.

(省略)

Splunk Software License Agreement 10.21.2019

Do you agree with this license? [y/n]: y

Splunk管理ユーザーの作成が求められますので任意のユーザを作成します。

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:sakamaki

作成するユーザーのパスワードを設定します。

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

(省略)

The Splunk web interface is at http://ip-172-31-40-35.ap-northeast-1.compute.internal:8000

Splunkが起動しました。

[ec2-user@ip-172-31-40-35 bin]$ sudo ./splunk status
splunkd is running (PID: 1382).
splunk helpers are running (PIDs: 1385 1401 1463 1485).
[ec2-user@ip-172-31-40-35 bin]$

Splunk Web(http://パブリックIP(or DNS名):8000)にアクセスします。(事前にセキュリティグループで該当ポートの許可が必要になります。)

Splunk Webにアクセスできました。

自動起動設定

システム起動時にSplunkが起動するように設定しておきましょう。

[ec2-user@ip-172-31-40-35 bin]$ sudo /opt/splunk/bin/splunk enable boot-start -systemd-managed 1
Systemd unit file installed at /etc/systemd/system/Splunkd.service.
Configured as systemd managed service.

Splunk App for AWS構築

Splunkアプリ(Splunk App for AWS)追加

Splunk Enterpriseが構築できたので、AWS統合サービス(Splunk App for AWS)を追加したいと思います。以下ページよりそれぞれファイルをダウンロードします。

ファイルダウンロード後、Splunk Webより「Appの管理」をクリックします。

「Install app from file」をクリックします。

ファイルを指定し「Upload」をクリックします。

更新を完了するため、Splunk Enterpriseを再起動します。

ダウンロードしたファイルそれぞれを、アップロード/反映するとアプリケーションが追加されていることが確認できます。

Splunk App for AWS設定

IAMロールアタッチ

AWSよりデータを取得するため、必要な権限をSplunk Enterpriseサーバに与えます。該当のEC2にIAMロールをアタッチし、必要な権限(ポリシー)を与えます。必要になる権限は取得するデータ(CloutTrail、CloudWatch Logsなど)により異なりますので、以下を参考にしてください。

AWSサービスの事前設定

CloutTrailなど、ログを取得するサービスに対し、事前にAWS側で設定が必要になります。以下を参考に設定しておきましょう。

Splunk Add-on for AWSデータ取得

ここでは、VPC Flow Logsのデータを取得してみたいと思います。「Splunk Add-on for AWS」より「追加」をクリックします。

「Create New Input」をクリックします。

「VPC Flow Logs」-「CloudWatch Logs」をクリックします。

EC2にアタッチしたロール等を指定します。

しばらく待った後にサーチ画面を確認すると、ソースタイプにaws:cloudwatchlogs:vpcflowが増えていたら、Splunkにデータが入力されています。

送信データが表示された後は、自由にログを検索できます。

さいごに

今回はパッケージを利用し、手動で構築しましたが、Splunk Enterpriseを利用するときはMarketPlaceの利用が簡易的かつ確実だと思いました。また、実際の案件では可用性等の検討等も必要になると思いますので、その際は、クイックスタートを参考にしてもよさそうです。そう考えだすとSplunk Cloudを利用した方が手堅いなのかなあとも思いました。

関連記事