grafana部署监控nginx

1.下载nginx压缩包

wget http://nginx.org/download/nginx-1.18.0.tar.gz

2.下载好解压到目录/opt/,并把文件夹重命名为nginx

tar zxvf nginx-1.18.0.tar.gz -C /opt/ && mv /opt/nginx/nginx-1.18.0 /opt/nginx/nginx

3.进入nginx目录后编译安装(注:一定要加上参数--with-http_stub_status_module),如果编译时报错make: *** No rule to make target `build', needed by `default'.  Stop,则先安装先关的库

yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel后,重新编译

cd /opt/nginx/

./configure --with-http_stub_status_module

make && make install

4.检查是否开启 tub_status 模块(返回with-http_stub_status_module则表示已经安装,若没有返回,请重新编译安装nginx)

cd /usr/local/nginx/sbin

./nginx -V 2>&1 | grep -o with-http_stub_status_module

5.修改nginx配置文件

cd /usr/local/nginx/conf

vim nginx.conf

6.检查并重新加载 nginx 的配置使其生效

cd /usr/local/nginx/sbin

./nginx -t

./nginx

7.下载nginx-prometheus-exporter(网页下载)

地址:https://github.com/nginxinc/nginx-prometheus-exporter/releases

 8.解压文件到/opt/aspire/product/nginx_exporter

mkdir -p /opt/aspire/product/nginx_exporter

tar zxvf nginx-prometheus-exporter_0.9.0_linux_amd64.tar.gz -C /opt/aspire/product/nginx_exporter/

9.启动nginx-prometheus-exporter服务

cd /opt/aspire/product/nginx_exporter/

./nginx-prometheus-exporter -nginx.scrape-uri http://localhost:80/nginx_status

 10.下载prometheus

wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz

11.解压prometheus到目录/opt/aspire/product/,并把文件夹重命名为prometheus

tar zxvf prometheus-2.28.1.linux-amd64.tar.gz -C /opt/aspire/product/

mv prometheus-2.28.1.linux-amd64 prometheus

12.修改prometheus配置文件,在原有的配置上追加nginx-prometheus-exporter地址,nginx-prometheus-exporter默认端口是9113

cd /opt/aspire/product/prometheus

 vim prometheus.yml

13.启动prometheus

cd /opt/aspire/product/prometheus

nohup ./prometheus &

14.打开网页验证是否成功,http://localhost:9090/targets

 

15.下载grafana并解压到/opt/aspire/product/,把文件夹重名名为grafana

wget https://dl.grafana.com/oss/release/grafana-8.0.6.linux-amd64.tar.gz

tar zxvf grafana-8.0.6.linux-amd64.tar.gz -C /opt/aspire/product/

mv grafana-8.0.6 grafana

16.启动grafana

cd /opt/aspire/product/grafana/bin

nohup ./grafana-server &

17.验证页面,http://localhost:3000,初始账号密码都是admin

 

18.下载nginx-prometheus-exporter对应的grafana模板的json文件

https://grafana.com/api/dashboards/13577/revisions/1/download

然后把这个json文件导入grafana,下面步骤见截图。

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

import bugs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值