How to do a basic install of Prometheus and Grafana on Ubuntu?
I will assume your machine is Ubuntu >= 16.04.
Please make sure only ports 80 and 443 are open.
I assume there are two DNS entries to your machine, such as
prometheus.blablabla.com and grafana.blablabla.com (replace as
appropriate throughout the tutorial).
Follow the steps (you can replace version 2.4.3 with whatever latest
version is available for you):
Create the file /etc/systemd/system/prometheus.service and put the
following content in it:
To install Grafana:
Do not try to configure Grafana yet! We need to do all the SSL stuff
Reverse-proxy and SSL certificates
Follow the steps:
Reverse-proxy for Prometheus
Prometheus web interface has no authentication mechanism, so we will
add one with nginx.
To install nginx as a reverse-proxy for SSL termination and
authentication for Prometheus (replace USERNAME and PASSWORD with a
username and password of your choice):
Then edit the file /etc/nginx/sites-available/prometheus to look
like this (replace prometheus.blablabla.com with your real domain
name; NB: don’t worry if the SSL config seems to lack some stuff,
things will be added by certbot later):
Create an SSL certificate for prometheus.blablabla.com:
Certbot will start an interactive session. Answer as follows:
When asked for your email address, enter it
Agree to the terms of service
Agree or not to the marketing, that has no incidence on your SSL
When asked to redirect all HTTP traffic to HTTPS, choose to
Reverse-proxy for Grafana
Edit the file /etc/nginx/sites-available/grafana to look like this
(same remarks as before):
Answer the interactive prompts in the same manner as previously.
Open your favourite browser to https://grafana.blablabla.com. The
Grafana login page should come up. Enter admin for both the username
and password; the next page should ask you for a more secure password.
Then click on the 2nd icon “Add data source” and enter the following
Name: Whatever you like
URL: http://localhost:9090 (reminder: Prometheus is running on
the same VM as Grafana)
Leave the rest untouched
Click “Save & Test”
You should see a message at the bottom of the page “Data source is
Install and configure Alertmanager
This is an optional extra to receive some notifications when certain
metrics go outside a certain range.
Follow these steps to install Alertmanager (you can replace version
0.15.2 with whatever latest version is available for you:
Create the file /etc/alertmanager/alertmanager.yml so it looks like
this (substitute the correct values for your setup):
Create the file /etc/systemd/system/altermanager.service and put the
following content in it:
You need to tell prometheus that an alertmanager service is available.
To do so, edit the /etc/prometheus/prometheus.yml file and add the
following at the end:
You should now have a basic Prometheus setup working.