-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstallkibana.txt
More file actions
226 lines (174 loc) · 6.15 KB
/
Copy pathinstallkibana.txt
File metadata and controls
226 lines (174 loc) · 6.15 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh
set -e
#
# This script is meant for quick & easy install via:
# 'curl -sSL https://healthcatalyst.github.io/InstallScripts/installkibana.txt | sh -s <ip1 of elasticsarch>'
# 'curl -sSL https://healthcatalyst.github.io/InstallScripts/installkibana.txt | sh -s 10.5.4.4'
# or:
# 'wget -qO- https://healthcatalyst.github.io/InstallScripts/installkibana.txt | sh -s <ip1> <ip2> <ip3>'
#
#
echo "starting version 2.15"
defaultpassword=""
echo "Starting setup..."
u="$(whoami)"
echo "User name: $u"
# no spaces allowed in variable set commands
ip1="$1"
serverhost="$2"
ssl="$3"
paramsToES=""
if [ -z "$ip1" ]; then
myip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' fabric.docker.elasticsearch)
echo "ElasticSearch IP:"
echo $myip
ip1="$myip"
fi
if [ -z "$serverhost" ]; then
serverhost="0.0.0.0"
fi
echo "Please enter name for cluster:"
read -e clustername < /dev/tty
echo "Please type in password to use for ElasticSearch built-in accounts:"
read -e defaultpassword < /dev/tty
# ask if user wants to use SSL
if [ -z "$ssl" ]; then
while true; do
read -e -p "Do you wish to turn on SSL?" yn < /dev/tty
case $yn in
[Yy]* ) ssl="yes"; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
hostname="$(hostname -s)"
echo "==== Parameters ======"
echo "node name: [$hostname]"
echo "ip1: $ip1"
echo "ssl: $ssl"
echo "==== End Parameters ===="
echo "==== Creating update script ===="
installfolder="/opt/install/"
installscriptfile="updatedocker"
installscript="$installfolder$installscriptfile"
mkdir -p $HOME/bin
if [[ ! -d "$installfolder" ]]; then
sudo mkdir -p $installfolder
sudo setfacl -m u:$u:rwx $installfolder
fi
echo "#!/bin/sh" > $installscript
echo "curl -sSL https://healthcatalyst.github.io/InstallScripts/installkibana.txt | sh -s $@" >> $installscript
chmod +x $installscript
if [[ ! -e "$HOME/bin/$installscriptfile" ]]; then
echo "creating a symbolic link for install file"
echo "ln -f -s $installscript $HOME/bin/$installscriptfile"
ln -f -s $installscript $HOME/bin/$installscriptfile
fi
protocol="http"
if [ ! -z "$ssl" ]; then
echo "Setting up SSL"
protocol="https"
if [[ ! -f "$installfolder/node.key" ]]; then
echo "$installfolder/node.key does not exist"
exit 1
fi
if [[ ! -f "$installfolder/node.crt" ]]; then
echo "$installfolder/node.crt does not exist"
exit 1
fi
if [[ ! -f "$installfolder/ca.crt" ]]; then
echo "$installfolder/ca.crt does not exist"
exit 1
fi
fi
echo "==== Update script ===="
cat $installscript
echo "==== End Update Script ===="
echo "==== Downloading and installing ElasticSearch Docker container ===="
echo "==== existing containers on this host ===="
docker ps -a
echo "==== existing images on this host ===="
docker images
echo "==== existing volumes on this host ===="
docker volume ls
# check to see if volume already exists. if not, create it
if [ -z $(docker volume ls -q --filter "name=esdata") ]; then
echo "==== Creating persistent volume for ElasticSearch ===="
docker volume create --name esdata
fi
# delete old containers
echo "stopping existing docker container"
docker stop dockerkibana || echo 'no container to stop'
echo "removing docker container"
docker rm dockerkibana || echo 'no container to remove'
echo "removing docker image"
docker rmi imranq2/dockerkibana || echo 'no image to remove'
echo "stopping existing docker container"
docker stop fabric.docker.kibana || echo 'no container to stop'
echo "removing docker container"
docker rm fabric.docker.kibana || echo 'no container to remove'
echo "removing docker image"
docker rmi healthcatalyst/fabric.docker.kibana || echo 'no image to remove'
echo "pulling latest docker image from repo"
docker pull healthcatalyst/fabric.docker.kibana
echo "starting docker container with new image."
set -x
docker create -p 5601:5601 --restart=unless-stopped --name fabric.docker.kibana -e ELASTICSEARCH_URL=$protocol://$ip1:9200 -e SERVER_HOST=$serverhost -e ELASTICSEARCH_USERNAME=kibana -e ELASTICSEARCH_PASSWORD=$defaultpassword $paramsToES healthcatalyst/fabric.docker.kibana
set +x
echo "sleeping for 5s so docker container is up"
sleep 5s
nodekeyfile="node.key"
nodekeypath="$installfolder$nodekeyfile"
if [ ! -z "$ssl" ]; then
echo "Checking if [$nodekeypath] exists"
if [[ -f "$nodekeypath" ]]; then
echo "copying ssl keys from $installfolder"
docker cp $installfolder/node.key fabric.docker.kibana:/usr/share/kibana/config
docker cp $installfolder/node.crt fabric.docker.kibana:/usr/share/kibana/config
docker cp $installfolder/ca.crt fabric.docker.kibana:/usr/share/kibana/config
docker start fabric.docker.kibana
sleep 5s
# use kibanassl.yml
docker exec fabric.docker.kibana /bin/cp -rf /usr/share/kibana/config/kibanassl.yml /usr/share/kibana/config/kibana.yml
docker restart fabric.docker.kibana
echo "kibana set up with SSL"
protocol="https"
else
echo "ERROR: No key files found in [$nodekeypath] so cannot set up SSL"
fi
else
docker start fabric.docker.kibana
sleep 5s
# use kibanasecure.yml since we don't have ssl keys
docker exec fabric.docker.kibana /bin/cp -rf /usr/share/kibana/config/kibanasecure.yml /usr/share/kibana/config/kibana.yml
docker restart fabric.docker.kibana
fi
echo "sleeping until docker container is up"
until [ "`/usr/bin/docker inspect -f {{.State.Running}} fabric.docker.kibana`"=="true" ]; do
sleep 1s;
done;
# https://www.elastic.co/guide/en/x-pack/current/kibana.html
echo "==== Listing running docker containers ===="
docker ps
echo "sleeping for 30 secs"
sleep 30s;
externalip=$(curl ipecho.net/plain)
echo "External IP:" $externalip
declare -i c=10
c=0
while [ $c -lt 60 ]; do
echo "curl -X GET $protocol://localhost:5601 -k -verbose"
curl -X GET -u elastic:$defaultpassword $protocol://localhost:5601 -k -verbose
RETVAL=$?
echo "RETVAL:[$RETVAL]"
if [ $RETVAL -eq 0 ]; then
break
fi
c=$c+1
echo "Trying again [$c]"
sleep 1s
done
echo "==== All Done ===="
echo "NOTE To update the docker image on this host in the future, just run"
echo "$installscriptfile"