一、prometheus 部署
1. 下载二进制包
wget https://github.com/prometheus/prometheus/releases/download/v2.45.4/prometheus-2.45.4.linux-amd64.tar.gz
2. 创建运行用户 prometheus
sudo useradd -rs /bin/false prometheus
3. 创建运行目录
sudo mkdir -p /lvmdata/prometheus/data-prometheus
sudo chown -R prometheus:prometheus /lvmdata/prometheus/
4. 部署文件
tar xzf prometheus-2.45.4.linux-amd64.tar.gz && cd prometheus-2.45.4.linux-amd64
sudo install -o prometheus -g prometheus -m 0755 prometheus /usr/local/bin/prometheus
sudo install -o prometheus -g prometheus -m 0755 promtool /usr/local/bin/promtool
sudo install -o prometheus -g prometheus -m 0755 prometheus.yml /lvmdata/prometheus/prometheus.yml
sudo install -o prometheus -g prometheus -m 0755 promtool /usr/local/bin/promtool
sudo sh -c "cp -r console* /lvmdata/prometheus/ && chown -R prometheus:prometheus /lvmdata/prometheus/"
5. 创建 systemd service 文件 /etc/systemd/system/prometheus.service
执行如下命令:
sudo tee /etc/systemd/system/prometheus.service<<EOF
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=always
ExecStart=/usr/local/bin/prometheus \
--config.file=/lvmdata/prometheus/prometheus.yml \
--web.console.libraries=/lvmdata/prometheus/console_libraries \
--web.console.templates=/lvmdata/prometheus/conf/consoles \
--storage.tsdb.path=/lvmdata/prometheus/data-prometheus \
--storage.tsdb.retention.time=30d
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
6. 重新加载配置文件
Prometheus 可以在运行时重新加载配置文件,而不用重启
curl -i -XPOST localhost:9090/-/reload
curl -X POST http://127.0.0.1:9090/-/reload
二、alertmanager 部署
1. 下载二进制包
wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz
2. 创建运行用户 alertmanager
sudo useradd -rs /bin/false alertmanager
如果与prometheus共同部署,也可以直接使用 prometheus
用户名
3. 部署文件
tar xzf alertmanager-0.27.0.linux-amd64.tar.gz && cd alertmanager-0.27.0.linux-amd64
sudo install -o prometheus -g prometheus -m 0755 prometheus /usr/local/bin/prometheus
sudo install -o prometheus -g prometheus -m 0755 amtool /usr/local/bin/amtool
sudo install -o prometheus -g prometheus -m 0755 alertmanager.yml /lvmdata/prometheus/alertmanager.yml
4. 创建 systemd service 文件 /etc/systemd/system/alertmanager.service
sudo tee /etc/systemd/system/alertmanager.service<<EOF
[Unit]
Description=Alertmanager
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
WorkingDirectory=/lvmdata/prometheus/
ExecStart=/usr/local/bin/alertmanager \
--config.file=/lvmdata/prometheus/alertmanager.yml \
--storage.path=/lvmdata/prometheus/data-alertmanager \
--web.external-url http://0.0.0.0:9093
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now alertmanager
三、node_exporter 部署
Node Exporter Setup on Linux Nodes - VMware
node-exporter - Prometheus
node-exporter - Github
1. 下载二进制包
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
2. 创建运行用户 node_exporter
sudo useradd -rs /bin/false node_exporter
3. 部署二进制文件
将解压后的 node_exporter
二进制文件部署到 /usr/local/bin/
sudo install -o node_exporter -g node_exporter -m 0755 node_exporter /usr/local/bin/node_exporter
4. 创建 systemd service 文件 /etc/systemd/system/node_exporter.service
sudo tee /etc/systemd/system/node_exporter.service<<EOF
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
四、process-exporter 部署
https://prometheus.io/docs/instrumenting/exporters/#miscellaneous
https://github.com/ncabatoff/process-exporter
注意事项
As/proc/[pid]/io
are set by the kernel as read only to the process' user (see #137), to get these values you should runprocess-exporter
either as that user or as root. Otherwise, we can't read these values and you'll get a constant 0 in the metric.
在运行环境中,可以配置运行账户固定为1002,然后指定 process-exporter 用户组为1002。
1. 二进制部署
- 下载二进制包
wget https://github.com/ncabatoff/process-exporter/releases/download/v0.8.2/process-exporter-0.8.2.linux-amd64.tar.gz
- 创建运行用户
process_exporter
sudo useradd -rs /bin/false process-exporter
- 部署二进制文件
将解压后的 process_exporter
二进制文件部署到 /usr/local/bin/
sudo install -o process_exporter -G 1002 -m 0755 process_exporter /usr/local/bin/process_exporter
- 创建 systemd service 文件
/etc/systemd/system/process_exporter.service
sudo tee /etc/systemd/system/node_exporter.service<<EOF
[Unit]
Description=process-exporter
After=network.target
[Service]
User=root
Type=simple
ExecStart=/usr/local/bin/process-exporter --config.path=/lvmdata/process-exporter/process-name.yaml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
2. 使用 rpm 包部署
- 下载rpm包,并部署
wget https://github.com/ncabatoff/process-exporter/releases/download/v0.8.2/process-exporter_0.8.2_linux_amd64.rpm
rpm -ivh process-exporter_0.8.2_linux_amd64.rpm
Created symlink
/etc/systemd/system/multi-user.target.wants/process-exporter.service
→/usr/lib/systemd/system/process-exporter.service
.
- 查看服务配置文件
[Unit]
Description=Process Exporter for Prometheus
[Service]
User=root
Type=simple
EnvironmentFile=-/etc/default/process-exporter
ExecStart=/usr/bin/process-exporter $OPTS
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
- 解析安装文件
[root@VM-99-12-centos ~]# rpm -ql process-exporter
/etc/default/process-exporter
/etc/process-exporter/all.yaml
/lib/systemd/system/process-exporter.service
/usr/bin/process-exporter
- 环境变量配置文件
[root@VM-99-12-centos ~]# cat /etc/default/process-exporter
# process-exporter startup flags
OPTS='--config.path /etc/process-exporter/all.yaml --web.listen-address=:9256'
- 监控配置文件
[root@VM-99-12-centos ~]# cat /etc/process-exporter/all.yaml
process_names:
- name: "{{.Comm}}"
cmdline:
- '.+'
网友评论