使用Prometheus進行伺服器監控

2021-10-06 11:28:55 字數 4530 閱讀 9698

感悟公司伺服器很多,最近要求每台伺服器都要安裝伺服器監控,我就順理成章的當了一回運維。坑很多,客戶那邊有些機器不提供root許可權,有些又開不了埠,只能自行想辦法解決。不過話說回來看,這玩意還是挺實用的,可對伺服器的資源,如cpu、記憶體、磁碟等進行實時監控,好工具用起來。

安裝prometheus

tar -xvf prometheus-2.8.1.linux-amd64.tar.gz
groupadd prometheus

useradd -g prometheus -s /sbin/nologin prometheus

chown -r prometheus:prometheus /develop/server/prometheus-2.8.1.linux-amd64/
mkdir -p /develop/software/prometheus-data

chown -r prometheus:prometheus /develop/software/prometheus-data/

vim /usr/lib/systemd/system/prometheus.service
[unit]

description=prometheus

documentation=

after=network.target

[service]

type=******

user=prometheus

# --storage.tsdb.path是可選項,預設資料目錄在執行目錄的./data目錄中

execstart=/develop/server/prometheus-2.8.1.linux-amd64/prometheus --config.file=/develop/server/prometheus-2.8.1.linux-amd64/prometheus.yml --storage.tsdb.path=/develop/software/prometheus-data

restart=on-failure

[install]

wantedby=multi-user.target

chown prometheus:prometheus /usr/lib/systemd/system/prometheus.service
systemctl enable prometheus

systemctl start prometheus

systemctl status prometheus

firewall-cmd --add-port=9090/tcp --permanent

firewall-cmd --reload

status -> configuration 可檢視prometheus.yml配置

status -> targets 可檢視配置的節點資訊

安裝grafana視覺化工具

方式一:需要聯網

wget 

yum -y localinstall grafana-6.1.3-1.x86_64.rpm

systemctl enable grafana-server

systemctl start grafana-server

方式二:無需聯網

tar -xvf grafana-6.7.1.linux-amd64.tar.gz
vim /usr/lib/systemd/system/grafana-server.service
[unit]

description=grafana

after=network.target

[service]

type=notify

execstart=/develop/server/grafana-6.7.1/bin/grafana-server -homepath /develop/server/grafana-6.7.1 -config=/develop/server/software/grafana-6.7.1/conf/defaults.ini

restart=on-failure

[install]

wantedby=multi-user.target

systemctl enable grafana-server

systemctl start grafana-server

兩種方式都要做的事

firewall-cmd --add-port=3000 --permanent

firewall-cmd --reload

add data source -> prometheus -> 填寫prometheus的訪問位址

加號 -> import -> upload .json file -> prometheus選擇資料來源 -> import(override)

# vim 

location /grafana/

# vim /develop/server/grafana-6.7.1/conf/defaults.ini

# root_url後面的路徑要和nginx一樣,比如這裡是/grafana/

proxy_busy_buffers_size 128k;

linux安裝監控 解壓

tar -xvf node_exporter-1.0.0-rc.1.linux-amd64.tar.gz
mv node_exporter-1.0.0-rc.1.linux-amd64/node_exporter /develop/server/node_exporter-1.0.0-rc.1.linux-amd64
sudo useradd -rs /bin/false node_exporter
sudo vi /etc/systemd/system/node_exporter.service
[unit]

description=node exporter

after=network.target

[service]

user=node_exporter

group=node_exporter

type=******

execstart=/develop/server/node_exporter-1.0.0-rc.1.linux-amd64/node_exporter

[install]

wantedby=multi-user.target

sudo systemctl daemon-reload

sudo systemctl enable node_exporter

sudo systemctl start node_exporter

sudo systemctl status node_exporter

firewall-cmd --add-port=9100/tcp --permanent

firewall-cmd --reload

window新增監控

新增到prometheus

vim /develop/server/prometheus-2.8.1.linux-amd64/prometheus.yml
- job_name: 'cbl-local02'

scrape_interval: 10s

static_configs:

- targets: ['192.168.157.134:9100']

labels:

instance: '192.168.157.134'

systemctl restart prometheus
總覺得這種安裝式教程記也不是,不記也不是,所以還是為了以後有參考的文件。在寫教程的過程中,一直在公司環境和本地環境互相切換,所以寫的部落格會有針對公司和面向公眾的版本,容易發生混亂。希望下次能夠有所改進。

使用thanos管理Prometheus持久化資料

關於thanos的介紹可以參考這篇官方部落格的翻譯文件,本文不作部署操作介紹。下圖是thanos的官方架構圖,主要有5個元件 通常thanos管理多集群時,除sidecar元件需要在每個集群內部署,其餘元件僅部署乙份,用於處理多個集群的資料。需要注意的是,thanos的storeapi採用的是grp...

使用Prometheus監控Spark任務

目前spark支援graphite打點,但是graphite缺省會為每個打點生成對應的檔案,直接只有兩個點資料,graphite生成的檔案也有200多k,對graphite造成很大的壓力。所以考慮使用prometheus來代替graphite。prometheus的打點預設是pull模式,和grap...

使用SiteScope監控Apache伺服器

1 配置 1 進入 檔案,新增以下內容 sethandler server status order allow,deny allow from all extendedstatus on 儲存文件。2 輸入http ip server status 進行測試 看能否等到響應資訊。2 配置sites...