Instalando e configurando o PROMETHEUS no Ubuntu e CentOS! | Série Monitoração #3
Table of Contents
Introduction
This tutorial will guide you through the installation and configuration of Prometheus on Ubuntu and CentOS. Prometheus is a powerful monitoring tool that helps you keep track of your infrastructure seamlessly. Whether you are a beginner or an experienced user, this step-by-step guide will make the process straightforward.
Step 1: Update Your System
Before installing any new software, it's important to update your package lists to ensure you have the latest versions.
For Ubuntu:
sudo apt-get update
For CentOS:
sudo yum install -y curl wget vim
Step 2: Install Required Packages
Install essential packages needed for the setup.
For Ubuntu:
sudo apt-get install -y curl wget vim
For CentOS:
sudo yum install -y curl wget vim
Step 3: Create Prometheus User and Directories
Create a dedicated user for Prometheus and necessary directories for its operation.
-
Create directories:
sudo mkdir /etc/prometheus sudo mkdir /var/lib/prometheus
-
Create a user for Prometheus:
sudo useradd --no-create-home --shell /bin/false prometheus
-
Create a user for Node Exporter (if applicable):
sudo useradd --no-create-home --shell /bin/false node_exporter
Step 4: Download Prometheus
Fetch the Prometheus binaries from the official GitHub repository.
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar.gz
Step 5: Extract the Downloaded Files
Unpack the downloaded tarball.
tar xvf prometheus-2.0.0.linux-amd64.tar.gz
Step 6: Move Binaries to Local Bin
Copy the Prometheus binaries to the appropriate directory.
sudo cp prometheus-2.0.0.linux-amd64/prometheus /usr/local/bin/
sudo cp prometheus-2.0.0.linux-amd64/promtool /usr/local/bin/
Step 7: Configure Prometheus
Copy the necessary console files to the configuration directory.
sudo cp -r prometheus-2.0.0.linux-amd64/consoles /etc/prometheus
sudo cp -r prometheus-2.0.0.linux-amd64/console_libraries /etc/prometheus
Step 8: Clean Up
Remove the tarball and extracted directory to save space.
rm -rf prometheus-2.0.0.linux-amd64.tar.gz prometheus-2.0.0.linux-amd64
Step 9: Configure Prometheus Settings
Edit the main configuration file to set up your monitoring parameters.
-
Open the configuration file:
sudo vim /etc/prometheus/prometheus.yml
Use the configuration template provided in the video.
-
Edit the alert rules file:
sudo vim /etc/prometheus/alert.rules
Use the alert rules template provided in the video.
Step 10: Set Permissions
Change the ownership of the Prometheus files to the Prometheus user.
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
sudo chown -R prometheus:prometheus /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus
Step 11: Create a Systemd Service
Set up Prometheus to run as a service.
-
Create the service file:
sudo vim /etc/systemd/system/prometheus.service
Use the service file template provided in the video.
-
Reload the systemd daemon:
sudo systemctl daemon-reload
-
Start the Prometheus service:
sudo systemctl start prometheus
-
Check the status of the service:
sudo systemctl status prometheus
Step 12: Verify Installation
Ensure Prometheus is running on the default port (9090).
netstat -atunp | grep 9090
Conclusion
You have successfully installed and configured Prometheus on your Ubuntu or CentOS system. By following these steps, you can monitor your infrastructure effectively. For further enhancements, consider integrating Node Exporter or setting up alerting rules tailored to your needs. Happy monitoring!