2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Splunk]Splunk Enterpriseの構築(dockerファイル作成)

Posted at

[Splunk]Splunk Enterpriseの構築(dockerファイル作成)

目的・背景

手作業と公開されているDockerイメージを使ってのSplunk Enterpriseの環境構築には成功しました。
次はdockerファイルを自分で作って構築してみたいと思います。

目標

  • Dockerfileの作成
  • コンテナ、イメージの作成と起動
  • Splunk Webへのアクセス

構成

/splunk  
    /Dockerfile  
    /files  
        /splunk-launch.conf  

./Dockerfile

インストール先は「/usr/local/splunk」、adminユーザの初期パスワードは「changeme」で構築してみます。

FROM ubuntu:18.04

RUN apt-get update -y
RUN apt-get install -y \
    wget
RUN wget -P /usr/local/src -O splunk-8.0.6-152fb4b2bb96-Linux-x86_64.tgz 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=8.0.6&product=splunk&filename=splunk-8.0.6-152fb4b2bb96-Linux-x86_64.tgz&wget=true'
RUN tar zxvf splunk-8.0.6-152fb4b2bb96-Linux-x86_64.tgz -C /usr/local/
COPY ./files/splunk-launch.conf /usr/local/splunk/etc
RUN /usr/local/splunk/bin/splunk start --accept-license --answer-yes --seed-passwd changeme

./files/splunk-launch.conf

#   Version 8.0.6

# Modify the following line to suit the location of your Splunk install.
# If unset, Splunk will use the parent of the directory containing the splunk
# CLI executable.
#
# SPLUNK_HOME=/opt/splunk-home
SPLUNK_HOME=/usr/local/splunk

# By default, Splunk stores its indexes under SPLUNK_HOME in the
# var/lib/splunk subdirectory.  This can be overridden
# here:
#
# SPLUNK_DB=/opt/splunk-home/var/lib/splunk
# Splunkd daemon name
SPLUNK_SERVER_NAME=Splunkd

# If SPLUNK_OS_USER is set, then Splunk service will only start
# if the 'splunk [re]start [splunkd]' command is invoked by a user who
# is, or can effectively become via setuid(2), $SPLUNK_OS_USER.
# (This setting can be specified as username or as UID.)
#
# SPLUNK_OS_USER

OPTIMISTIC_ABOUT_FILE_LOCKING=1

ビルド

$ docker build -t splunk .

起動

$ docker run -itd -p 8000:8000 --name splunk splunk

※(課題)これだけだとSplunkが起動してくれなかったので、意図的にrestartさせました
$ docker exec splunk sh -c "/usr/local/splunk/bin/splunk restart"

コンテナ内に入る

※splunkコマンドの実行などのため直接コンテナ内で作業したい場合に利用する

$ docker exec -it splunk /bin/bash

diag情報の取得

$ docker exec splunk sh -c "/usr/local/splunk/bin/splunk diag"

Collecting components: conf_replication_summary, consensus, dispatch, etc, file_validate, index_files, index_listing, kvstore, log, searchpeers, suppression_listing
Skipping components: rest
Selected diag name of: diag-7ffffbe066aa-2020-09-11_07-32-48
Starting splunk diag...
    :
Cleaning up...
Splunk diagnosis file created: /usr/local/splunk/diag-7ffffbe066aa-2020-09-11_07-32-48.tar.gz

起動時にマウントしたホスト側のフォルダにファイルをコピー
(diagの出力先を設定できればこのコマンド実行は不要)

$ docker exec splunk sh -c "cp /usr/local/splunk/diag-f03a58497527-2020-09-11_07-42-14.tar.gz /tmp"

※コピー結果の確認
$ ll ./Volumes/tmp/
total 15M
drwxrwxr-x 2 xxxxx xxxxx 4.0K Sep 11 16:42 ./
drwxrwxr-x 3 xxxxx xxxxx 4.0K Sep 11 16:35 ../
-rw------- 1 root  root   15M Sep 11 16:42 diag-f03a58497527-2020-09-11_07-42-14.tar.gz

もしくは以下のコマンドでコンテナ内からホストへファイルをコピー

$ docker cp splunk://usr/local/splunk/diag-f03a58497527-2020-09-11_07-42-14.tar.gz ./
$ ll
total 15M
drwxrwxr-x  4 xxxxx xxxxx 4.0K Sep 11 16:47 ./
drwxrwxr-x 11 xxxxx xxxxx 4.0K Sep 11 11:25 ../
-rw-------  1 xxxxx xxxxx  15M Sep 11 16:42 diag-f03a58497527-2020-09-11_07-42-14.tar.gz
-rw-rw-r--  1 xxxxx xxxxx  551 Sep 11 16:26 Dockerfile
drwxrwxr-x  2 xxxxx xxxxx 4.0K Sep 11 16:09 files/
drwxrwxr-x  3 xxxxx xxxxx 4.0K Sep 11 16:35 Volumes/

おわりに

コンテナを起動しただけだとSplunkが起動せず、手動で再起動させなければならないという課題は残りましたが、ホストを汚さずコンテナ内でSplunkを起動させることができました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?