1. 下載必要的包
wget -c https://github.com/prometheus/prometheus/releases/download/v2.18.0/prometheus-2.18.0.linux-amd64.tar.gz
wget -c https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
wget -c https://dl.grafana.com/oss/release/grafana-6.7.3-1.x86_64.rpm
2. 安裝prometheus
- 安裝腳本
tar -zxvf prometheus-2.18.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv prometheus-2.18.0.linux-amd64 prometheus
- 啓動項編寫
vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Type=simple
#Change this line if you download the
#Prometheus on different path user
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path=/usr/local/prometheus/data \
--web.listen-address=:9092
Restart=on-failure
[Install]
WantedBy=multi-user.target
- 啓動服務
systemctl daemon-reload
systemctl start prometheus.service
systemctl status prometheus.service
systemctl enable prometheus.service
3. 安裝node_exporter
- 安裝腳本
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/prometheus/exporters
cd /usr/local/prometheus/exporters
mv node_exporter-0.18.1.linux-amd64 node_exporter
- 啓動項編寫
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus node exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/prometheus/exporters/node_exporter --web.listen-address=:9101
Restart=on-failure
[Install]
WantedBy=multi-user.target
- 啓動服務
systemctl daemon-reload
systemctl start node_exporter.service
systemctl status node_exporter.service
systemctl enable node_exporter.service
4. 安裝grafana
yum localinstall grafana-6.7.3-1.x86_64.rpm
systemctl start grafana-server.service
systemctl status grafana-server.service
systemctl enable grafana-server.service
5. 安裝過程中遇到的問題
-
Prometheus 以及 Exporter 的端口號衝突
–web.listen-address=:9101 使用這個參數,可以自定義端口號 -
grafana 端口號衝突
修改配置文件 /etc/grafana/grafana.ini ,http_port = 3001參數可修改端口號
vim /etc/grafana/grafana.ini
...
#################################### Server ####################################
[server]
# Protocol (http, https, h2, socket)
;protocol = http
# The ip address to bind to, empty will bind to all interfaces
;http_addr =
# The http port to use
http_port = 3001
...
- systemd方式啓動異常原因查找
systemctl start grafana-server.service
systemctl status grafana-server.service
啓動時發現一直無法正常啓動,此時我們可以用如下命令查看日誌
# 查看全局
journalctl -xe
# 查看某個PID
journalctl _PID=25532
- 權限問題
chown -R grafana:grafana /var/run/grafana/
參考: