一、Prometheus安装
github:https://github.com/prometheus/prometheus
官网: https://prometheus.io
# 1下载prometheus-v2.40.7镜像 https://hub.docker.com/r/prom/prometheus/tags [root@master prometheus]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE prom/prometheus v2.40.7 b816c2dd5971 2 months ago 223MB # 2.配置prometheus配置文件 # 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=<job_name>` to any timeseries scraped from this config. - job_name: "prometheus" # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ["192.168.10.60:9090"] # 改为prometheus服务端地址 # 3.启动prometheus docker run -di -p 9090:9090 -v /db/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus:v2.40.7 [root@master prometheus]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 780f6a30bde9 prom/prometheus:v2.40.7 "/bin/prometheus --c…" 2 hours ago Up 11 minutes 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp tender_haibt # 4.访问prometheus界面 http://192.168.10.60:9090 点击:Status-->Targets
通过http://192.168.10.60:9090/metrics可以看到监控的数据
在web主界面可以查看图形
二、node_exporter监控远程主机
# 下载node_exporter https://prometheus.io/download/#node_exporter https://github.com/prometheus/node_exporter/releases # 安装启动node_exporter [root@node1 node_exporter]# tar -xzvf node_exporter-1.5.0.linux-amd64.tar.gz mv node_exporter-1.5.0.linux-amd64 node_exporter [root@node1 node_exporter]# nohup /db/node_exporter/node_exporter & [root@node1 node_exporter]# netstat -ntlp | grep 9100 tcp6 0 0 :::9100 :::* LISTEN 10614/node_exporter # 查看监控数据 http://192.168.10.61:9100/metrics # 在prometheus 服务器上添加配置 vim /db/prometheus/prometheus.yml - job_name: "node1" static_configs: - targets: ["192.168.10.61:9100"] # 重启docker [root@master prometheus]# docker restart tender_haibt 使用热加载测试:curl -X POST http://192.168.10.60:9090/-/reload
# 查看图形化界面
三、监控远程mysql:mysqld_exporter
# 1.下载监控程序 https://prometheus.io/download/#mysqld_exporter # 1.创建一个监控账号 grant select,replication client,process on *.* to 'monitor'@'localhost' identified by 'monitor@123'; flush privileges; # 2.创建存放密码文件 mv mysqld_exporter-0.14.0.linux-amd64 mysqld_exporter # 创建存放mysql账号密码文件 [root@iZuf671s2u2a1ivhvekjz5Z mysqld_exporter]# cat mysqld_export.cnf [client] user=monitor password=monitor@123 # 3.启动程序 [root@iZuf671s2u2a1ivhvekjz5Z mysqld_exporter]# nohup /db/mysqld_exporter/mysqld_exporter --config.my-cnf=/db/mysqld_exporter/mysqld_export.cnf & [root@iZuf671s2u2a1ivhvekjz5Z mysqld_exporter]# netstat -ntlp | grep 9104 tcp6 0 0 :::9104 :::* LISTEN 19183/mysqld_export # 4.修改prometheus.yml配置,新增 - job_name: "connect_mysql" static_configs: - targets: ["192.168.10.62:9104"] # 5.web界面查看
四、Grafana链接prometheus
Grafana官网:https://grafana.com/
下载地址:https://grafana.com/grafana/download
dockerhub:https://hub.docker.com/r/grafana/grafana
4.1 grafana安装
# 直接安装
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.6-1.x86_64.rpm sudo yum install grafana-enterprise-9.3.6-1.x86_64.rpm
systemctl start grafana-server
# 镜像安装
# 镜像下载 [root@master ~]# docker pull grafana/grafana:9.2.10 [root@master ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE grafana/grafana 9.2.10 7633eefbf3e8 4 weeks ago 344MB prom/prometheus v2.40.7 b816c2dd5971 2 months ago 223MB # 启动docker [root@master ~]# docker run -di --name=grafana -p 3000:3000 grafana/grafana:9.2.10 [root@master ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ccdef48c2249 grafana/grafana:9.2.10 "/run.sh" 4 seconds ago Up 3 seconds 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp grafana 780f6a30bde9 prom/prometheus:v2.40.7 "/bin/prometheus --c…" 3 hours ago Up About an hour 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp tender_haibt # 页面访问 http://192.168.10.60:3000/ 默认账号密码: admin和admin
4.2 grafana 添加数据源
点击:DATA SOURCE--->选择:Prometheus--->填写对应选项--->save&test
创建dashboard:点击HOME,回到首页:Create your first dashboard--->Add a new panel
标签:node,exporter,9090,prometheus,grafana,Prometheus,各类,监控,root From: https://www.cnblogs.com/yangmeichong/p/17151723.html