In this post, we will know How to Prometheus Running on Different Port
if you have followed this tutorial before, Prometheus is running well on localhost on port 9090
So, in order for to Prometheus Run on Different Port, we are going to modify its systemd startup file /etc/systemd/system/prometheus.service
.
Edit it with nano:
sudo nano /etc/systemd/system/prometheus.service
[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=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
Add this line after the last line before the [Install] section
--web.listen-address="127.0.0.1:9090"
And then it should be like this:
[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=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.listen-address="127.0.0.1:9090"
[Install]
WantedBy=multi-user.target
If you want to change port to port 7001, you can change it into
--web.listen-address="127.0.0.1:7001"
Save it with CTRL+X and choose Yes.
Reload daemon, and then restart Prometheus service
sudo systemctl daemon-reload
Restart Prometheus service using the following command:
sudo systemctl restart prometheus
Done!