Splunk Universal Forwederを入れてログをSplunkに飛ばす


前回

前回まででSplunkをインストールして、Web画面にログインまでを実施しましたので、
今回は別サーバでUniversal Forwederを構築して「/var/log」配下のログを
Splunkに飛ばしていきたいと思います。

前回については以下を参考にしてください。
https://qiita.com/kzyomr/items/b6c0ddd8cf9b64de099c

環境

  • OS:Amazon Linux 2
  • Splunkのインストールバージョン:8.1.3
  • Universal Forwederのインストールバージョン:8.1.3
  • セキュリティグループで以下利用ポートをあけておく
ポート番号 用途
22 ssh用
8000 SplunkWebブラウザ用
8089 Splunk管理通信用
9997 データ転送用

Universal Forwederダウンロード

前回と同じくSplunkを公式サイトにログインしてダウンロードしていきます。

※事前にアカウントの登録が必要となります。
https://www.splunk.com/ja_jp/download/universal-forwarder.html

タブでLinuxを選択して64-bitの.rpmの「Download Now」をクリックしてダウンロードします。
ダウンロードしたファイルは「/home/ec2-user」配下に格納しておきます。

参考

以下Splunkの公式ドキュメントを参考にすすめていきます。

Universal Forwederのインストール手順

Splunkを構築したサーバとは別のサーバを準備して実施していきます。

①Universal Forwederをインストールする(rpm)

$ sudo su -
#
# cd /home/ec2-user/
#
# ls
splunkforwarder-8.1.3-63079c59e632-linux-2.6-x86_64.rpm
#
# rpm -i splunkforwarder-8.1.3-63079c59e632-linux-2.6-x86_64.rpm
warning: splunkforwarder-8.1.3-63079c59e632-linux-2.6-x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID b3cd4420: NOKEY
cp: cannot stat ‘/opt/splunkforwarder/etc/regid.2001-12.com.splunk-UniversalForwarder.swidtag’: No such file or directory
complete
#
# ls /opt/ | grep splunkforwarder
splunkforwarder
#

② Universal Forwederを起動する

インストール時にはライセンス確認を同意するにしておきます。
ユーザ名は「admin」で設定します。

# /opt/splunkforwarder/bin/splunk start --accept-license

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:

~~~ 省略 ~~~~

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

#

③サーバ起動時にSplunkが自動起動するように設定する

一度Universal Forwederを停止して自動起動設定を入れていきます。

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

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

④再度Splunkを起動してコマンドで起動確認する

「splunkd is running」となっていれば起動しています。

# /opt/splunkforwarder/bin/splunk start

Splunk> CSI: Logfiles.

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.1.3-63079c59e632-linux-2.6-x86_64-manifest'
        All installed files intact.
        Done
All preliminary checks passed.

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

# /opt/splunkforwarder/bin/splunk status
splunkd is running (PID: 30125).
splunk helpers are running (PIDs: 30128).
#

以上でインストールは終了となります。

Universal Forwederの設定

続いてログをSplunkへ飛ばす設定をしていきます。

①ログの送信先の設定

前回作成したSplunkに送信するように設定します。


# /opt/splunkforwarder/bin/splunk add forward-server [送信先SplunkのIPアドレス]:9997 -auth [user]:[pssword]]
Added forwarding to: [送信先SplunkのIPアドレス]:9997.

[user][password]は、Universal Forwederのインストール時に設定したユーザ、パスワードを入力する

②転送対象ログの設定

今回は「/var/log」配下すべてを対象にします。

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

③設定反映のために Universal Forwederを再起動する

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

Splunk> CSI: Logfiles.

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.1.3-63079c59e632-linux-2.6-x86_64-manifest'
        All installed files intact.
        Done
All preliminary checks passed.

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

Splunk側で受信設定をする

Splunkを構築したサーバにログインして実施します。

# /opt/splunk/bin/splunk enable listen 9997 -auth [user]]:[password]]
Listening for Splunk data on TCP port 9997.

[user][password]はSplunkインストール時に設定したユーザ、パスワードを入力する

取り込んだログを確認してみる

①SplunkWebにログインしてサーチ画面を開く


②以下サーチ文を入力して取り込んだログが表示されるか確認する

index = "main"
※今回は特にインデックスを指定していないのでデフォルトの「main」に取り込まれている

  • 「host」にUniversal Forwederの「ホスト名」「source」に「/var/log/・・・」(/var/log配下のログ)が表示されていれば取り込めている

これでログが取り込めたので、Splunk上でサーチができるようになりました。