santanude | f22d9b5 | 2021-07-27 15:43:30 +0530 | [diff] [blame] | 1 | #!/bin/bash |
santanude | bc32a2a | 2021-09-24 17:47:31 +0530 | [diff] [blame^] | 2 | # 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 | # |
santanude | f22d9b5 | 2021-07-27 15:43:30 +0530 | [diff] [blame] | 16 | # 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 | |
| 34 | influx_port=3330 |
| 35 | grafana_port=8880 |
| 36 | kafka_port=9092 |
| 37 | kafdrop_port=9000 |
| 38 | zookeeper_port=2181 |
| 39 | vel_ves_port=9999 |
| 40 | |
| 41 | OS=`uname -s` |
| 42 | # Check Docker, collectd, ip and git is installed on the VM |
| 43 | |
| 44 | if ! 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; |
| 47 | fi |
| 48 | |
| 49 | if ! 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; |
| 60 | fi |
| 61 | |
| 62 | if ! 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; |
| 74 | fi |
| 75 | |
| 76 | clear |
| 77 | |
| 78 | #get local ip address of VM from first interface |
| 79 | if [ $OS = 'Darwin' ] |
| 80 | then |
| 81 | local_ip=`ip -4 addr list | grep en11 | grep inet | awk '{print $2}' | cut -d/ -f1` |
| 82 | elif [ $OS = 'Linux' ] |
| 83 | then |
| 84 | local_ip=`/sbin/ip -o -4 addr list | grep enp | head -n 1 | awk '{print $4}' | cut -d/ -f1` |
| 85 | else |
| 86 | echo -e "Could not determine which OS this.\n" |
| 87 | exit 1 |
| 88 | fi |
| 89 | echo -e "Binding VES Services to local ip address $local_ip \n " |
| 90 | echo "" |
| 91 | echo -e "--------------------------------------------------------------------\n" |
| 92 | #Spin influx DB |
| 93 | echo -e "Starting influxdb container on Local Port Number $influx_port. Please wait..\n" |
| 94 | docker run -d -p $influx_port:8086 -v $PWD/influxdb influxdb:1.8.5 |
| 95 | if [ $? != 0 ] |
| 96 | then |
| 97 | exit 1 |
| 98 | fi |
| 99 | |
| 100 | sleep 5 #Give some time to spin the container and bring service up |
| 101 | echo "Done." |
| 102 | echo"" |
| 103 | echo -e "--------------------------------------------------------------------\n" |
| 104 | #Spin Grafana Cotainer |
| 105 | echo -e "Starting Grafana cotainer on Local port number $grafana_port. Please wait..\n" |
| 106 | docker run -d -p $grafana_port:3000 grafana/grafana |
| 107 | if [ $? != 0 ] |
| 108 | then |
| 109 | exit 1 |
| 110 | fi |
| 111 | sleep 5 #Give some time to spin the container and bring service up |
| 112 | echo "Done." |
| 113 | echo "" |
| 114 | echo -e "--------------------------------------------------------------------\n" |
| 115 | #Spin zookeeper container |
| 116 | echo -e "Starting zookeeper container on Local port number $zookeeper_port. Please wait..\n" |
| 117 | docker 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 |
| 120 | if [ $? != 0 ] |
| 121 | then |
| 122 | exit 1 |
| 123 | fi |
| 124 | sleep 5 |
| 125 | echo "Done." |
| 126 | echo "" |
| 127 | echo -e "--------------------------------------------------------------------\n" |
| 128 | #Spin Kafka container. |
| 129 | echo -e "Starting Kafka container on Local port number $kafka_port. Please wait..\n" |
| 130 | docker 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 |
| 134 | if [ $? != 0 ] |
| 135 | then |
| 136 | exit 1 |
| 137 | fi |
| 138 | sleep 7 |
| 139 | echo "Done." |
| 140 | echo "" |
| 141 | echo -e "--------------------------------------------------------------------\n" |
| 142 | #Spin Kafdrop UI container (this is optional componant) |
| 143 | echo -e "Starting kafdrop UI container on Local port numner $kafdrop_port. please wait..\n" |
| 144 | docker 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 |
| 147 | if [ $? != 0 ] |
| 148 | then |
| 149 | exit 1 |
| 150 | fi |
| 151 | sleep 5 |
| 152 | echo "Done." |
| 153 | echo "" |
| 154 | echo -e "--------------------------------------------------------------------\n" |
| 155 | # Spin ves-collector container. |
| 156 | echo -e "Starting ves collector container on Local port number $vel_ves_port. Please wait\n" |
| 157 | docker 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 |
| 164 | if [ $? != 0 ] |
| 165 | then |
| 166 | exit 1 |
| 167 | fi |
| 168 | sleep 6 |
| 169 | echo "Done." |
| 170 | echo "" |
| 171 | echo -e "--------------------------------------------------------------------\n" |
| 172 | #Spin ves agent container. |
| 173 | echo -e "Starting ves agent container. Please wait\n" |
| 174 | docker 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 |
| 181 | if [ $? != 0 ] |
| 182 | then |
| 183 | exit 1 |
| 184 | fi |
| 185 | sleep 5 |
| 186 | echo "Done." |
| 187 | echo "" |
| 188 | echo -e "--------------------------------------------------------------------\n" |
| 189 | echo"" |
| 190 | echo -e "ves stack summary\n" |
| 191 | echo -e "===================================================================================================================\n" |
| 192 | echo "" |
| 193 | echo -e "Kafka port: $kafka_port \n" |
| 194 | echo -e "Kafdrop port: $kafdrop_port \n" |
| 195 | echo -e "ves collector listner port: $vel_ves_port \n" |
| 196 | echo -e "Grafana port: $grafana_port \n" |
| 197 | echo -e "To access kafdrop UI use http://$local_ip:$kafdrop_port from your web browser. \n" |
| 198 | echo -e "To access grafana dashboard paste url http://$local_ip:$grafana_port in web browser. " |
| 199 | echo -e "Grafana username/password is admin/admin *** DO NOT CHANGE THE ADMIN PASSWORD, CLICK SKIP OPTION ***\n" |
| 200 | echo "" |
| 201 | echo -e "===================================================================================================================\n" |