daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Jun 4th, 2017 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # This script will install Docker, Grafana, InfluxDB, Graphite & CollectD. It will also add systemd service files to ensure auto startup each boot.
  4. # This script was created by reddit user /u/tyler_hammer. This is a combination of several guides with edits to make it as easy as possible for new people to start.
  5.  
  6. # Checking for Root Permissions # Thanks to Github User "codygarver" for the recommendation
  7. check_your_privilege () {
  8.     if [[ "$(id -u)" != 0 ]]; then
  9.         echo -e "\e[91mError: This setup script requires root permissions. Please run the script as root.\e[0m" > /dev/stderr
  10.         exit 1
  11.     fi
  12. }
  13. check_your_privilege
  14.  
  15. # Docker Installation for Ubuntu 16.04
  16.  
  17. clear
  18.  
  19. # Grab IP for Link
  20. myip=$(ip route | head -n 1 | egrep 'dev (.*)' -o | cut -d' ' -f2 | xargs ip a s $1 | egrep '([0-9]{1,3}\.){3}[0-9]{1,3}' -o | awk '{ if (NR == 1) print $1}')
  21.  
  22. # Update Package Database
  23. while true; do
  24.     echo -n -e "\e[7mDo you wish to run system updates? [y/n]:\e[0m "
  25.     read yn
  26.     case $yn in
  27.         [yY] | [yY][Ee][Ss] ) echo -ne "\e[36mUpdating System - This may take awhile!\e[0m";  sudo apt-get -y update >/dev/null 2>>install.log && sudo apt-get -y upgrade >/dev/null 2>>install.log;clear;echo -e "\r\033[K\e[36mUpdating System ----- Complete\e[0m"; break;; #(Run both in one line)
  28.         [nN] | [n|N][O|o] ) echo -e "\e[36mSkipping Updates\e[0m"; break;;  #Boring people don't update
  29.         * ) echo -e "\e[7mPlease answer y or n.\e[0m ";;  #Error handling to get the right answer
  30.     esac
  31. done
  32.  
  33. # Add GPG Key for Docker Repo
  34. echo -ne "\e[36mAdding GPG Key for Docker Repo\e[0m"
  35. apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D >>/dev/null 2>>install.log
  36. echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list >>/dev/null 2>>install.log
  37. echo -e "\r\033[K\e[36mAdding GPG Key for Docker Repo ----- Complete\e[0m"
  38.  
  39. # Update Database
  40. echo -ne "\e[36mUpdating Database\e[0m"
  41. apt-get update >>/dev/null 2>>install.log
  42. echo -e "\r\033[K\e[36mUpdating Database ----- Complete\e[0m"
  43.  
  44. # Verify Repo
  45. echo -ne "\e[36mVerifying Repo\e[0m"
  46. apt-cache policy docker-engine >>/dev/null 2>>install.log
  47. echo -e "\r\033[K\e[36mVerifying Repo ----- Complete\e[0m"
  48.  
  49. # Install Docker
  50. echo -ne "\e[36mInstalling Docker\e[0m"
  51. apt-get install -y docker-engine >>/dev/null 2>>install.log
  52. echo -e "\r\033[K\e[36mInstalling Docker ----- Complete\e[0m"
  53.  
  54. # Grafana Install - Docker - Ubuntu 16.04
  55.  
  56. echo
  57.  
  58. clear
  59.  
  60. echo -e "\e[7mPlease specify an admin password for Grafana\e[0m"
  61. read -p "> " -s GADMINPW
  62.  
  63. echo
  64. echo
  65.  
  66. echo -e "\e[7mPlease re-enter the password\e[0m"
  67. read -p "> " -s GADMINPW2
  68.  
  69. echo
  70. echo
  71.  
  72. while [ "${GADMINPW}" != "${GADMINPW2}" ];
  73. do
  74.     echo
  75.     echo -e "\e[41mPasswords do not match, please try again!\e[0m"
  76.     echo
  77.     echo -e "\e[7mPlease specify an admin password for Grafana\e[0m"
  78.     read -p "> " -s GADMINPW
  79.     echo
  80.     echo
  81.     echo -e "\e[7mPlease re-enter the password\e[0m"
  82.     read -p "> " -s GADMINPW2
  83.     echo
  84. done
  85.  
  86. # Create Grafana Docker
  87. clear
  88. echo -e "\r\033[K\e[36mUpdating System ----- Complete\e[0m"
  89. echo -e "\r\033[K\e[36mAdding GPG Key for Docker Repo ----- Complete\e[0m"
  90. echo -e "\r\033[K\e[36mUpdating Database ----- Complete\e[0m"
  91. echo -e "\r\033[K\e[36mVerifying Repo ----- Complete\e[0m"
  92. echo -e "\r\033[K\e[36mInstalling Docker ----- Complete\e[0m"
  93. echo -e "\r\033[K\e[36mCreating persistent storage for Grafana ----- Complete\e[0m"
  94.  
  95. echo -ne "\e[36mCreating Grafana docker container - This make take awhile!\e[0m"
  96. sudo docker create \
  97. --name=grafana \
  98. -e PUID=1000 -e PGID=1000 \
  99. -p 3000:3000 \
  100. --restart always \
  101. -v /docker/containers/grafana/sqlite3/:/var/lib/grafana \
  102. -v /docker/containers/grafana/config/:/etc/grafana \
  103. -e "GF_SECURITY_ADMIN_PASSWORD=${GADMINPW}" \
  104. grafana/grafana >>/dev/null 2>>install.log
  105. echo -e "\r\033[K\e[36mCreating Grafana docker container ----- Complete\e[0m"
  106.  
  107. # Start Grafana Docker
  108. echo -ne "\e[36mStarting Grafana\e[0m"
  109. docker start grafana >>/dev/null 2>>install.log
  110. echo -e "\r\033[K\e[36mStarting Grafana ----- Complete\e[0m"
  111.  
  112. # Make Bin folder for update scripts
  113. echo -ne "\e[36mCreating Update Folder\e[0m"
  114. mkdir ~/updates >>/dev/null 2>>install.log
  115. echo -e "\r\033[K\e[36mCreating Update Folder ----- Complete\e[0m"
  116.  
  117. # Download Grafana Update Script
  118. echo -ne "\e[36mDownloading Grafana update script\e[0m"
  119. wget https://raw.githubusercontent.com/tylerhammer/grafana/master/Update%20Scripts/grafanaupdate.sh -O ~/updates/updategrafana.sh >>/dev/null 2>>install.log
  120. echo -e "\r\033[K\e[36mDownloading Grafana update script ----- Complete\e[0m"
  121.  
  122. # InfluxDB - Docker - Ubuntu 16.04
  123.  
  124. # Create Local Storage
  125. echo -ne "\e[36mCreating local storage for InfluxDB\e[0m"
  126. mkdir -p /docker/containers/influxdb/conf/ >>/dev/null 2>>install.log
  127. mkdir -p /docker/containers/influxdb/db/ >>/dev/null 2>>install.log
  128. echo -e "\r\033[K\e[36mCreating local storage for InfluxDB ----- Complete\e[0m"
  129.  
  130. # Check Ownership
  131. echo -ne "\e[36mVerifying ownership\e[0m"
  132. chown ${USER:=$(/usr/bin/id -run)}:$USER -R /docker >>/dev/null 2>>install.log
  133. echo -e "\r\033[K\e[36mVerifying ownership ----- Complete\e[0m"
  134.  
  135. # Generate Default Config
  136. echo -ne "\e[36mGenerating default config file for InfluxDB\e[0m"
  137. docker run --rm influxdb influxd config > /docker/containers/influxdb/conf/influxdb.conf 2>>install.log
  138. echo -e "\r\033[K\e[36mGenerating default config file for InfluxDB ----- Complete\e[0m"
  139.  
  140. # Create InfluxDB Container
  141. echo -ne "\e[36mCreating InfluxDB docker container - This make take awhile!\e[0m"
  142. docker create \
  143. --name influxdb \
  144. -e PUID=1000 -e PGID=1000 \
  145. -p 8083:8083 -p 8086:8086 \
  146. -v /docker/containers/influxdb/conf/influxdb.conf:/etc/influxdb/influxdb.conf:ro \
  147. -v /docker/containers/influxdb/db:/var/lib/influxdb \
  148. influxdb -config /etc/influxdb/influxdb.conf >>/dev/null 2>>install.log
  149. echo -e "\r\033[K\e[36mCreating InfluxDB docker container ----- Complete\e[0m"
  150.  
  151. # Start InfluxDB
  152. echo -ne "\e[36mStarting InfluxDB\e[0m"
  153. docker start influxdb >>/dev/null 2>>install.log
  154. echo -e "\r\033[K\e[36mStarting InfluxDB ----- Complete\e[0m"
  155.  
  156. # Create Influx Update Script
  157. echo -ne "\e[36mDownloading InfluxDB update script\e[0m"
  158. wget https://raw.githubusercontent.com/tylerhammer/grafana/master/Update%20Scripts/influxdbupdate.sh -O ~/updates/influxupdate.sh >>/dev/null 2>>install.log
  159. echo -e "\r\033[K\e[36mDownloading InfluxDB update script ----- Complete\e[0m"
  160.  
  161. # Setup Auto Start
  162. echo -ne "\e[36mCreating InfluxDB SystemD file\e[0m"
  163. sudo bash -c "cat >/lib/systemd/system/influxdb.service" << EOF  2>>install.log
  164. [Unit]
  165.  Description=influxdb container
  166.  Requires=docker.service
  167.  After=docker.service
  168.  
  169. [Service]
  170.  User=root
  171.  Restart=on-failure
  172.  RestartSec=45
  173.  ExecStart=/usr/bin/docker start -a influxdb
  174.  ExecStop=/usr/bin/docker stop -t 2 influxdb
  175.  
  176. [Install]
  177.  WantedBy=multi-user.target
  178. EOF
  179. echo -e "\r\033[K\e[36mCreating InfluxDB SystemD file ----- Complete\e[0m"
  180.  
  181. # Enable Service
  182. echo -ne "\e[36mEnabling InfluxDB Service\e[0m"
  183. systemctl enable influxdb.service >>/dev/null 2>>install.log
  184. echo -e "\r\033[K\e[36mEnabling InfluxDB Service ----- Complete\e[0m"
  185.  
  186. # Graphite Install - Docker - Ubuntu 16.04
  187.  
  188. # Create Graphite Container
  189. echo -ne "\e[36mCreating Graphite docker container - This may take awhile!\e[0m"
  190. docker run -d\
  191.  --name graphite\
  192.  --restart=always\
  193.  -p 80:80\
  194.  -p 2003-2004:2003-2004\
  195.  -p 2023-2024:2023-2024\
  196.  -p 8125:8125/udp\
  197.  -p 8126:8126\
  198.  hopsoft/graphite-statsd >>/dev/null 2>>install.log
  199. echo -e "\r\033[K\e[36mCreating Graphite docker container ----- Complete\e[0m"
  200.  
  201. # Auto Start
  202. echo -ne "\e[36mCreating Graphite SystemD file\e[0m"
  203. sudo bash -c "cat >/lib/systemd/system/graphite.service" << EOF
  204. [Unit]
  205.  Description=Graphite container
  206.  Requires=docker.service
  207.  After=docker.service
  208.  
  209. [Service]
  210.  User=root
  211.  Restart=on-failure
  212.  RestartSec=45
  213.  ExecStart=/usr/bin/docker start -a graphite
  214.  ExecStop=/usr/bin/docker stop -t 2 graphite
  215.  
  216. [Install]
  217.  WantedBy=multi-user.target
  218. EOF
  219. echo -e "\r\033[K\e[36mCreating Graphite SystemD file ----- Complete\e[0m"
  220.  
  221. # Enable Service
  222. echo -ne "\e[36mEnabling Graphite Service\e[0m"
  223. systemctl enable graphite.service >>/dev/null 2>>install.log
  224. echo -e "\r\033[K\e[36mEnabling Graphite Service ----- Complete\e[0m"
  225.  
  226. # Enable InfluxDB WebUI
  227. echo -ne "\e[36mEnabling InfluxDB WebUI\e[0m"
  228. sed -i '40s/.*/  enabled = true/' /docker/containers/influxdb/conf/influxdb.conf >>/dev/null 2>>install.log
  229. echo -e "\r\033[K\e[36mEnabling InfluxDB WebUI ----- Complete\e[0m"
  230.  
  231. # Install other dependencies
  232. echo -ne "\e[36mInstalling SSHPASS and SNMP dependencies - This may take awhile!\e[0m"
  233. apt-get install -y sshpass >>/dev/null 2>>install.log
  234. apt-get install -y snmp snmp-mibs-downloader >>/dev/null 2>>install.log
  235. echo -e "\r\033[K\e[36mInstalling SSHPASS and SNMP dependencies ----- Complete\e[0m"
  236.  
  237. # Remove the need to user Sudo before docker. This generally requires you to log out and log back in, which is why we restart at the end of the script.
  238. echo -ne "\e[36mRemoving "Sudo" requirement from docker command\e[0m"
  239. sudo usermod -aG docker $(logname) >>/dev/null 2>>install.log
  240. echo -e "\r\033[K\e[36mRemoving "Sudo" requirement from docker command ----- Complete\e[0m"
  241.  
  242.  
  243. # Restart Announcment for previous command
  244. echo -e "\e[7mThe VM needs to be restarted in order to apply changes and finalize the installation.\e[0m"
  245.  
  246. echo -e "\e[7mAfter the restart, Grafana can be accessed via http://${myip}:3000 & the InfluxDB AdminUI can be accessed via http://${myip}:8083\e[0m"
  247.  
  248. echo -n "Press any key to restart"
  249. read -rsn1
  250.  
  251. # Restart
  252. reboot
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top