Skip to content

Instantly share code, notes, and snippets.

@Bharat-B
Created February 4, 2022 18:46
Show Gist options
  • Save Bharat-B/d655c244e070b169aadc4a14f1d06735 to your computer and use it in GitHub Desktop.
Save Bharat-B/d655c244e070b169aadc4a14f1d06735 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Grafana Repository and Installation commands
wget -q -O - https://packages.grafana.com/gpg.key | apt-key add -
add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
apt-get update
apt-get install grafana
systemctl enable grafana-server
systemctl start grafana-server
# The following package allows you to run commands like netstat, ifconfig etc.
apt-get install net-tools -y
# The following commands shows what port grafana is listening on
netstat -plunt | grep grafana
# Installing nGINX
apt-get install nginx -y
# Open the following file to overwrite the configuration as described in the Tutorial
nano /etc/nginx/sites-enabled/default
# Setting up SSL via letsencrypt
wget https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh
chmod +x acme.sh
./acme.sh --issue -d domain.tld -w /var/www/html --home /etc/nginx/ssl
# Setup a cron for ACME to auto renew your ssl and nginx to reload 5 minutes later
echo "0 0 * * * root /root/acme.sh --cron --home /etc/nginx/ssl" > /etc/cron.d/acme.cron
echo "05 0 * * * root /sbin/nginx -s reload" > /etc/cron.d/nginx.cron
# Setting up VictoriaMetrics
apt-get install -y jq
export VM_VER=`curl -s https://api.github.com/repos/VictoriaMetrics/VictoriaMetrics/releases/latest | jq -r '.tag_name'`
curl -L https://github.com/VictoriaMetrics/releases/download/${VM_VER}/victoria-metrics-amd64-${VM_VER}.tar.gz --output victoria-metrics-amd64-${VM_VER}.tar.gz
tar -zxvf victoria-metrics-amd64-${VM_VER}.tar.gz
mv victoria-metrics-prod /usr/local/bin
chmod +x /usr/local/bin/victoria-metrics-prod
cat <<EOF > /etc/systemd/system/victoriametrics.service
[Unit]
Description=High-Permance, scalable time series database for prometheus
After=network.target
[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/local/bin/victoria-metrics-prod -storageDataPath=/mnt/victoria_metrics -httpListenAddr=127.0.0.1:8429 -retentionPeriod=3
ExecStop=/bin/kill -s SIGTERM $MAINPID
LimitNOFILE=65536
LimitNPROC=32000
[Install]
WantedBy=multi-user.target
EOF
# Installing Telegraf
wget -q -O - https://repos.influxdata.com/influxdb.key | apt-key add -
add-apt-repository "deb https://repos.influxdata.com/ubuntu focal stable"
apt-get update
apt-get install apt-transport-https telegraf -y
@Bharat-B
Copy link
Author

Bharat-B commented Feb 5, 2022

server {
        listen 80 default_server;
        listen [::]:80 default_server;
#       server_name monitoring.readydedis.com;  
        location /.well-known {
                root /var/www/html;
        }
        location / {
                return 301 https://$host$request_uri;
        }
}

server {
        listen 443 ssl;
        server_name monitoring.readydedis.com;
        ssl_certificate /etc/nginx/ssl/monitoring.readydedis.com/fullchain.cer;
        ssl_certificate_key /etc/nginx/ssl/monitoring.readydedis.com/monitoring.readydedis.com.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
        location / {
                proxy_pass http://localhost:3000;
        }
          location /api/live/ws {
            rewrite  ^/(.*)  /$1 break;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $http_host;
            proxy_pass http://127.0.0.1:3000/;
        }
}

This is the final file for the tutorial, I forgot to cover the websockets issue that is caused by reverse proxy :)

@binitta21
Copy link

Install VictoriaMetrics Single

VM_VERSION=curl -sg "https://api.github.com/repos/VictoriaMetrics/VictoriaMetrics/tags" | jq -r '.[0].name'
wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/${VM_VERSION}/victoria-metrics-linux-amd64-${VM_VERSION}.tar.gz -O /tmp/victoria-metrics.tar.gz
tar xvf /tmp/victoria-metrics.tar.gz -C /usr/bin
chmod +x /usr/bin/victoria-metrics-prod
chown root:root /usr/bin/victoria-metrics-prod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment