How to Install Prometheus for System Monitoring on Ubuntu 18.04
Prometheus is an open-source monitoring and alerting toolkit that is widely used for system monitoring. Its powerful metrics collection capabilities and query language make it an essential tool for systems administrators. In this tutorial, we will guide you through the process of installing Prometheus on an Ubuntu 18.04 server.
Prerequisites
- Ubuntu 18.04 server instance.
- A non-root user with sudo privileges.
- Basic knowledge of the command line interface.
Main Steps
1. Update Your System
Before you begin the installation, it is important to ensure that your system packages are up to date. Open your terminal and run the following commands:
sudo apt update
sudo apt upgrade -y
2. Download Prometheus
Next, you will need to download the latest version of Prometheus from the official GitHub repository. You can check for the latest version on the Prometheus releases page.
wget https://github.com/prometheus/prometheus/releases/download/v2.36.0/prometheus-2.36.0.linux-amd64.tar.gz
3. Extract the Downloaded Archive
After downloading the file, you need to extract it using the following command:
tar xvfz prometheus-*.tar.gz
4. Move Prometheus Binaries
Once extracted, move the Prometheus binaries to the /usr/local/bin directory for easier access:
sudo mv prometheus-*/prometheus /usr/local/bin/
sudo mv prometheus-*/promtool /usr/local/bin/
5. Create a Prometheus User
For security reasons, it is advisable to run Prometheus as a dedicated user. Create a new user called prometheus:
sudo useradd --no-create-home --shell /bin/false prometheus
6. Create Directories for Prometheus
Create the necessary directories for Prometheus to store its configuration files and data:
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
7. Move Configuration Files
Next, move the default configuration files into the appropriate directory:
sudo mv prometheus-*/prometheus.yml /etc/prometheus/
sudo mv prometheus-*/consoles /etc/prometheus/
sudo mv prometheus-*/console_libraries /etc/prometheus/
8. Set Permissions
Change the ownership of the created directories and configuration files to the prometheus user:
sudo chown -R prometheus:prometheus /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus
9. Create a Systemd Service File
To manage Prometheus as a service, create a new systemd service file:
sudo nano /etc/systemd/system/prometheus.service
Then add the following configuration into the file:
[Unit]
Description=Prometheus Service
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Restart=always
RestartSec=5
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus/
[Install]
WantedBy=default.target
10. Start Prometheus Service
Reload the systemd configuration and start the Prometheus service:
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
11. Verify Prometheus Installation
To verify that Prometheus is running, open your web browser and navigate to http://your_server_ip:9090. You should see the Prometheus UI.
Advanced Configuration
To tailor Prometheus to your needs, you may wish to edit the prometheus.yml configuration file. Here are a few common adjustments:
- Configuring scrape targets to monitor specific applications or services.
- Setting up alerts using Alertmanager.
- Customizing retention policies for collected metrics.
Always back up your configuration files before making changes to avoid losing your settings.
Best Practices
- Regularly update Prometheus to benefit from new features and security updates.
- Monitor the performance and health of your Prometheus server to ensure it operates efficiently.
- Utilize labels and annotations effectively within your metrics to enhance query capabilities.
Troubleshooting
If you encounter issues while installing or running Prometheus, consider the following:
- Check the service status using
sudo systemctl status prometheusto see if there are errors. - Review the logs in
/var/log/syslogfor any error messages related to Prometheus. - Ensure that the network firewall allows traffic on port 9090.
Conclusion
In this tutorial, we have covered the comprehensive steps required to install Prometheus for system monitoring on Ubuntu 18.04. By following this guide, you should now have Prometheus running and ready to monitor your system metrics. Remember to keep your installation updated and make use of its powerful features to gain insights into your system's performance.
Verifikasi Teknis
Panduan ini disusun berdasarkan referensi teknis terbaru. Namun, konfigurasi server dapat bervariasi. Lihat sumber referensi asli →
📚 Artikel Terkait
Cara Install Grafana untuk System Monitoring di Ubuntu 18.04
607 kata • Baca selengkapnya →
Cara Install Prometheus untuk System Monitoring di Ubuntu 18.04
560 kata • Baca selengkapnya →
Cara Monitoring Bandwidth di Ubuntu
574 kata • Baca selengkapnya →
Cara Monitoring VPS DigitalOcean
579 kata • Baca selengkapnya →