
我在全新安裝的 Ubuntu 16.04 上安裝最新版本的 Prometheus 時遇到問題。我能找到的所有指南均適用於 14.04,從 systemV 遷移到 systemd 使得這些指南在 16.04 上設定時不相容(或至少不完整)。
我可以從 apt 安裝 Prometheus,但它安裝的版本是 0.16.2,目前版本是 1.0.2。
我一直用的是官方的prometheus.io 安裝指南和本數位海洋指南。
誰能幫我設定 systemd?我對 Ubuntu 比較有經驗,但是 systemd 的改變給我帶來了麻煩。
答案1
安裝普羅米修斯時,以下單元檔案對我有用伺服器版本 1.x(與導出器相對)。
# /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=prometheus
Restart=on-failure
ExecStart=/usr/local/bin/prometheus-1.1.2.linux-amd64/prometheus \
-config.file=/etc/prometheus/prometheus.yml \
-storage.local.path=/var/lib/prometheus/data
[Install]
WantedBy=multi-user.target
當然,這假設您已經建立了一個 prometheus 使用者並授予了必要的權限。
然後使用 WInfly 提到的指令。
$ sudo systemctl daemon-reload
$ sudo systemctl enable prometheus
$ sudo systemctl start prometheus
$ sudo systemctl status prometheus
我發現以下內容很有幫助:
普羅米修斯:https://blog.svedr.in/posts/prometheus-quick-start.html
單元檔案指令的手冊頁:https://www.freedesktop.org/software/systemd/man/systemd.directives.html
答案2
伺服器儲存參數名稱在版本 2.x 中更改,工作語法:
[Unit]
Description=Prometheus Server
After=network-online.target
[Service]
User=root
Restart=on-failure
ExecStart=/usr/local/bin/prometheus-2.2.1.linux-amd64/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus/data
[Install]
WantedBy=multi-user.target
答案3
我找到了我的答案本文。我在嘗試將其設定為與 systemd 一起運行時缺少的特定部分是建立單元檔案。下面是為 node_exporter 建立單元文件,然後將其作為服務運行。希望這對其他人有幫助!
建立單元檔案:
$ sudo vim /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
[Service]
User=vxx
ExecStart=/home/vxx/Prometheus/node_exporter/node_exporter
[Install]
WantedBy=default.target
然後重新載入守護程序後啟動服務或重新啟動伺服器:
$ sudo systemctl daemon-reload
$ sudo systemctl enable node_exporter.service
$ sudo systemctl start node_exporter.service
$ sudo systemctl status node_exporter.service
答案4
如果有人仍然回到這個問題,我已經根據以下腳本編寫了 prometheus、node_exporter 和 apache_exporter 的安裝這個 DigitalOcean 教學。
您可以在這裡找到我的腳本: https://github.com/icolwell/install_scripts
以下腳本可能令人感興趣:
prometheus_install.bash
prometheus_node_exporter_install.bash
prometheus_apache_exporter_install.bash
您可以使用以下命令下載並執行腳本:
wget https://raw.githubusercontent.com/icolwell/install_scripts/master/prometheus_install.bash
bash prometheus_install.bash
請注意,任何現有的 prometheus 配置都將被覆蓋。