1.环境准备
准备两台机器:
Node1 用于安装Promethus
Node2 用于被监控或者在上面安装其他被监控的服务
下载安装包:
Promethus 安装包,grafana安装包以及node_exporter安装包
下载地址: https://prometheus.io/download/
2,Node1上传prometheus安装包
解压prometheus 安装包
tar -zxf prometheus-2.39.1.linux-amd64.tar.gz
mv prometheus-2.39.1.linux-amd64 prometheus2.39.1
3、启动prometheus服务
默认情况下,不需要做任何的配置和修改,直接使用下面的命令启动即可
cd prometheus2.39.1
./prometheus --config.file=prometheus.yml &
或者使用以下命令启动(生产环境)
nohup /root/soft/prometheus2.39.1/prometheus --config.file="prometheus.yml" --web.listen-address="0.0.0.0:9090" --web.enable-lifecycle --web.enable-remote-write-receiver --web.max-connections=512 --storage.tsdb.retention.time=7d --query.timeout=1m --query.max-concurrency=100 --query.max-samples=2000000 --web.read-timeout=3m --log.level=debug --log.format=logfmt >> prometheus.log 2>&1 &
启动成功后,prometheus 默认暴露的服务访问端口为 9090
4.浏览器访问
主机ip+端口 http://192.168.73.11:9090/
点击Status ---> Targets
5.配置监控其他服务器
node2节点上传 node_exporter安装包
tar -zxf node_exporter-1.6.0.linux-amd64.tar.gz
mv node_exporter-1.6.0.linux-amd64 node_exporter
6.启动node_exporter 服务
cd node_exporter
nohup ./node_exporter &
7.检查服务状态
node_exporter 默认暴露9100端口 可以使用netstat -antp | grep LIST | grep 9100查看
8.node1节点Prometheus做如下配置
vim prometheus.yml 找到下面的配置所在的位置,然后在后面添加新的配置
添加如下配置:
- job_name: "prometheus_node1"
static_configs:
- targets: ["23.247.131.231:9100"]
9.可以直接重启也可以重新加载配置文件
重启:先杀死进程在重新启动
ps aux | grep prometheus | grep -v grep | awk '{print $2}' | xargs kill
nohup /root/soft/prometheus2.39.1/prometheus --config.file="prometheus.yml" --web.listen-address="0.0.0.0:9090" --web.enable-lifecycle --web.enable-remote-write-receiver --web.max-connections=512 --storage.tsdb.retention.time=7d --query.timeout=1m --query.max-concurrency=100 --query.max-samples=2000000 --web.read-timeout=3m --log.level=debug --log.format=logfmt >> prometheus.log 2>&1
或者使用重新加载命令:(此命令前提是启动时制定了--web.enable-lifecycle参数)
/usr/bin/curl -X POST http://192.168.73.11:9090/-/reload
然后打开浏览器页面查看发现已经有了node2的监控项