Here are the steps to set up Prometheus on Ubuntu:
First, you need to download the latest version of Prometheus from the official website.
wget https://github.com/prometheus/prometheus/releases/download/v2.30.2/prometheus-2.30.2.linux-amd64.tar.gz
Then extract the content of the downloaded file:
tar -xzf prometheus-2.30.2.linux-amd64.tar.gz
This will create a directory named prometheus-2.30.2.linux-amd64
which contains the Prometheus files.
For security purposes, it is best to create a dedicated user to run Prometheus.
sudo useradd -rs /bin/false prometheus
Create a new directory for the Prometheus configuration files and move the sample configuration file to this directory:
sudo mkdir /etc/prometheus
sudo mv prometheus-2.30.2.linux-amd64/prometheus.yml /etc/prometheus/prometheus.yml
Edit the Prometheus configuration file using a text editor of your preference:
sudo nano /etc/prometheus/prometheus.yml
You will find a list of targets, which are the endpoints that Prometheus will scrape. Modify this list to add the endpoints of the systems that you want to monitor.
To start and stop Prometheus automatically, create a systemd service file:
sudo nano /etc/systemd/system/prometheus.service
Paste the following configuration into the file:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/usr/local/share/prometheus/console_templates \
--web.console.libraries=/usr/local/share/prometheus/console_libraries \
--web.enable-lifecycle
[Install]
WantedBy=multi-user.target
Save and close the file.
Prometheus stores its data in a directory. Create the directory and assign it to the Prometheus user:
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
Start the Prometheus service, and enable it to start at boot time:
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
Check the status of Prometheus to ensure that it has started correctly:
sudo systemctl status prometheus
If there are any problems, refer to the log files and troubleshoot as needed.
The Prometheus server should now be up and running, ready to start monitoring your system!
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-05-16 11:00:00 +0000
Seen: 22 times
Last updated: Nov 27 '21