prometheus(17):使用nginx-prometheus-exporter
·
一 安装nginx
1.1 下载安装包
cd /opt
安装包下载
wget https://nginx.org/download/nginx-1.26.2.tar.gz
解压
tar -zxvf nginx-1.26.2.tar.gz
下依赖
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel
yum -y install openssl openssl-devel
1.2 去新建nginx目录
cd /usr/local
mkdir nginx
1.3 切回解压后安装包的目录重新编译
cd /opt/nginx-1.26.2
congfigure文件
./configure --prefix=/usr/local/nginx
编译
make&&make install
1.4 去检测编译完的nginx能不能用
1.4.1 检测目录完整性
[root@rocky9-2 nginx-1.26.2]# ls -l /usr/local/nginx
总用量 4
drwxr-xr-x. 2 root root 4096 9月 25 06:26 conf
drwxr-xr-x. 2 root root 40 9月 25 06:26 html
drwxr-xr-x. 2 root root 6 9月 25 06:26 logs
drwxr-xr-x. 2 root root 19 9月 25 06:26 sbin
1.4.2 启动进程
[root@rocky9-2 nginx-1.26.2]# /usr/local/nginx/sbin/nginx
[root@rocky9-2 nginx-1.26.2]# ps -ef | grep nginx
root 36486 1 0 06:28 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 36487 36486 0 06:28 ? 00:00:00 nginx: worker process
root 36489 2330 0 06:28 pts/0 00:00:00 grep --color=auto nginx
[root@rocky9-2 nginx-1.26.2]# curl http:192.168.880.172
curl: (3) URL using bad/illegal format or missing URL
1.4.3 curl网页
[root@rocky9-2 nginx-1.26.2]# curl http://192.168.80.172
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
二配置prometheus
2.1 没有找到目标的文件
[root@rocky9-2 sbin]# ll
总用量 3724
-rwxr-xr-x. 1 root root 3811848 9月 25 06:26 nginx
[root@rocky9-2 sbin]# ./nginx -V 2>&1 |grep -o with-http_stub_status_module
[root@rocky9-2 sbin]#
2.2 加上stub_status模块
cd /opt/nginx-1.26.2
删除之前的配置
make clean
# 1. 重新配置,注意加上 stub_status 模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
# 2. 编译
make
# 3. 安装
make install
检测状态
[root@rocky9-2 nginx-1.26.2]# cd /usr/local/nginx/sbin/
[root@rocky9-2 sbin]# ll
总用量 7484
-rwxr-xr-x. 1 root root 3849720 9月 25 07:01 nginx
-rwxr-xr-x. 1 root root 3811848 9月 25 06:26 nginx.old
[root@rocky9-2 sbin]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
-bash: ./configure: 没有那个文件或目录
[root@rocky9-2 sbin]# ./nginx -V 2>&1 |grep -o with-http_stub_status_module
with-http_stub_status_module
3 编辑nginx.conf
server {
listen 8088;
server_name localhost;
location /nginx-status {
stub_status on;
access_log off;
}
}
检查语法是否正确
[root@rocky9-2 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@rocky9-2 conf]#
4 启动检测状态
更改完配置后,尽量不要搞平滑重载,不然会存在更新不了的问题
[root@rocky9-2 conf]# ss -lntp | grep 8088
[root@rocky9-2 conf]# vim nginx.conf
[root@rocky9-2 conf]# curl http://127.0.0.1:8088/nginx-status
curl: (7) Failed to connect to 127.0.0.1 port 8088: 拒绝连接
[root@rocky9-2 conf]# /usr/local/nginx/sbin/nginx -s stop
[root@rocky9-2 conf]# /usr/local/nginx/sbin/nginx
[root@rocky9-2 conf]# curl http://127.0.0.1:8088/nginx-status
Active connections: 1
server accepts handled requests
1 1 1
Reading: 0 Writing: 1 Waiting: 0
[root@rocky9-2 conf]#

三 配置docker环境
1 找docker镜像源
2 找docker加速源
四 prometheus展示数据
4.1 重启prometheus
curl -XPOST localhost:9090/-/reload
4.2 找到grafana
[root@localhost ~]# systemctl start grafana-server
[root@localhost ~]# systemctl status grafana-server
● grafana-server.service - Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2025-09-24 09:38:37 CST; 4s ago
Docs: http://docs.grafana.org
Main PID: 9984 (grafana-server)
CGroup: /system.slice/grafana-server.service
└─9984 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --packaging=rpm cfg:default.paths.logs=/var/log/grafana cfg:...
9月 24 09:38:36 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:36+0800 lvl=info msg="Path Plugins" logger=settings path=/var/lib/grafana/plugins
9月 24 09:38:36 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:36+0800 lvl=info msg="Path Provisioning" logger=settings path=/etc/grafana/provisioning
9月 24 09:38:36 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:36+0800 lvl=info msg="App mode production" logger=settings
9月 24 09:38:36 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:36+0800 lvl=info msg="Writing PID file" logger=server path=/var/run/grafana/grafana-server.pid pid=9984
9月 24 09:38:36 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:36+0800 lvl=info msg="Connecting to DB" logger=sqlstore dbtype=sqlite3
9月 24 09:38:36 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:36+0800 lvl=info msg="Starting DB migrations" logger=migrator
9月 24 09:38:36 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:36+0800 lvl=info msg="Starting plugin search" logger=plugins
9月 24 09:38:37 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:37+0800 lvl=info msg="Registering plugin" logger=plugins id=input
9月 24 09:38:37 localhost.localdomain systemd[1]: Started Grafana instance.
9月 24 09:38:37 localhost.localdomain grafana-server[9984]: t=2025-09-24T09:38:37+0800 lvl=info msg="HTTP Server Listen" logger=http.server address=[::]:3000 protocol=http ...l= socket=
Hint: Some lines were ellipsized, use -l to show in full
4.3 grafana默认密码admin/admin
http://192.168.80.151:3000/?orgId=1
登录grafana去下仪表盘
发现网站看不懂,没办法

更多推荐


所有评论(0)