LoginSignup
2
3

More than 1 year has passed since last update.

AWS EC2にSplunkを立ててみた。

Posted at

AWSにはちゃんとあるんだけど、Free枠でできるかどうかよくわからなかったので、立ててみた。

EC2の準備

aws起動.sh
aws ec2 run-instances --block-device-mappings '{"DeviceName": "/dev/xvda", "Ebs": {"VolumeSize": 30}}' --image-id ami-0be2609ba883822ec --count 1 --instance-type t2.micro \
--key-name XXX --subnet-id  subnet-XXXXX  --security-group-ids sg-XXXXXXXXXX \
--user-data file://open.txt --output text

立ち上げ用スクリプト。ポイントはディスク容量をfree枠いっぱいの30GBにしているところ。
セキュリティグループでは22と8000番のポートを開けている。

open.txt
yum update -y
yum install man-pages-ja -y

localectl set-locale LANG=ja_JP.UTF-8
timedatectl set-timezone Asia/Tokyo

source /etc/locale.conf

echo 'LANG=ja_JP.UTF-8' >> /etc/profile

以前作るのに苦労した記憶のあるec2-userのローカル時刻と日本語環境に直す起動ファイル。

Splunkのインストール

wget --content-disposition 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=latest&product=splunk&filename=.tgz&wget=true'

これで、いつでも最新版がダウンロードできる。

を見つつインストール。でも、ec2だとこのやり方そのままだとうまくいかないので、

install.sh
sudo su
groupadd -g 503 splunker
useradd -u 501 -g 503 splunker
passwd splunker
su - splunker
# ここでsplunker
export SPLUNK_HOME=/usr/local/splunk
wget --content-disposition 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=latest&product=splunk&filename=.tgz&wget=true'
tar xvfs splunk*
exit
# ここでrootに戻る。
mv /home/splunker/splunk /usr/local/
exit
# ここでec2-userに戻る。
su - splunker
cd $SPLUNK_HOME/etc
cp splunk-launch.conf.default splunk-launch.conf
vi splunk-launch.conf
# SPLUNK_HOMEを定義
# 今回はSPLUNK_HOME=/usr/local/splunk
cd $SPLUNK_HOME/bin
./splunk start --accept-license

で起動する(はず。)

administratorのユーザ名とパスワードを聞かれるので、適当に打ち込む

アクセス

スクリーンショット 2021-05-04 15.07.49.png

セキュリティグループがしっかり設定できていると、ログインが可能となる。
:sweat_smile: なんか恥ずかしいのが右上にでている。

まとめ

とりあえず、EC2を起動して、splunkをインストール及び起動ができた。

$SPLUNK_HOME/bin/splunk startの前にappsとか入れたりすると、データも含めて起動できそう。

あとは、ちょこちょこと自動化していきます。

2
3
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
3