二进制部署Prometheus 和Grafana
nginx_exporter插件编译安装
| |
| # mkdir /usr/local/nginx-vts-module |
| # ls /usr/local/nginx-vts-module ----上传 Nginx 扩展模块到服务器上并解压 |
| nginx-module-sts-0.1.1.tar.gz nginx-module-stream-sts-0.1.1.tar.gz nginx-module-vts-0.1.18.tar.gz nginx-1.21.5 nginx-module-stream-sts-0.1.1 nginx-module-sts-0.1.1 nginx-module-vts-0.1.18 |
| # nginx -V ----获取当前已安装 Nginx 的运行参数 |
| # yum -y install gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel libtool ---- |
| # cd /usr/local/nginx-vts-module/nginx-1.21.5 |
| |
| # --prefix=/usr/local/nginx --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_ssl_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-pcre --with-http_stub_status_module --with-stream --add-module=/usr/local/src/nginx-module-vts-0.1.18 --add-module=/usr/local/src/nginx-module-sts-0.1.1 --add-module=/usr/local/src/nginx-module-stream-sts-0.1.1 --add-module=/usr/local/src/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ --add-module=/usr/local/src/naxsi-0.55.3/naxsi_src/ --add-module=/usr/local/src/nginx_upstream_check_module-master --with-openssl=/usr/local/src/openssl-1.1.1g |
| # make |
| # make install |
| |
| http { |
| vhost_traffic_status_zone |
| ... |
| server { |
| ... |
| location /status { ----新增location |
| vhost_traffic_status_display |
| vhost_traffic_status_display_format html |
| } |
| } |
| } |
| |
| |
| |
| |
| |
| |
| nginx_vts_info{hostname="yidongqy.com",version="1.21.5"} 1 |
| |
| |
| nginx_vts_start_time_seconds 1642158757.711 |
- 附件中有编译好的nginx可以执行使用适用于Centos7系列系统
| [root@portal_node_1 BAK] |
| |
| [root@portal_node_1 vhosts] |
| vhost_traffic_status_zone |
| |
| [root@portal_node_1 vhosts] |
| location /status { |
| vhost_traffic_status_display |
| vhost_traffic_status_display_format html |
| } |
| |
| [root@portal_node_1 sbin] |
| [root@portal_node_1 sbin] |
| [root@portal_node_1 sbin] |
| |
| |
| nginx_vts_info{hostname="portal_node_1",version="1.20.2"} 1 |
| |
| |
| nginx_vts_start_time_seconds 1642660147.903 |
| |
| |
| nginx_vts_main_connections{status="accepted"} 100 |
| nginx_vts_main_connections{status="active"} 8 |
| nginx_vts_main_connections{status="handled"} 100 |
| nginx_vts_main_connections{status="reading"} 0 |
| nginx_vts_main_connections{status="requests"} 97 |
| nginx_vts_main_connections{status="waiting"} 7 |
| nginx_vts_main_connections{status="writing"} 1 |
| |
| |
| nginx_vts_main_shm_usage_bytes{shared="max_size"} 1048575 |
| nginx_vts_main_shm_usage_bytes{shared="used_size"} 3525 |
| nginx_vts_main_shm_usage_bytes{shared="used_node"} 1 |
部署Node_exporter
| [root@portal_node_1 ~] |
| [metric@portal_node_1 ~] |
| [metric@portal_node_1 ~] |
| [metric@portal_node_1 ~] |
| [metric@portal_node_1 ~] |
| [metric@portal_node_1 node_exporter-1.3.1] |
| |
| |
| jarfilename=node_exporter |
| AppPath=/home/metric/node_exporter/ |
| start() |
| { |
| nohup $AppPath$jarfilename > /dev/null & |
| } |
| |
| stop() |
| { |
| kill -9 $(ps -ef|grep $jarfilename|grep -v grep |awk '{print $2}') |
| } |
| |
| status() |
| { |
| ps -ef|grep $jarfilename|grep -v grep |
| } |
| |
| restart() { |
| stop |
| start |
| } |
| |
| case "$1" in |
| start) |
| start |
| ;; |
| stop) |
| stop |
| ;; |
| restart) |
| restart |
| ;; |
| status) |
| status |
| ;; |
| *) |
| echo $"Usage: $0 {start|stop|restart|status}" |
| esac |
| |
| [metric@portal_node_1 node_exporter]$ ./start.sh start |
| [metric@portal_node_1 node_exporter]$ curl 127.0.0.1:9100/metrics |
| |
| |
部署Mysql_exporter
| [root@localhost ~] |
| [metric@localhost ~]$ rz -be mysqld_exporter-0.13.0.linux-amd64.tar.gz |
| [metric@localhost ~]$ tar xvf soft/mysqld_exporter-0.13.0.linux-amd64.tar.gz |
| [metric@localhost ~]$ mv mysqld_exporter-0.13.0.linux-amd64 mysqld_exporter-0.13.0 |
| [metric@localhost ~]$ cd mysqld_exporter-0.13.0 |
| [metric@localhost mysqld_exporter-0.13.0]$ vim mysqld_exporter.cnf |
| [client] |
| user=ucds |
| password=ucds |
| host=10.130.41.51 |
| port=3306 |
| |
| [metric@localhost mysqld_exporter-0.13.0]$ vim start.sh |
| |
| jarfilename=mysqld_exporter |
| AppPath=/home/metric/mysqld_exporter-0.13.0/ |
| configname=mysqld_exporter.cnf |
| start() |
| { |
| nohup $AppPath$jarfilename --config.my-cnf="$AppPath$configname" > /dev/null & |
| } |
| |
| stop() |
| { |
| kill -9 $(ps -ef|grep $jarfilename|grep -v grep |awk '{print $2}') |
| } |
| |
| status() |
| { |
| ps -ef|grep $jarfilename|grep -v grep |
| } |
| |
| restart() { |
| stop |
| start |
| } |
| |
| case "$1" in |
| start) |
| start |
| |
| stop) |
| stop |
| |
| restart) |
| restart |
| |
| status) |
| status |
| |
| *) |
| echo $"Usage: $0 {start|stop|restart|status}" |
| esac |
| [metric@localhost mysqld_exporter-0.13.0]$ ./start.sh start |
| |
| [metric@localhost mysqld_exporter-0.13.0]$ curl http://10.130.41.120:9104/metrics ----验证结果 |
| |
| |
| mysql_up 1 ----成功获取到1个 Mysql 实例 |
部署docker_exporet
| 在docker中运行启动cadvisor容器之前需要做如下操作否则启动失败 |
| [root@my-dev ~]#mount -o remount,rw '/sys/fs/cgroup' |
| [root@my-dev ~]#ln -s /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuacct,cpu |
| |
| [root@my-dev ~]# docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker:/var/lib/docker:ro --publish=50715:8080 --detach=true --name=cadvisor google/cadvisor:latest |
| |
| [root@my-dev ~]#curl 127.0.0.1:50715/metrics 是否出相关数据 |
部署redis_exporter
| [root@localhost ~] |
| [metric@localhost ~]$ rz -be redis_exporter-v1.33.0.linux-amd64.tar.gz |
| [metric@localhost ~]$ tar xvf soft/redis_exporter-v1.33.0.linux-amd64.tar.gz |
| [metric@localhost ~]$mv redis_exporter-v1.33.0.linux-amd64 redis_exporter-v1.33.0 |
| [metric@localhost ~]$ cd redis_exporter-v1.33.0 |
| [metric@localhost redis_exporter-v1.33.0]$ vim start.sh |
| |
| jarfilename=redis_exporter |
| AppPath=/home/metric/redis_exporter-v1.33.0/ |
| redisip=10.130.41.43:6380 |
| redispasswd=e4M8s2nyUC44MJXd |
| start() |
| { |
| |
| |
| } |
| |
| stop() |
| { |
| kill -9 $(ps -ef|grep $jarfilename|grep -v grep |awk '{print $2}') |
| } |
| |
| status() |
| { |
| ps -ef|grep $jarfilename|grep -v grep |
| } |
| |
| restart() { |
| stop |
| start |
| } |
| |
| case "$1" in |
| start) |
| start |
| |
| stop) |
| stop |
| |
| restart) |
| restart |
| |
| status) |
| status |
| |
| *) |
| echo $"Usage: $0 {start|stop|restart|status}" |
| esac |
| |
| [metric@localhost redis_exporter-v1.33.0]$ ./start.sh start |
| [metric@localhost redis_exporter-v1.33.0]$ curl http://10.130.41.120:9121/metrics |
| |
| |
| redis_up 1 ----成功获取到1个 Redis 实例 |
部署Prometheus Server
| [metric@localhost ~]$ rz -beprometheus-2.32.1.linux-amd64.tar.gz |
| [metric@localhost ~]$ tar xvf soft/prometheus-2.32.1.linux-amd64.tar.gz |
| [metric@localhost ~]$ mv prometheus-2.32.1.linux-amd64 prometheus-2.32.1 |
| [metric@localhost ~]$ cd prometheus-2.32.1/ |
| |
| [root@localhost ~] |
| [Unit] |
| Description=Prometheus server daemon |
| After=network.target |
| [Service] |
| Type=simple |
| User=metric |
| Group=metric |
| ExecStart=/home/metric/prometheus-2.32.1/prometheus \ |
| --config.file "/home/metric/prometheus-2.32.1/prometheus.yml" \ |
| --storage.tsdb.path "/home/metric/prometheus-2.32.1/data" \ |
| --storage.tsdb.retention.time=45d \ |
| --web.console.templates "/home/metric/prometheus-2.32.1/consoles" \ |
| --web.console.libraries "/home/metric/prometheus-2.32.1/console_libraries" \ |
| --web.max-connections=1024 \ |
| --web.external-url "http://10.130.41.120:9090" \ |
| --web.listen-address "10.130.41.120:9090" \ |
| --web.enable-lifecycle |
| Restart=no |
| [Install] |
| WantedBy=multi-user.target |
| |
| [root@localhost ~] |
| [root@localhost home] |
| [metric@localhost ~]$ cd prometheus-2.32.1/ |
| [metric@localhost prometheus-2.32.1]$ vim prometheus.yml |
| global: |
| scrape_interval: 10s ----调整为10秒抓取一次 |
| scrape_timeout: 5s ----设置超时时间为5s |
| evaluation_interval: 15s |
| |
| scrape_configs: |
| - job_name: "prometheus" |
| static_configs: |
| - targets: ["10.130.41.120:9090"] ----修改localhost为本机IP |
| |
| - job_name: "nginx-metircs" ----新增 Nginx vts 配置 |
| metrics_path: /status/format/prometheus |
| static_configs: |
| - targets: ['10.130.41.10:8091'] ----多个节点使用 , 分隔 |
| |
| - job_name: "node-exporter" ----新增 node-exporter 配置 |
| metrics_path: /metrics |
| static_configs: |
| - targets: |
| - "10.130.41.10:9100" |
| - "10.130.41.120:9100" |
| |
| - job_name: "mysql-exporter" ----新增 mysql-exporter 配置 |
| metrics_path: /metrics |
| static_configs: |
| - targets: ['10.130.41.120:9104'] |
| |
| - job_name: "redis-exporter-targets" ----新增 Redis 节点设置 |
| static_configs: |
| - targets: |
| - redis://10.130.41.42:6379 ----存在多节点时,将所有节点都写上 |
| - redis://10.130.41.43:6380 ----存在多节点时,将所有节点都写上 |
| - redis://10.130.41.44:6381 ----存在多节点时,将所有节点都写上 |
| |
| metrics_path: /scrape |
| relabel_configs: |
| - source_labels: [__address__] |
| target_label: __param_target |
| - source_labels: [__param_target] |
| target_label: instance |
| - target_label: __address__ |
| replacement: 10.130.41.120:9121 ----填写 Redis-exporter IP:PORT |
| |
| - job_name: "redis-exporter" ----新增 Redis-exporter 配置 |
| metrics_path: /metrics |
| static_configs: |
| - targets: |
| - 10.130.41.120:9121 |
| |
| - job_name: "docker-exporter" ---新增 docker-exporter 配置 |
| metrics_path: /metrics |
| static_configs: |
| - targets: |
| - 10.130.41.10:50715 |
| |
| [metric@localhost prometheus-2.32.1]$ ./promtool check config prometheus.yml |
| Checking prometheus.yml |
| SUCCESS: 0 rule files found |
| |
| [metric@localhost prometheus-2.32.1]$ exit |
| [root@localhost home] |
| [root@localhost home] |
| [root@localhost home] |
| |
| [root@localhost home] |
| |
| |
| prometheus_sd_discovered_targets{config="config-0",name="notify"} 0 |
| prometheus_sd_discovered_targets{config="mysql-exporter",name="scrape"} 1 |
| prometheus_sd_discovered_targets{config="nginx-metircs",name="scrape"} 2 |
| prometheus_sd_discovered_targets{config="nginx-stub-status",name="scrape"} 2 |
| prometheus_sd_discovered_targets{config="node-exporter",name="scrape"} 2 |
| prometheus_sd_discovered_targets{config="prometheus",name="scrape"} 1 |
| prometheus_sd_discovered_targets{config="redis-exporter",name="scrape"} 1 |
| prometheus_sd_discovered_targets{config="redis-exporter-targets",name="scrape"} 1 |
部署Grafana Server
| [root@localhost home] |
| [metric@localhost ~]$ rz -be grafana-enterprise-8.3.3.linux-amd64.tar.gz |
| [metric@localhost ~]$ tar xvf grafana-enterprise-8.3.3.linux-amd64.tar.gz |
| [metric@localhost ~]$ mv grafana-enterprise-8.3.3.linux-amd64 grafana-8.3.3 |
| [metric@localhost ~]$ cd grafana-8.3.3 bin |
| [root@localhost conf] |
| [root@localhost conf] |
| [root@localhost conf] |
| [root@localhost grafana-8.3.3] |
| |
| jarfilename=grafana-server |
| AppPath=/home/metric/grafana-8.3.3/bin/ |
| configpath=/home/metric/grafana-8.3.3/conf/ |
| configname=grafana.ini |
| start() |
| { |
| nohup $AppPath$jarfilename -config $configpath$configname > /dev/null & |
| } |
| |
| stop() |
| { |
| kill -9 $(ps -ef|grep $jarfilename|grep -v grep |awk '{print $2}') |
| } |
| |
| status() |
| { |
| ps -ef|grep $jarfilename|grep -v grep |
| } |
| |
| restart() { |
| stop |
| start |
| } |
| |
| case "$1" in |
| start) |
| start |
| ;; |
| stop) |
| stop |
| ;; |
| restart) |
| restart |
| ;; |
| status) |
| status |
| ;; |
| *) |
| echo $"Usage: $0 {start|stop|restart|status}" |
| esac |
| [root@localhost grafana-8.3.3]# ./start.sh start |
| |
| |
Grafana-WebUI配置


【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)