环境说明:
| 主机名称 | IP地址 | 安装服务 |
|---|---|---|
| master(服务端) | 192.168.8.129 | prometheus |
| node1(客户端) | 192.168.8.130 | node_exporter |
安装服务端
//下载安装包 [root@master ~]# cd /usr/src/ [root@master src]# wget https://github.com/prometheus/prometheus/releases/download/v2.31.1/prometheus-2.31.1.linux-amd64.tar.gz [root@master src]# ls debug kernels prometheus-2.31.1.linux-amd64.tar.gz
// 解压到/usr/local下 [root@master src]# tar xf prometheus-2.31.1.linux-amd64.tar.gz -C /usr/local/ [root@master src]# cd /usr/local/ [root@master local]# ls bin games lib libexec sbin src etc include lib64 prometheus-2.31.1.linux-amd64 share [root@master local]# ln -s prometheus-2.31.1.linux-amd64/ prometheus [root@master local]# ll 总用量 0 drwxr-xr-x. 2 root root 6 8月 12 2018 bin drwxr-xr-x. 2 root root 6 8月 12 2018 etc drwxr-xr-x. 2 root root 6 8月 12 2018 games drwxr-xr-x. 2 root root 6 8月 12 2018 include drwxr-xr-x. 2 root root 6 8月 12 2018 lib drwxr-xr-x. 2 root root 6 8月 12 2018 lib64 drwxr-xr-x. 2 root root 6 8月 12 2018 libexec lrwxrwxrwx 1 root root 30 11月 25 22:29 prometheus -> prometheus-2.31.1.linux-amd64/ drwxr-xr-x 4 3434 3434 132 11月 6 04:46 prometheus-2.31.1.linux-amd64 drwxr-xr-x. 2 root root 6 8月 12 2018 sbin drwxr-xr-x. 5 root root 49 10月 15 15:47 share drwxr-xr-x. 2 root root 6 8月 12 2018 src [root@master local]#
[root@master local]# ls bin games lib libexec prometheus-2.31.1.linux-amd64 share etc include lib64 prometheus sbin src [root@master local]# cd prometheus [root@master prometheus]# ls console_libraries consoles LICENSE NOTICE prometheus prometheus.yml promtool [root@master prometheus]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" [root@master ~]# ss -antl|grep 9090 LISTEN 0 128 *:9090 *:* [root@master ~]#
浏览器输入ip:9090访问Prometheus监控页面
安装客户端
//下载node_exporter安装包 [root@node1 ~]# cd /usr/src/ [root@node1 src]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz
// 解压 [root@node1 src]# tar xf node_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/ [root@node1 src]# cd /usr/local/ [root@node1 local]# ls bin games lib libexec sbin src etc include lib64 node_exporter-1.3.0.linux-amd64 share [root@node1 local]# ln -s node_exporter-1.3.0.linux-amd64/ node_exporter [root@node1 local]# ll 总用量 0 drwxr-xr-x. 2 root root 6 8月 12 2018 bin drwxr-xr-x. 2 root root 6 8月 12 2018 etc drwxr-xr-x. 2 root root 6 8月 12 2018 games drwxr-xr-x. 2 root root 6 8月 12 2018 include drwxr-xr-x. 2 root root 6 8月 12 2018 lib drwxr-xr-x. 2 root root 6 8月 12 2018 lib64 drwxr-xr-x. 2 root root 6 8月 12 2018 libexec lrwxrwxrwx 1 root root 32 11月 25 22:49 node_exporter -> node_exporter-1.3.0.linux-amd64/ drwxr-xr-x 2 3434 3434 56 11月 19 00:41 node_exporter-1.3.0.linux-amd64 drwxr-xr-x. 2 root root 6 8月 12 2018 sbin drwxr-xr-x. 5 root root 49 10月 21 17:05 share drwxr-xr-x. 2 root root 6 8月 12 2018 src [root@node1 local]#
[root@node1 local]# cd node_exporter/ [root@node1 node_exporter]# nohup /usr/local/node_exporter/node_exporter [root@node1 ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 128 *:9100 *:* [root@node1 ~]#
//在prometheus配置文件添加受控主机
[root@master ~]# cd /usr/local/prometheus
[root@master prometheus]# ls
console_libraries consoles data LICENSE NOTICE prometheus prometheus.yml promtool
[root@master prometheus]# vim prometheus.yml
[root@master prometheus]# cat prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: "node1" //名称
static_configs: //客户端ip
- targets: ["192.168.8.130:9100"]
[root@master prometheus]#
[root@master prometheus]# pkill prometheus
[root@master prometheus]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml"
重新访问



