1夯到、先下載安裝prometheus server
從 https://prometheus.io/download/ 下載相應(yīng)版本,安裝到服務(wù)器上侮攀。
# 解壓安裝包
tar -xf prometheus-2.32.1.linux-amd64.tar.gz -C /opt
# 創(chuàng)建鏈接目錄
cd /opt
ln -s prometheus-2.32.1.linux-amd64 prometheus
# 直接使用默認配置文件啟動哺眯,? cd到 /opt/prometheus 目錄下媳谁,運行 ./prometheus --help 可以查看相關(guān)明細 以下命令修改了默認端口
/opt/prometheus/prometheus?--web.listen-address="0.0.0.0:29090" --config.file="/opt/prometheus/prometheus.yml" &
# 確認是否正常啟動(默認端口9090) 我改的是 29090 品山,
[root@server ~]# netstat -lnptu | grep 29090? 或者用命令? ps -ef | grep prometheus
tcp6? ? ? 0? ? ? 0 :::29090? ? ? ? ? ? ? ? :::*? ? ? ? ? ? ? ? ? ? LISTEN? ?? 2008/prometheus
2、在需要被監(jiān)控的機器上面安裝 node_exporter組件街州,
地址同上兼丰,下載后操作
# 解壓安裝包
tar -xf node_exporter-1.3.1.linux-amd64.tar.gz -C /opt
# 創(chuàng)建鏈接目錄
cd /opt
ln -s node_exporter-1.3.1.linux-amd64 node_exporter
# 使用nohup運行 ,最好是cd到/opt/node_exporter 目錄后在運行菇肃,nohup.out文件會在相應(yīng)目錄生成地粪,一下命令也是改了默認端口的。
nohup /opt/node_exporter/node_exporter?--web.listen-address=":29100" &
# 確認是否正常啟動(默認端口9100) 我改成了 29100
[root@mysql01 ~]# netstat -lnptu | grep 29100
tcp6? ? ? 0? ? ? 0 :::29100? ? ? ? ? ? ? ? :::*? ? ? ? ? ? ? ? ? ? LISTEN? ?? 30816/node_exporter
3琐谤、修改prometheus服務(wù)器的配置文件蟆技,添加被監(jiān)控機器的配置信息
修改 /opt/prometheus 下面的 prometheus.yml? 配置文件,在 scrape_configs: 下面添加相應(yīng)配置斗忌,
[root@server ~]# vim /opt/prometheus/prometheus.yml
- job_name: "zhu2012910"??? # 被監(jiān)控服務(wù)的名字质礼,
? ? static_configs:
? ? ? - targets: ["192.168.252.201:29100"]
? - job_name: "cong202"
? ? static_configs:
? ? ? - targets: ["192.168.252.202:29100"]
有多少臺就往下加多少,我現(xiàn)在暫時只加了二臺织阳,加二條眶蕉。
4、改外配置之后重啟prometheus 服務(wù)
pkill prometheus??? #或者使用 ps -ef | grep prometheus?? 查看進程唧躲,然后kill 殺掉進程
/opt/prometheus/prometheus?--web.listen-address="0.0.0.0:29090" --config.file="/opt/prometheus/prometheus.yml" &?? #啟動
netstat -lnptu | grep 29090?? # 查看
以上不出意外prometheus 就配置好了造挽,關(guān)掉防火墻或者打開你啟動的端口,訪問如下服務(wù)地址就能看到信息
http://192.168.252.201:9090/metrics
5弄痹、安裝grafana服務(wù)器
下載安裝grafana 饭入,在/etc/yum.repos.d新建文件 grafana.repo 文件內(nèi)容如下:
[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命令安裝
yum install grafana?
安裝完成后啟動服務(wù)
systemctl start grafana-server.service?
檢查服務(wù)狀態(tài)
systemctl status grafana-server.service
啟動后開放服務(wù)器3000端口就可以通過地址訪問界面了
http://192.168.252.201:3000/ 默認登錄用戶名密碼: admin/ admin 登錄之后修改密碼。
進來后左邊設(shè)置圖標(biāo)先添加 datasources 肛真,選擇 Prometheus? 添加
然后導(dǎo)入監(jiān)控模板 11074
load之后選擇數(shù)據(jù)源導(dǎo)入完成后成功谐丢。
下一步加入mysql監(jiān)控。