安装prometheus
下载并安装 服务器地址为:192.168.10.1
cd /usr/local
wget https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.linux-amd64.tar.gz
tar -zxvf prometheus-2.26.0.linux-amd64.tar.gz
mv prometheus-2.26.0.linux-amd64 promehtues
创建prometheus用户
groupadd prometheus useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
chown prometheus.prometheus /usr/local/prometheus -R
创建启动脚本:
vim /usr/lib/systemd/system/prometheus.service [Unit] Description=prometheus After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --storage.tsdb.retention.time=15d --log.level=info Restart=on-failure [Install] WantedBy=multi-user.target
配置 Prometheus 添加监控目标
cd /usr/local/prometheus vim prometheus.yml scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: '192.168.10.1' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090','localhost:9100'] # 对本机node_exporter 监控 # 新添加的对其它node节点抓取数据 - job_name: '192.168.75.10' #重写了全局抓取间隔时间,由15秒重写成5秒。 scrape_interval: 5s static_configs: - targets: ['192.168.10.2:9100']
启动prometheus
systemctl enable prometheus.service
systemctl start prometheus.service
systemctl status prometheus.service
访问
访问 Prometheus WEB 查看我们定义的目标主机:http://192.168.10.1:9090/targets