prometheus数据库服务搭建和自监控配置
prometheus数据库服务搭建和自监控配置
1、下载prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
2、解压,移动prometheus二进制包至/opt目录并做个版本链接。
tar zxf prometheus-2.48.1.linux-amd64.tar.gz mv prometheus-2.48.1.linux-amd64 /opt/prometheus-2.48.1 ln -s /opt/prometheus-2.48.1 /usr/local/prometheus
版本软连接是方便后期版本更新。
3、配置prometheus自监控
vim /usr/local/prometheus/prometheus.yml
#修改文件内配置为以下配置 global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"]
这里采用的最简单配置,后续根据需求再增加。
4、配置systemd管理脚本
vim /usr/lib/systemd/system/prometheus.service
#添加以下配置 [Unit] Description=Prometheus After=network.target [Service] Type=simple ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus-data --storage.tsdb.retention=365d --web.enable-lifecycle [Install] WantedBy=multi-user.target
--storage.tsdb.path 指定数据目录。
--storage.tsdb.retention 配置数据保存时间
--web.enable-lifecycle 开启prometheus接收POST请求来重新加载配置文件。
重新加载配置文件:
curl -X POST http://localhost:9090/-/reload
5、启动prometheus,设置开机启动。
systemctl start prometheus
systemctl enable prometheus
6、防火墙端口开通。
firewall-cmd --permanent --add-port=9090/tcp
firewall-cmd --reload
7、查看监控情况。
在浏览器打开地址http://xxx.xxx.xxx.xxx:9090