Prometheus安装及使用(二进制方式)
一、Prometheus简介
1、Prometheus是什么
Prometheus是一个开源系统监控和警报工具,最初由 SoundCloud创建。自 2012 年以来,许多公司和组织都采用了 Prometheus,该项目拥有非常活跃的开发者和用户社区。
它现在是一个独立的开源项目,独立于任何公司进行维护。为了强调这一点,并明确项目的治理结构,Prometheus 于 2016 年作为继Kubernetes之后的第二个托管项目加入了云原生计算基金会(CNCF)。
2、Prometheus官方网址
https://prometheus.io/docs/introduction/overview/
二、Prometheus安装环境准备
实验环境
修改主机名
hostnamectl set-hostname xxx
三、Prometheus安装(prometheus-server)
1、下载或上传prometheus-2.37.8.linux-amd64.tar.gz包到/root目录
下载方式:wget https://github.com/prometheus/prometheus/releases/download/v2.37.8/prometheus-2.37.8.linux-amd64.tar.gz
2、Prometheus安装
tar xf prometheus-2.37.8.linux-amd64.tar.gz
mv prometheus-2.37.8.linux-amd64 /usr/local/prometheus
3、修改Prometheus配置文件
cd /usr/local/prometheus/
vim prometheus.yml
修改:
4、启动Prometheus
nohup ./prometheus --config.file=prometheus.yml &
ps aux | grep prometheus
ss -anpt | grep 9090
5、将Prometheus托管给systemd
pkill prometheus
cat > /usr/lib/systemd/system/prometheus.service << EOF
[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
[Unit]
Description=prometheus
After=network.target
EOF
重新加载 systemd 单元文件
systemctl daemon-reload
systemctl enable --now prometheus
systemctl status prometheus
yum -y install lsof
列出正在使用指定端口(这里是 9090 端口)的进程和相关文件
lsof -i:9090
ps -ef | grep prometheus
四、Prometheus UI界面访问
可以通过运行Prometheus server节点IP+9090端口对Prometheus进行访问
使用浏览器访问192.168.10.14:9090
五、使用Prometheus监控Prometheus server及其它主机
1、对Prometheus server主机监控(prometheus-server)
(1)下载node_exporter或上传node_exporter-1.6.0.linux-amd64.tar.gz包到/root目录
下载方法:wget https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz
(2)安装node_exporter
tar xf node_exporter-1.6.0.linux-amd64.tar.gz
mv node_exporter-1.6.0.linux-amd64 /usr/local/node_exporter
cd /usr/local/node_exporter/
(3)启动node_exporter
nohup ./node_exporter &
ss -anpt | grep node_exporter
ss -anpt | grep 9100
(4)注册为systemd管理的系统服务
pkill node_exporter
cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
[Unit]
Description=node_exporter
After=network.target
EOF
systemctl daemon-reload
systemctl enable --now node_exporter
systemctl status node_exporter
(5)修改Prometheus Server配置文件添加node节点
cd /usr/local/prometheus/
vim prometheus.yml
添加:
- job_name: "prometheus-server"
static_configs:
- targets: ["192.168.10.14:9100"]
systemctl restart prometheus
2、对其它主机进行监控(以192.168.10.15为例)
(1)下载node_exporter或上传node_exporter-1.6.0.linux-amd64.tar.gz包到/root目录(prometheus-agent)
下载方法:wget https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz
(2)安装node_exporter(prometheus-agent)
tar xf node_exporter-1.6.0.linux-amd64.tar.gz
mv node_exporter-1.6.0.linux-amd64 /usr/local/node_exporter
cd /usr/local/node_exporter/
(3)启动node_exporter(prometheus-agent)
nohup ./node_exporter &
ss -anpt | grep node_exporter
(4)注册为systemd管理的系统服务(prometheus-agent)
pkill node_exporter
cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
[Unit]
Description=node_exporter
After=network.target
EOF
systemctl daemon-reload
systemctl enable --now node_exporter
systemctl status node_exporter
(5)修改Prometheus Server配置文件添加node节点(prometheus-server)
cd /usr/local/prometheus/
vim prometheus.yml
添加:
- job_name: "prometheus-agent"
static_configs:
- targets: ["192.168.10.15:9100"]
systemctl restart prometheus