centos7安装Promethus及Node Exporter

grafana 安装

 
下载promethus包或上传包至服务器
#下载、解压
wget https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gz
tar -xf prometheus-2.13.0.linux-amd64.tar.gz
mv prometheus-2.13.0.linux-amd64 prometheus
mv prometheus  /usr/local/
 
修改配置文件
# 全局配置
global:
  scrape_interval:     15s # 设置抓取间隔,默认为1分钟
  evaluation_interval: 15s #估算规则的默认周期,每15秒计算一次规则。默认1分钟
  # scrape_timeout  #默认抓取超时,默认为10s

# Alertmanager相关配置
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# 规则文件列表,使用'evaluation_interval' 参数去抓取
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

#  抓取配置列表
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

创建Systemd服务启动prometheus

 vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target

 开机启动及相关命令

加入开机启动
systemctl enable prometheus
启动及查看状态
systemctl start prometheus
systemctl status prometheus

使用Node Exporter采集主机运行数据

下载安装及启动

wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar -xzvf node_exporter-1.3.1.linux-amd64.tar.gz
#改名
mv node_exporter-1.3.1.linux-amd64  node-exporter

mv node_exporter /usr/local/
启动
cd /usr/local/node_exporter
nohup /usr/local/prometheus_exporter/node_exporter/node_exporter >/dev/null 2>&1 &
  

加入开机启动

在 /etc/rc.local 加入上面的启动命令即可
##node exporter
nohup /usr/local/prometheus_exporter/node_exporter/node_exporter >/dev/null 2>&1 &
验证是否启动成功
netstat -npl|grep 9100

  

配置Prmethus采集node_exporter机器数据

配置promethus配置文件,增加相应采集机器内容

- job_name: "OCR"
    static_configs:
      - targets: ["172.16.1.57:9100"]

  - job_name: "172.16.1.61"
    static_configs:
      - targets: ["172.16.1.61:9100"]

配置好后,重新加载配置及启动promethus

systemctl daemon-reload  
systemctl stop prometheus.service
systemctl start prometheus.service
systemctl status prometheus.service

  

 至此,promethus及node_exporter均已安装完成并已经运行,

 

posted @ 2022-02-23 14:13  test_yu  阅读(171)  评论(0编辑  收藏  举报