prometheus+grafana接入nginx实战

接上文:
prometheus监控实战
Grafana接入Prometheus实战

操作系统:阿里龙蜥操作系统(AnolisOS-7.9-GA-x86_64)(类似CentOS7.9)

1.安装nginx

nginx下载地址:https://nginx.org/download/nginx-1.28.0.tar.gz

nginx-module-vts下载地址:https://codeload.github.com/vozlt/nginx-module-vts/tar.gz/refs/tags/v0.2.4

本文默认放在"/home"目录下,如下图:

powershell 复制代码
cd /home/nginx_home/nginx-1.28.0

# 执行配置文件
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --add-module=/home/nginx_home/nginx-module-vts-0.2.4

# 执行make命令
make
make install

# 查看Nginx是否存在
whereis nginx
powershell 复制代码
# 查看版本
/usr/local/nginx/sbin/nginx -v

修改配置文件:

检查配置:

powershell 复制代码
cd /usr/local/nginx/conf
/usr/local/nginx/sbin/nginx -t

启动:

powershell 复制代码
cd /usr/local/nginx/sbin
./nginx

查看进程:

powershell 复制代码
 netstat -lntp | grep 80

访问统计信息:

http://ip/status

http://10.86.97.201/status

2.安装nginx-vts-exporter

下载地址:https://github.com/sysulq/nginx-vts-exporter/releases

powershell 复制代码
# 解压
tar -xvf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz

# 启动
cd /home/nginx_home/nginx-vts-exporter-0.10.3
nohup /home/nginx_home/nginx-vts-exporter-0.10.3/nginx-vts-exporter -nginx.scrape_uri http://10.86.97.201/status/format/json &

# 检查
lsof -i:9913

访问:

http://10.86.97.201:9913/metrics

3.接入prometheus

修改配置:

powershell 复制代码
vim /home/prometheus/prometheus.yml

  - job_name: "nginx-vts"
    metrics_path: "/metrics"
    static_configs:
    - targets: ["10.86.97.201:9913"]

重启prometheus:

powershell 复制代码
lsof -i:9090
kill -9 pid
nohup /home/prometheus/prometheus --config.file="/home/prometheus/prometheus.yml" &

访问:http://10.86.97.200:9090

4.接入grafana

访问grafana:

http://10.86.97.200:3000/

Grafana Dashboard ID: 2949

5.常见问题

①问题:nginx安装,执行./configure报错如下:

./configure: error: C compiler cc is not found

解决:

sudo yum groupinstall "Development Tools"

②问题:nginx安装,执行./configure,报错如下:

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre= option.

解决:

安装 PCRE 开发库:sudo yum install pcre-devel

③问题:nginx安装,执行./configure,报错如下:

./configure: error: the HTTP gzip module requires the zlib library.

You can either disable the module by using --without-http_gzip_module

option, or install the zlib library into the system, or build the zlib library

statically from the source with nginx by using --with-zlib= option.

解决:

sudo yum install zlib-devel

④问题:nginx-vtx-exporter启动,报错如下:

./nginx-vtx-exporter: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./nginx-vtx-exporter)

解决:

不要使用最新版本,建议使用nginx-vts-exporter-0.10.3.linux-amd64.tar.gz。

6.相关资源

官网下载较慢,相关资源已上传百度网盘(虽然限速,也比官网快):链接: https://pan.baidu.com/s/1MkLygpBzD-OBxxUh_w6HUw?pwd=h22b

相关推荐
小阳睡不醒32 分钟前
小白成长之路-部署prometheus监控平台
prometheus
ZzzZZzzzZZZzzzz…2 小时前
Nginx_Tomcat综合案例
运维·nginx·tomcat·负载均衡·rhce·反向代理·https加密服务
VueVirtuoso17 小时前
SaaS 建站从 0 到 1 教程:Vue 动态域名 + 后端子域名管理 + Nginx 配置
前端·vue.js·nginx
007php00720 小时前
Redis高级面试题解析:深入理解Redis的工作原理与优化策略
java·开发语言·redis·nginx·缓存·面试·职场和发展
Xxtaoaooo20 小时前
Nginx 502 网关错误:upstream 超时配置的踩坑与优化
运维·nginx·负载均衡·502错误·upstream超时
爱琴孩21 小时前
企业级VIP+Nginx的网络访问方案
nginx·keepalive·vip
看好多桂花树1 天前
Nginx 优化
运维·nginx
羑悻的小杀马特1 天前
Docker 容器化部署核心实战:从镜像仓库管理、容器多参数运行到 Nginx 服务配置与正反向代理原理解析
nginx·docker·容器·镜像仓库
linux修理工1 天前
n1 ARMbian部署Grafana
arm开发·架构·grafana
白鹭1 天前
nginx(介绍+源码安装+平滑升级和回滚)
linux·运维·服务器·nginx·回滚·平滑升级