prometheus的安装


下载Promethues二进制包:Download | Prometheus

image-20240926162436793

#### 下载4个软件
## 下载prometheus
## 下载alertmanager(告警组件)
## 下载node_exporter(宿主机指标收集器)
## 下载pushgateway(自定义监控组件)

安装prometheus

[root@master01 ~]# mkdir /app
[root@master01 ~]# tar xf prometheus-2.54.1.linux-amd64.tar.gz -C /app/
[root@master01 ~]# mv /app/prometheus-2.54.1.linux-amd64 /app/prometheus-2.54.1
[root@master01 ~]# ln -s /app/prometheus-2.54.1 /app/prometheus

### 启动命令
/app/prometheus/prometheus --config.file=/app/prometheus/prometheus.yml
#### 配置文件详解 
cat /app/prometheus/prometheus.yml

image-20240926162727955

image-20240926163156062

浏览器访问: http://10.0.0.200:9090/

image-20240926163341460


安装node_exporter(宿主机指标收集器)

[root@master01 ~]# tar xf node_exporter-1.8.2.linux-amd64.tar.gz -C /app/
[root@master01 ~]# mv /app/node_exporter-1.8.2.linux-amd64 /app/node_exporter-1.8.2
[root@master01 ~]# ln -s /app/node_exporter-1.8.2 /app/node_exporter
### 将master 加入集群
[root@master01 ~]# vim /app/prometheus/prometheus.yml


## 启动命令
/app/node_exporter/node_exporter

image-20240926163632944

#### 开启两个终端 都启动测试

浏览器访问: http://10.0.0.200:9090/

image-20240926163922294

安装pushgateway(自定义监控组件)

[root@master01 ~]# tar xf pushgateway-1.10.0.linux-amd64.tar.gz -C /app/
[root@master01 ~]# mv /app/pushgateway-1.10.0.linux-amd64 /app/pushgateway-1.10.0
[root@master01 ~]# ln -s /app/pushgateway-1.10.0 /app/pushgateway


## 启动命令 
/app/pushgateway/pushgateway

安装alertmanager(告警组件)

[root@master01 ~]# tar xf alertmanager-0.27.0.linux-amd64.tar.gz -C /app
[root@master01 ~]# mv /app/alertmanager-0.27.0.linux-amd64 /app/alertmanager-0.27.0
[root@master01 ~]# ln -s /app/alertmanager-0.27.0 /app/alertmanager

## 启动命令
/app/alertmanager/alertmanager --config.file=/app/alertmanager/alertmanager.yml

安装cAdvisor

docker run --name cadvisor -p 8080:8080 -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys:ro  -v /var/lib/docker:/var/lib/docker:ro  -d  google/cadvisor:latest

使用supervisor 管理应用

[root@master01 ~]# vim /etc/supervisord.d/prome.ini
[program:prometheus]
directory=/app/prometheus/
command=/bin/bash -c "/app/prometheus/prometheus --config.file=/app/prometheus/prometheus.yml"
autostart=true
autorestart=true
stdout_logfile=/var/log/prome_stdout.log
stderr_logfile=/var/log/prome_stderr.log
user=root
stopsignal=TERM
startsecs=5
startretries=3
stopasgroup=true
killasgroup=true


[program:node]
directory=/app/node_exporter
command=/bin/bash -c "/app/node_exporter/node_exporter"
autostart=true
autorestart=true
stdout_logfile=/var/log/node_exporter_stdout.log
stderr_logfile=/var/log/node_exporter_stderr.log
user=root
stopsignal=TERM
startsecs=5
startretries=3
stopasgroup=true
killasgroup=true

[program:pushgateway]
directory=/app/pushgateway
command=/bin/bash -c "/app/pushgateway/pushgateway"
autostart=true
autorestart=true
stdout_logfile=/var/log/pushgateway_stdout.log
stderr_logfile=/var/log/pushgateway_stderr.log
user=root
stopsignal=TERM
startsecs=5
startretries=3
stopasgroup=true
killasgroup=tru