#! /bin/bash . /usr/src/m2/framework/settings.sh . /usr/src/m2/framework/bash_functions.sh # ---- VARS ----- VERSION="1.1.4" SCRIPT_NAME="Prometheus/Grafana install" # Supports Centos 7 and Centos 8 # ---- MAIN ----- k_start _centos_version if (( centos_version > 6 )); then report "Centos: $centos_version" 0 else report "Wrong Centos version: $centos_version. Script can only be run on Centos 7/8" k_exit 1 fi # --- Prometheus --- # maybe it's already installed? if [[ -d "/home/prometheus" ]] then report "Prometheus is already installed" 3 #/bin/systemctl status prometheus | grep 'Active\|Prometheus Server' #/bin/systemctl status grafana-server.service | grep 'Active\|Grafana instance' k_exit 0 fi report "Installing dependencies" 3 yum -y install net-tools wget firewalld tar sqlite # making sure firewall is up systemctl start firewalld systemctl enable firewalld if (systemctl -q is-active firewalld.service); then report "Firewalld is active" 0 else report "Firewalld is not active" 1 k_exit 1 fi # Selinux off cd /usr/src/m2/maintenance ./selinux_disable.sh # Time-sync (currently fails on C8) if (( centos_version == 7 )); then ./time_sync.sh fi report "Installing Prometheus" 3 # check newest prometheus version here: https://github.com/prometheus/prometheus/releases version="2.22.0" cd /usr/src/ wget https://github.com/prometheus/prometheus/releases/download/v$version/prometheus-$version.linux-amd64.tar.gz tar -xzvf prometheus-$version.linux-amd64.tar.gz mv prometheus-$version.linux-amd64/ prometheus/ mkdir /home/prometheus mv /usr/src/prometheus /home/prometheus/prometheus # configure Systemd Service cd /etc/systemd/system/ touch prometheus.service cat << 'EOF' > /etc/systemd/system/prometheus.service [Unit] Description=Prometheus Server Documentation=https://prometheus.io/docs/introduction/overview/ After=network-online.target [Service] User=root Restart=on-failure ExecStart=/home/prometheus/prometheus/prometheus \ --config.file=/home/prometheus/prometheus/prometheus.yml \ --storage.tsdb.path=/home/prometheus/prometheus/data [Install] WantedBy=multi-user.target EOF /bin/systemctl start prometheus /bin/systemctl enable prometheus # sane location for prometheus config mkdir -p /etc/prometheus ln -s /home/prometheus/prometheus/prometheus.yml /etc/prometheus/prometheus.yml # is it running? if (systemctl -q is-active prometheus.service); then report "Prometheus is active" 0 else report "Prometheus is not active" 1 k_exit 1 fi netstat -plntu | grep prometheus # --- Grafana --- report "Installing Grafana" 3 # newest version: https://grafana.com/grafana/download # over there: Red Hat, CentOS, RHEL, and Fedora(64 Bit) SHA256: # wget https://dl.grafana.com/oss/release/grafana-7.2.2-1.x86_64.rpm grafana_version="7.2.2-1" yum -y install initscripts urw-fonts fontconfig freetype* cd /usr/src/ wget https://dl.grafana.com/oss/release/grafana-$grafana_version.x86_64.rpm yum -y localinstall grafana-$grafana_version.x86_64.rpm /bin/systemctl daemon-reload /bin/systemctl enable grafana-server.service /bin/systemctl start grafana-server.service if (systemctl -q is-active grafana-server.service); then report "Grafana is active" 0 else report "Grafana is not active" 1 k_exit 1 fi report "Configuring Grafana" 3 # add Prometheus as data-source sleep 2 # to avoid "database is locked" cat <