Prometheus is an open-source monitoring system that allows you to collect and analyze various metrics from your applications and infrastructure. It is designed to be highly scalable and adaptable, making it an excellent choice for monitoring large-scale environments.
In this article, we will discuss how to install Prometheus using Docker on CentOS 7.
- A CentOS 7 machine with root access.
Update the system.
# sudo yum update -y
Add the Docker repository.
# sudo yum install -y yum-utils
# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Install Docker and other dependencies.
# sudo yum -y install docker-ce docker-ce-cli containerd.io
Start and enable the docker service.
# sudo systemctl start docker
# sudo systemctl enable docker
To install Prometheus using Docker, follow these steps.
Create a new directory to store the Prometheus configuration file.
# mkdir -p /opt/prometheus
Create a new file called "prometheus.yml".
# sudo vi /opt/prometheus/prometheus.yml
Add the following content to the "prometheus.yml" file.
This configuration file defines two scrape jobs. The first job scrapes data from the Prometheus server itself, and the second job scrapes data from the Node Exporter, which is a tool that collects system-level metrics.
- job_name: 'prometheus'
- targets: ['localhost:9090']
- job_name: 'node_exporter'
- targets: ['your_server_ip:9100']
your_server_ipwith your server IP address.
Run the following command to start the Prometheus container.
# docker run -d --name prometheus -p 9090:9090 -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
You can list all running Docker containers using the following command.
# docker ps
Verify that Prometheus is running by opening a web browser and navigating to "http://your_server_ip:9090". You should see the Prometheus web UI.