要在Ubuntu上安装和配置Prometheus,您可以遵循以下步骤:
wget https://github.com/prometheus/prometheus/releases/download/vX.X.X/prometheus-X.X.X.linux-amd64.tar.gz
请将X.X.X
替换为您要下载的最新版本号。
tar xvf prometheus-X.X.X.linux-amd64.tar.gz
cd prometheus-X.X.X.linux-amd64
ls
/usr/local/bin/
目录下,以便在任何地方都可以访问它:sudo cp prometheus /usr/local/bin/
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
/etc/prometheus/
目录:sudo cp prometheus.yml /etc/prometheus/
sudo useradd -m -s /bin/false prometheus
/var/lib/prometheus/
目录的访问权限:sudo chown -R prometheus:prometheus /var/lib/prometheus/
编辑Prometheus配置文件prometheus.yml
,配置您的监控目标以及其他设置。您可以根据需要对其进行自定义。
创建一个用于启动和管理Prometheus服务的systemd单元文件prometheus.service
:
sudo nano /etc/systemd/system/prometheus.service
在文件中添加以下内容:
[Unit]
Description=Prometheus Monitoring
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
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
http://localhost:9090
来查看Prometheus的Web界面,并开始配置和监控您的系统。以上就是在Ubuntu上安装和配置Prometheus的基本步骤。希望对您有所帮助!