-
Notifications
You must be signed in to change notification settings - Fork 1
/
userdata-kibana
executable file
·130 lines (96 loc) · 3.07 KB
/
userdata-kibana
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#
# Install Kibana (and nginx).
#
# Source:
# https://www.digitalocean.com/community/tutorials/
# how-to-install-elasticsearch-logstash-and-kibana-elk-stack-on-centos-7
#
TMP=/tmp/kibana
GITHUBFOLDER=/home/ec2-user/gs-kibana
##
# Validate parameters.
##
space=$1
nginxuserid=gs
nginxpassword=$2
echo nginx credentials: ${nginxuserid}/${nginxpassword} &> $TMP-0900
if [ ${space} = 'prod' ]; then
gstype='gsp'
else
if [[ \
${space} = 'int' || ${space} = 'test' || \
${space} = 'dev' || ${space} = 'stage' ]]; then
gstype='gsn'
else
echo Space must be either int, test, dev, stage or prod. It''s ${space}
exit 1
fi
fi
##
# Install GPG key.
##
cd ~ &> $TMP-1000
wget --no-cookies --no-check-certificate \
--header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.rpm" &> $TMP-1100
sudo yum -y localinstall jdk-8u73-linux-x64.rpm &> $TMP-1200
# Now Java should be installed at /usr/java/jdk1.8.0_73/jre/bin/java,
# and linked from /usr/bin/java.
rm /home/ec2-user/jdk-8u*-linux-x64.rpm &> $TMP-1300
##
# Install public key
##
sudo rpm --import http://packages.elastic.co/GPG-KEY-elasticsearch &> $TMP-1400
sudo cp ${GITHUBFOLDER}/elasticsearch.repo \
/etc/yum.repos.d/elasticsearch.repo &> $TMP-1500
##
# Install Kibana
##
sudo cp ${GITHUBFOLDER}/kibana.repo /etc/yum.repos.d/kibana.repo &> $TMP-1600
sudo yum -y install kibana &> $TMP-1700
if [ ${gstype} = 'gsp' ]; then
elasticsearchDNS=$( \
aws cloudformation describe-stacks --stack-name gsp-elasticsearch-${space} \
--region us-east-1 --query Stacks[].Outputs[].[OutputValue] \
--output text | grep LoadBala) &> $TMP-1800
else
elasticsearchDNS=$( \
aws cloudformation describe-stacks --stack-name gsn-elasticsearch-${space} \
--region us-east-1 --query Stacks[].Outputs[].[OutputValue] \
--output text | grep LoadBala) &> $TMP-1805
fi
sudo sed -i \
"s/# elasticsearch.url: \"http:\/\/localhost:9200\"/elasticsearch.url: \"http:\/\/${elasticsearchDNS}:9200\"/" \
/opt/kibana/config/kibana.yml &> $TMP-1900
sudo service kibana start &> $TMP-2000
# Allow time for kibana service start
sleep 5 &> TMP-2010
# Must occur after service has started (see kibana#6085)
sudo /opt/kibana/bin/kibana plugin --install elastic/sense &> $TMP-2020
sudo service kibana restart &> $TMP-2030
##
# Install nginx
##
sudo yum -y install epel-release &> $TMP-2100
sudo yum -y install nginx httpd-tools &> $TMP-2200
sudo htpasswd -cb /etc/nginx/htpasswd.users ${nginxuserid} ${nginxpassword} &> $TMP-2300
sudo cp ${GITHUBFOLDER}/nginx.conf /etc/nginx &> $TMP-2400
sudo cp ${GITHUBFOLDER}/kibana.conf /etc/nginx/conf.d &> $TMP-2500
# Allow time for kibana.conf to be saved.
sleep 15 &> $TMP-2550
sudo service nginx start &> $TMP-2600
##
# Update route53
##
cd ${GITHUBFOLDER} &> $TMP-2650
if [ ${gstype} = 'gsp' ]; then
./upsert-route53 gsp-kibana-${space} &> $TMP-2700
else
./upsert-route53 gsn-kibana-${space} &> $TMP-2705
fi
##
# Add https
##
cd ${GITHUBFOLDER} &> $TMP-2800
./https ${space} &> $TMP-2900