监控系统
Prometheus
安装prometheus
CPU报警规则
磁盘报警规则
内存报警规则
实例存活告警规则
node_exporter
安装node_exporter
consul服务发现
安装consul
ansible注册服务器到consul
curl注册、注销服务到consul
AlertManger
安装AlertManger
BlackBox_exporter
安装blackbox_exporter
本文档使用 MrDoc 发布
-
+
首页
安装prometheus
# 安装prometheus [【附件】prometheus和grafana安装配置.zip](/media/attachment/2021/08/prometheus和grafana安装配置.zip) ## 下载 - 官网链接: [https://prometheus.io/download/](https://prometheus.io/download/ "https://prometheus.io/download/") - 本文使用版本:`2.28.1/2021-07-01` - 下载链接:[https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz](https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz "https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz") ```shell tar xzf prometheus-2.28.1.linux-amd64.tar.gz mv prometheus-2.28.1.linux-amd64 /usr/local/prometheus mkdir /usr/local/prometheus/{data,rules,config,logs} ``` ## prometheus主配置文件 ```yaml global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: - 1.1.1.1:9093 timeout: 10s api_version: v2 path_prefix: / scheme: http basic_auth: username: ${username} password: ${password} rule_files: - "/usr/local/prometheus/rules/cpu_over.yml" - "/usr/local/prometheus/rules/disk_over.yml" - "/usr/local/prometheus/rules/memory_over.yml" - "/usr/local/prometheus/rules/node_down.yml" scrape_configs: - job_name: 'prometheus-server' scheme: 'http' static_configs: - targets: ['localhost:9090'] metrics_path: /metrics basic_auth: username: ${username} password: ${password} - job_name: 'consul-sd' consul_sd_configs: - server: '127.0.0.1:8500' services: [] relabel_configs: - source_labels: [__meta_consul_service_port] regex: 8300 action: drop - regex: __meta_consul_service_metadata_(.+) action: labelmap ``` ## prometheus web配置文件 - 需要:httpd-tools - 加密命令:`htpasswd -nBC 10 "" | tr -d ':\n'` 运行命令后将输出的密码加入到web-config.yml文件的用户名后。 ``` basic_auth_users: ${username}: ${password} zhangky: ${password} ``` ## 启动服务器 ``` /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" \ --web.listen-address="0.0.0.0:9090" \ --web.config.file="/usr/local/prometheus/config/web-config.yml" \ --storage.tsdb.path="/usr/local/prometheus/config/data" > /usr/local/prometheus/logs/prometheus.log 2>&1 & ``` ## systemd启动脚本 ``` [root@osa-monitor node_exporter]# cat /usr/lib/systemd/system/prometheus.service [Unit] Description=prometheus After=syslog.target network.target ConditionFileIsExecutable=/usr/local/prometheus/prometheus [Service] StartLimitInterval=5 StartLimitBurst=10 ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/config/prometheus.yml --web.listen-address=0.0.0.0:9090 --web.config.file=/usr/local/prometheusconfig//web-config.yml --storage.tsdb.path=/usr/local/prometheus/data --storage.tsdb.retention=180d ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=always RestartSec=30 [Install] WantedBy=multi-user.target ```
zhangky
2021年8月23日 14:17
分享文档
收藏文档
上一篇
下一篇
微信扫一扫
复制链接
手机扫一扫进行分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码