记录一下 免得踩坑
- 手动挂载共享文件
- [root@lxf-Prometheus nginx-1.16.1]# vmware-hgfsclient
- File
- [root@lxf-Prometheus hgfs]# cd /usr/bin/
- [root@lxf-Prometheus bin]# ./vmhgfs-fuse .host:/ /mnt/hgfs
- 可以忽略
=======================================================
- yum install nginx -y
- yum安装的是二进制文件,意思是已经编译好的nginx,它只有配置文件和二进制文件,没有源代码,所以你想加第三方模块,只能去nginx的官方网站:http://nginx.org 下载源代码进行安装。
一、下载nginx
yum install wget #安装下载工具
wget http://nginx.org/download/nginx-1.6.3.tar.gz #下载安装包
tar -zxvf nginx-1.6.3.tar.gz #解压缩
二、添加监控模块并安装nginx
git clone git://http://github.com/vozlt/nginx-module-vts.git #下载监控模块
mv nginx-module-vts ./nginx-1.16.1/
![v2-c525081631e777c76e5d5f2ca18cd1ff_b.jpg](https://i-blog.csdnimg.cn/blog_migrate/c51dc1746b22bcdaafdfd4e96056f836.jpeg)
![v2-433217d8de4c487a2c60464dc20c37b8_b.jpg](https://i-blog.csdnimg.cn/blog_migrate/9491e91069ad8fc6beaf7d0590c18725.jpeg)
在/root/nginx-1.16.1/编译nginx 和安装
./configure --prefix=/software/nginx/ --add-module=nginx-module-vts
make&make install
vim /usr/lib/systemd/system/nginx.service #创建服务
- [Unit]
- Description=nginx
- After=network.target
- [Service]
- Type=forking
- ExecStart=/software/nginx/sbin/nginx
- ExecReload=/software/nginx/sbin/nginx -s reload
- ExecStop=/software/nginx/sbin/nginx -s quit
- PrivateTmp=true
- [Install]
- WantedBy=multi-user.target
- systemctl enable nginx.service
- systemctl start nginx.service
- systemctl status nginx.service
![v2-8c6d4b61eb1e62ff4679a8921babab4d_b.jpg](https://i-blog.csdnimg.cn/blog_migrate/e42b7c5a70bfabaa4b2a950c6f7d51b3.jpeg)
完成后打开浏览器输入localhost/status 会有数据显示
![v2-253e0573f137119d5415f1bc6ad0d5f3_b.jpg](https://i-blog.csdnimg.cn/blog_migrate/5c4dbad5389f43fd9f17f059c202cb84.jpeg)
wget -O nginx-vts-exporter-0.5.zip https://github.com/hnlq715/nginx-vts-exporter/archive/v0.5.zip #下载nginx-vts-esporter
unzip nginx-vts-exporter-0.5.zip #解压缩
mv nginx-vts-exporter-0.5 /usr/local/prometheus/nginx-vts-exporter #移动prometheus文件夹下
chmod +x /usr/local/prometheus/nginx-vts-exporter/bin/nginx-vts-exporter #修改权限
vim /etc/systemd/system/nginx-exporter.service #编辑服务文件
- [Unit]
- Description=nginx-exporter
- After=network.target
- [Service]
- ExecStart=/usr/local/prometheus/nginx-vts-exporter/bin/nginx-vts-exporter -nginx.scrape_uri http://192.168.72.30/status/format/json &
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target
开启服务
- systemctl enable nginx-exporter.service
- systemctl status nginx-exporter.service
- systemctl start nginx-exporter.service
![v2-6d5b3236f0b15922925b883c79bbcf98_b.jpg](https://i-blog.csdnimg.cn/blog_migrate/8fd6f6e962ac0e2f795073c1c5e82e52.jpeg)
http://192.168.72.30:9913/metrics 可以看到抓取的数据
![v2-602729bce72f964babaf895ca652cb75_b.jpg](https://i-blog.csdnimg.cn/blog_migrate/582e35488dd9f1630c9674f35fe1dab1.jpeg)
四、prometheus 添加 nginx 监控项目
vim /usr/local/prometheus/prometheus.yml
- - job_name: 'Server'
- static_configs:
- - targets: ['192.168.72.30:9913']
- labels:
- instance: nginx
systemctl restart prometheus.service #重启服务
prometheus 使用2949 模板
效果
![v2-ba41e44b0f6f5a34bba5edf65153155e_b.jpg](https://i-blog.csdnimg.cn/blog_migrate/71ba2295a0f8961a3e945933d38ef6b6.jpeg)