一、非容器運(yùn)行
安裝prometheus
官網(wǎng)下載
https://prometheus.io
上傳解壓
# tar xzvf prometheus-2.48.0.linux-amd64.tar.gz -C /usr/local/
# mv prometheus-2.48.0.linux-amd64 prometheus
啟動(dòng)文件為 prometheus旺韭,配置文件為 prometheus.yml
啟動(dòng)方式:
1氛谜、直接啟動(dòng)
# ./prometheus [參數(shù)]
可以--help查看具體信息
基本就是指定配置文件、指定數(shù)據(jù)保存地址区端、數(shù)據(jù)保留時(shí)間等
可以參考下文service文件中啟動(dòng)參數(shù)
2值漫、systemctl啟動(dòng)
創(chuàng)建啟動(dòng)system文件
# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus-server
Documentation=https://prometheus.io/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--web.enable-lifecycle \
--storage.tsdb.path=/usr/local/prometheus/data \
--storage.tsdb.retention.time=7d \
--web.max-connections=512 \
--web.read-timeout=3m \
--query.max-concurrency=25 \
--query.timeout=2m
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/ki11 -s QUIT $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start prometheus
# systemctl enable prometheus
啟動(dòng)完成后可以 ip:9090查看Web UI
Status-->Targets中可以查看到監(jiān)控的對(duì)象prometheus
安裝node_exporter
官網(wǎng)下載
https://prometheus.io
在其他需要被監(jiān)控的機(jī)器上上傳node_exporter壓縮包
解壓
# tar xzvf node_exporter-1.7.0.linux-amd64.tar.gz -C /usr/local/
# mv node_exporter-1.7.0.linux-amd64 node_exporter
啟動(dòng)文件為node_exporter
啟動(dòng)方式:
1、直接啟動(dòng)
# nohup ./node_exporter [啟動(dòng)參數(shù)] &
./node_exporter --help查看具體信息 根據(jù)需求收集需要的數(shù)據(jù)
2织盼、systemctl啟動(dòng)
# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/node_exporter \
-collector.ntp \
-collector.mountstats \
-collector.systemd \
-collector.tcpstat
ExecReload=/bin/kil1 -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start node_exporter.service
# systemctl enable node_exporter.service
可以訪問ip:9100/metrics 查看相關(guān)信息
修改prometheus.yml,在scrape_configs下添加
- job_name: 'node_exporter_1'
static_configs:
- targets: ['ip:9100']
重啟prometheus
# systemctl restart prometheus
訪問prometheus的ip:9090 Status-->Targets
看到監(jiān)控的對(duì)象多了node_exporter_1
安裝grafana
在安裝grafana的機(jī)器上更新yum源
# vim /etc/yum.repo.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
# yum makecache fast
# yum -y install grafana
訪問grafana的ip:3000
默認(rèn)admin/admin
進(jìn)入后add your fiirst data source
選擇prometheus
根據(jù)需求填寫