prometheus

prometheus部署

部署prometheus
下载prometheus

[root@prometheus ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-amd64.tar.gz
[root@prometheus ~]# tar xf prometheus-2.28.0.linux-amd64.tar.gz
[root@prometheus ~]# mv prometheus-2.28.0.linux-amd64 /usr/local/prometheus

[root@prometheus ~]# useradd -r -M -s /sbin/nologin prometheus

[root@prometheus ~]# mkdir -p /opt/data/prometheus

[root@prometheus ~]# chown -R prometheus.prometheus /usr/local/prometheus /opt/data/prometheus

[root@prometheus ~]# ll /usr/local/
total 0
drwxr-xr-x. 2 root       root         6 May 18  2020 bin
drwxr-xr-x. 2 root       root         6 May 18  2020 etc
drwxr-xr-x. 2 root       root         6 May 18  2020 games
drwxr-xr-x. 2 root       root         6 May 18  2020 include
drwxr-xr-x. 2 root       root         6 May 18  2020 lib
drwxr-xr-x. 3 root       root        17 Apr 23 05:53 lib64
drwxr-xr-x. 2 root       root         6 May 18  2020 libexec
drwxr-xr-x. 4 prometheus prometheus 132 Jun 21 12:01 prometheus
drwxr-xr-x. 2 root       root         6 May 18  2020 sbin
drwxr-xr-x. 5 root       root        49 Apr 23 05:53 share
drwxr-xr-x. 2 root       root         6 May 18  2020 src

[root@prometheus ~]# ll /opt/data/
total 0
drwxr-xr-x. 2 prometheus prometheus 6 July 1 09:55 prometheus

编写service文件

[root@prometheus ~]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
After=network.target

[Service]
Type=simple
Environment="GOMAXPROCS=4"
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/prometheus/prometheus \
  --config.file=/usr/local/prometheus/prometheus.yml \
  --storage.tsdb.path=/opt/data/prometheus \
  --storage.tsdb.retention=30d \
  --web.console.libraries=/usr/local/prometheus/console_libraries \
  --web.console.templates=/usr/local/prometheus/consoles \
  --web.listen-address=0.0.0.0:9090 \
  --web.read-timeout=5m \
  --web.max-connections=10 \
  --query.max-concurrency=20 \
  --query.timeout=2m \
  --web.enable-lifecycle
PrivateTmp=true
PrivateDevices=true
ProtectHome=true
NoNewPrivileges=true
LimitNOFILE=infinity
ReadWriteDirectories=/opt/data/prometheus
ProtectSystem=full

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

启动prometheus

[root@prometheus ~]# systemctl daemon-reload   #重新加载服务的配置文件
[root@prometheus ~]# systemctl enable prometheus && systemctl start prometheus
[root@prometheus ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port       Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                         
LISTEN        0             128                           [::]:22                         [::]:*                         
LISTEN        0             128                              *:9090     

在这里插入图片描述
AlertManager部署
下载AlertManager

[root@prometheus ~]# wget https://github.com/prometheus/alertmanager/releases/download/v0.22.2/alertmanager-0.22.2.linux-amd64.tar.gz
[root@prometheus ~]# tar xf alertmanager-0.22.2.linux-amd64.tar.gz

安装AlertManager

[root@prometheus ~]# mv alertmanager-0.22.2.linux-amd64 /usr/local/alertmanager
[root@prometheus ~]# chown -R prometheus.prometheus /usr/local/alertmanager

编写service文件

[root@prometheus ~]# vim /usr/lib/systemd/system/alertmanager.service
[Unit]
Description=Alertmanager
After=network.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/usr/local/alertmanager/alertmanager \
  --config.file=/usr/local/alertmanager/alertmanager.yml \
  --storage.path=/usr/local/alertmanager/data \
  --web.listen-address=0.0.0.0:9093 \
  --cluster.listen-address=0.0.0.0:9094 \
  --log.level=info \
  --log.format=logfmt
Restart=always

[Install]
WantedBy=multi-user.target

启动AlertManager

[root@prometheus ~]# systemctl daemon-reload
[root@prometheus ~]# systemctl enable alertmanager && systemctl start alertmanager
[root@prometheus ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port       Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                         
LISTEN        0             128                              *:9093                          *:*                         
LISTEN        0             128                              *:9094                          *:*                         
LISTEN        0             128                           [::]:22                         [::]:*                         
LISTEN        0             128                              *:9090                          *:*

配置prometheus

[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
  - job_name: 'alertmanager'
    static_configs:
    - targets: ['192.168.11.120:9093']
[root@prometheus ~]# systemctl restart prometheus

在这里插入图片描述
在这里插入图片描述

部署Node Exporter

下载Node Exporter

[root@prometheus ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
[root@prometheus ~]# tar xf node_exporter-1.1.2.linux-amd64.tar_2.gz

安装Node Exporter

[root@prometheus ~]# mv node_exporter-1.1.2.linux-amd64 /usr/local/node_exporter
[root@prometheus ~]# chown -R prometheus.prometheus /usr/local/node_exporter

编写service文件

[root@prometheus ~]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/usr/local/node_exporter/node_exporter \
  --web.listen-address=0.0.0.0:9100 \
  --web.telemetry-path=/metrics \
  --log.level=info \
  --log.format=logfmt
Restart=always

[Install]
WantedBy=multi-user.target

启动Node Exporter

[root@prometheus ~]# systemctl daemon-reload
[root@prometheus ~]# systemctl enable node_exporter && systemctl start node_exporter
[root@prometheus ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port       Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                         
LISTEN        0             128                              *:9093                          *:*                         
LISTEN        0             128                              *:9094                          *:*                         
LISTEN        0             128                              *:9100                          *:*                         
LISTEN        0             128                           [::]:22                           [::]:*                         
LISTEN        0             128                              *:9090                       *:*

配置prometheus

[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'node'
    static_configs:
    - targets: ['192.168.11.120:9100']
[root@prometheus ~]# systemctl restart prometheus

在这里插入图片描述
grafana部署

[root@prometheus ~]# wget https://dl.grafana.com/oss/release/grafana-7.5.6-1.x86_64.rpm
[root@prometheus ~]# dnf -y install grafana-7.5.6-1.x86_64.rpm
[root@prometheus ~]# service grafana-server restart
Reloading systemd:                                         [  OK  ]
Restarting grafana-server (via systemctl):                 [  OK  ]
[root@prometheus ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port       Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                         
LISTEN        0             128                              *:9093                          *:*                         
LISTEN        0             128                              *:9094                          *:*                         
LISTEN        0             128                              *:9100                          *:*                         
LISTEN        0             128                           [::]:22                         [::]:*                         
LISTEN        0             128                              *:3000                          *:*                         
LISTEN        0             128                              *:9090       

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

监控nginx

[root@prometheus ~]# git clone https://github.com/vozlt/nginx-module-vts.git
[root@prometheus ~]# unzip nginx-module-vts-master.zip
[root@prometheus ~]# cd nginx-module-vts-master
[root@prometheus nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=../nginx-module-vts-master/
[root@prometheus nginx-1.20.1]# make
[root@prometheus nginx-1.20.1]# cp /usr/local/nginx/sbin/nginx{,-bak}
[root@prometheus nginx-1.20.1]# pkill nginx;\cp objs/nginx /usr/local/nginx/sbin/;nginx
[root@prometheus nginx-1.20.1]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=../nginx-module-vts-master/

修改配置文件

[root@prometheus ~]# vim /usr/local/nginx/conf/nginx.conf
#在server中添加
        location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
#在http中添加
vhost_traffic_status_zone;
[root@prometheus ~]# pkill nginx
[root@prometheus ~]# nginx

在这里插入图片描述
安装nginx-vts-exporter
主要用于收集Nginx的监控数据,并且给prometheus提供监控接口,默认端口号是9913

[root@prometheus ~]# wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.9.1/nginx-vts-exporter-0.9.1.linux-amd64.tar.gz
[root@prometheus ~]# tar xf nginx-vts-exporter-0.9.1.linux-amd64.tar.gz 
[root@prometheus ~]# mv nginx-vts-exporter-0.9.1.linux-amd64 /usr/local/nginx-vts-exporter

编写service文件

[root@prometheus ~]# vim /usr/lib/systemd/system/nginx_vts_exporter.service
[Unit]
Description=prometheus_nginx_vts
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/nginx-vts-exporter/nginx-vts-exporter  -nginx.scrape_uri http://192.168.11.120/status/format/json
Restart=on-failure

[Install]
WantedBy=multi-user.target

启动nginx-vts-exporter

[root@prometheus ~]# systemctl daemon-reload
[root@prometheus ~]# systemctl enable  nginx_vts_exporter
[root@prometheus ~]# systemctl start  nginx_vts_exporter
[root@prometheus ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port       Process        
LISTEN        0             128                        0.0.0.0:80                      0.0.0.0:*                         
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                         
LISTEN        0             128                              *:9093                          *:*                         
LISTEN        0             128                              *:9094                          *:*                         
LISTEN        0             128                              *:9100                          *:*                         
LISTEN        0             128                           [::]:22                         [::]:*                         
LISTEN        0             128                              *:3000                          *:*                         
LISTEN        0             128                              *:9913                          *:*                         
LISTEN        0             128                              *:9090                          *:*

配置prometheus

[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
  - job_name: 'nginx'
    static_configs:
    - targets: ['192.168.11.120:9913']
[root@prometheus ~]# systemctl restart prometheus

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值