blob: b5ef2c644d0adb4bc45a7e926433a7e53c44419f [file] [log] [blame]
santanudef22d9b52021-07-27 15:43:30 +05301#!/bin/bash
santanudebc32a2a2021-09-24 17:47:31 +05302# Copyright 2021 Xoriant Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
santanudef22d9b52021-07-27 15:43:30 +053016# Script to build ves project and its dependent containers
17# Maintainer shrinivas.joshi@xoriant.com
18
19# List of containers for this project
20
21# ves-kafka -- kafka broker to store events recieved from collectd or other similar services
22# ves-agent -- read events forom kafka and send those events to VEL port on ves-collector container
23# ves-collector -- Read the event received from ves-agent and write it to influxdb
24# grafana -- Read the events written by ves-collector in influxdb and show the graphs on UI
25# influxdb -- Store the events in DB sent by ves-agent
26# kafdrop -- UI for Kafka
27
28# Stop all containers if those are running accedently.
29
30./ves-stop.sh
31
32# Port allotment on host system for the micro services running in docker.
33
34influx_port=3330
35grafana_port=8880
36kafka_port=9092
37kafdrop_port=9000
38zookeeper_port=2181
39vel_ves_port=9999
40
41OS=`uname -s`
42# Check Docker, collectd, ip and git is installed on the VM
43
44if ! which docker > /dev/null; then
45 echo -e "Docker not found, please install docker from https://docs.docker.com/engine/install/ubuntu\n"
46 exit;
47fi
48
49if ! which collectd > /dev/null; then
50 if [ $OS = 'Darwin' ]
51 then
52 echo -e "Collectd not found, please install collectd using brew install collectd\n"
53 elif [ $OS = 'Linux' ]
54 then
55 echo -e "Collectd not found, please install collectd using sudo apt-get install -y collectd\n"
56 else
57 echo -e "Could not determine kind of system. Collectd not found, please install collectd using whatever method works.\n"
58 fi
59 exit;
60fi
61
62if ! which ip > /dev/null; then
63 if [ $OS = 'Darwin' ]
64 then
65 echo -e "ip not found, please install ip using brew install ip.\n"
66 elif [ $OS = 'Linux' ]
67 then
68 echo -e "/sbin/ip not found, please install ip using sudo apt-get install ip.\n"
69 else
70 echo -e "Could not determine kind of system. ip not found, please install ip using whatever method works.\n"
71 exit 1
72 fi
73 exit;
74fi
75
76clear
77
78#get local ip address of VM from first interface
79if [ $OS = 'Darwin' ]
80then
81 local_ip=`ip -4 addr list | grep en11 | grep inet | awk '{print $2}' | cut -d/ -f1`
82elif [ $OS = 'Linux' ]
83then
84 local_ip=`/sbin/ip -o -4 addr list | grep enp | head -n 1 | awk '{print $4}' | cut -d/ -f1`
85else
86 echo -e "Could not determine which OS this.\n"
87 exit 1
88fi
89echo -e "Binding VES Services to local ip address $local_ip \n "
90echo ""
91echo -e "--------------------------------------------------------------------\n"
92#Spin influx DB
93echo -e "Starting influxdb container on Local Port Number $influx_port. Please wait..\n"
94docker run -d -p $influx_port:8086 -v $PWD/influxdb influxdb:1.8.5
95if [ $? != 0 ]
96then
97 exit 1
98fi
99
100sleep 5 #Give some time to spin the container and bring service up
101echo "Done."
102echo""
103echo -e "--------------------------------------------------------------------\n"
104#Spin Grafana Cotainer
105echo -e "Starting Grafana cotainer on Local port number $grafana_port. Please wait..\n"
106docker run -d -p $grafana_port:3000 grafana/grafana
107if [ $? != 0 ]
108then
109 exit 1
110fi
111sleep 5 #Give some time to spin the container and bring service up
112echo "Done."
113echo ""
114echo -e "--------------------------------------------------------------------\n"
115#Spin zookeeper container
116echo -e "Starting zookeeper container on Local port number $zookeeper_port. Please wait..\n"
117docker run -d --add-host mykafka:$local_ip --add-host myzoo:$local_ip \
118 -p $zookeeper_port:2181 -p 2888:2888 -p 3888:3888 \
119 -p 8800:8080 zookeeper
120if [ $? != 0 ]
121then
122 exit 1
123fi
124sleep 5
125echo "Done."
126echo ""
127echo -e "--------------------------------------------------------------------\n"
128#Spin Kafka container.
129echo -e "Starting Kafka container on Local port number $kafka_port. Please wait..\n"
130docker run -d --add-host mykafka:$local_ip -e zookeeper_host=$local_ip \
131 -e zookeeper_hostname='myzoo' -e zookeeper_port=$zookeeper_port \
132 -e kafka_hostname='mykafka' -e kafka_port=$kafka_port \
133 -p $kafka_port:$kafka_port ves-kafka
134if [ $? != 0 ]
135then
136 exit 1
137fi
138sleep 7
139echo "Done."
140echo ""
141echo -e "--------------------------------------------------------------------\n"
142#Spin Kafdrop UI container (this is optional componant)
143echo -e "Starting kafdrop UI container on Local port numner $kafdrop_port. please wait..\n"
144docker run -d --add-host mykafka:$local_ip -p $kafdrop_port:9000 \
145 -e KAFKA_BROKERCONNECT=$local_ip:$kafka_port \
146 -e JVM_OPTS="-Xms64M -Xmx128M" obsidiandynamics/kafdrop:latest
147if [ $? != 0 ]
148then
149 exit 1
150fi
151sleep 5
152echo "Done."
153echo ""
154echo -e "--------------------------------------------------------------------\n"
155# Spin ves-collector container.
156echo -e "Starting ves collector container on Local port number $vel_ves_port. Please wait\n"
157docker run -d -e ves_influxdb_host=$local_ip \
158 -e ves_influxdb_port=$influx_port -e ves_grafana_host=$local_ip \
159 -e ves_grafana_port=$grafana_port -e ves_host='localhost' \
160 -e ves_port=$vel_ves_port -e ves_grafana_auth='admin:admin' \
161 -e ves_user='user' -e ves_pass='password' -e ves_path=''\
162 -e ves_topic='events' -e ves_loglevel='DEBUG' \
163 -p $vel_ves_port:$vel_ves_port ves-collector
164if [ $? != 0 ]
165then
166 exit 1
167fi
168sleep 6
169echo "Done."
170echo ""
171echo -e "--------------------------------------------------------------------\n"
172#Spin ves agent container.
173echo -e "Starting ves agent container. Please wait\n"
174docker run -d -e ves_kafka_host=$local_ip \
175 -e ves_kafka_hostname='mykafka' -e ves_host=$local_ip \
176 -e ves_port=$vel_ves_port -e ves_path='' \
177 -e ves_topic='events' -e ves_https='False' -e ves_user='user' \
178 -e ves_pass='password' -e ves_interval='10' \
179 -e ves_kafka_port=$kafka_port -e ves_mode='./yaml/host' \
180 -e ves_version='7' -e ves_loglevel='DEBUG' ves-agent
181if [ $? != 0 ]
182then
183 exit 1
184fi
185sleep 5
186echo "Done."
187echo ""
188echo -e "--------------------------------------------------------------------\n"
189echo""
190echo -e "ves stack summary\n"
191echo -e "===================================================================================================================\n"
192echo ""
193echo -e "Kafka port: $kafka_port \n"
194echo -e "Kafdrop port: $kafdrop_port \n"
195echo -e "ves collector listner port: $vel_ves_port \n"
196echo -e "Grafana port: $grafana_port \n"
197echo -e "To access kafdrop UI use http://$local_ip:$kafdrop_port from your web browser. \n"
198echo -e "To access grafana dashboard paste url http://$local_ip:$grafana_port in web browser. "
199echo -e "Grafana username/password is admin/admin *** DO NOT CHANGE THE ADMIN PASSWORD, CLICK SKIP OPTION ***\n"
200echo ""
201echo -e "===================================================================================================================\n"