部署思路:
1、安装go语言环境
2、在监控服务器上安装prometheus
3、在被监控环境上安装export
4、安装grafana
5、安装alertmanager
以下基于centos7系统进行演示。
一、安装go语言环境
下载地址:https://studygolang.com/dl
1、解压
tar -xvf go1.13.linux-amd64.tar.gz -C /usr/local/
2、配置环境变量
echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
source /etc/profile
3、测试
验证一下是否成功,用go version 来验证
go version
二、在监控服务器安装prometheus
1、开始安装prometheus
去官网下载对应系统的版本:https://prometheus.io/download/
下载地址:https://github.com/prometheus/prometheus/releases/download/v2.12.0/prometheus-2.12.0.linux-amd64.tar.gz
2、上传到监控服务器并解压
tar -xvf prometheus-2.12.0.linux-amd64.tar.gz -C /usr/local/
ln -sv /usr/local/prometheus-2.12.0.linux-amd64/ /usr/local/Prometheus
3、监控端配置文件
prometheus.yml默认配置如下:
my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
scrape_timeout is set to the global default (10s).
Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
targets:
- alertmanager:9093
Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
- alertmanager:9093
rule_files:
- "first_rules.yml"
- "second_rules.yml"
A scrape configuration containing exactly one endpoint to scrape:
Here it's Prometheus itself.
scrape_configs:
The job name is added as a label job=<job_name>
to any timeseries scraped from this config.
- job_name: 'prometheus'
metrics_path defaults to '/metrics'
scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
prometheus.yml 中的配置详解
<boolean>: 布尔值,true 或 false
<duration>: 持续时间,格式符合正则表达式 [0-9]+(ms|[smhdwy])
<labelname>: 标签名,格式符合正则表达式 a-zA-Z_*
<labelvalue>: 标签值,可以包含任意 unicode 字符
<filename>: 文件名,任意有效的文件路径
<host>: 主机,可以是主机名或 IP,后面可跟端口号
<path>: URL 路径
<scheme>: 协议,http 或 https
<string>: 字符串
<secret>: 密钥,比如密码
<tmpl_string>: 模板字符串,里面包含需要展开的变量
4、启动prometheus
./prometheus
5、测试访问
访问地址:服务器IP:9090,点击Status-->targets 跳转到监控目标,红框的表示部署的prometheus
本文由 梁承龙 创作,采用 知识共享署名4.0 国际许可协议进行许可