开源监控方案 Prometheus+Grafana 安装配置

Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由 SoundCloud 公司开发。

输出被监控组件信息的 HTTP 接口被叫做 exporter(相当于 zabbix_agent)。目前互联网公司常用的组件大部分都有 exporter 可以直接使用,比如 Varnish、Haproxy、Nginx、MySQL、Linux 系统信息 (包括磁盘、内存、CPU、网络等等),具体支持的源看:https://github.com/prometheus

Grafana 是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。

Prometheus 中存储的数据,通过 Grafana 很优美的展现出来。

这里测试安装将 Prometheus、Grafana、node_exporter 都安装在一台机器上。

go 环境配置

Golang的官网可能由于政策原因登陆不上,所以可以到Go语言中文网下载:https://studygolang.com/dl

在 Ubuntu 系统上使用apt install golang-go命令安装即可。

在 CentOS 系统上下载二进制包解压后即可:

  1. wget https://studygolang.com/dl/golang/go1.11.10.linux-amd64.tar.gz
  2. tar zxvf go1.11.10.linux-amd64.tar.gz -C /usr/local/
  3. ln -s /usr/local/go/bin/* /usr/local/bin/

Prometheus 部署

下载地址:https://prometheus.io/download/

  1. wget https://github.com/prometheus/prometheus/releases/download/v2.11.1/prometheus-2.11.1.linux-amd64.tar.gz
  2. tar zxvf prometheus-2.11.1.linux-amd64.tar.gz
  3. mv prometheus-2.11.1.linux-amd64 /usr/local/prometheus
  4. # 启动
  5. /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
  6. # 启动后默认端口是 9090

Grafana 部署

  1. wget https://dl.grafana.com/oss/release/grafana-6.2.5.linux-amd64.tar.gz
  2. tar zxvf grafana-6.2.5.linux-amd64.tar.gz
  3. mv grafana-6.2.5.linux-amd64 /usr/local/grafana
  4. cp /usr/local/grafana/conf/defaults.ini /usr/local/grafana/conf/custom.ini

rafana 默认使用 sqllite3 数据库存储,这里修改为 MySQL,编辑/usr/local/grafana/conf/custom.ini配置文件:

  1. [database]
  2. # You can configure the database connection by specifying type, host, name, user and password
  3. # as separate properties or as on string using the url property.
  4. # Either "mysql", "postgres" or "sqlite3", it's your choice
  5. type = mysql
  6. host = 127.0.0.1:3306
  7. name = grafana
  8. user = root
  9. # If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
  10. password = pwd123

先要创建好数据库,然后启动:

  1. /usr/local/grafana/bin/grafana-server &
  2. # 启动后默认端口是 3000,可使用 Nginx 反向代理进行访问。

登录后,默认用户名/密码都是:admin,首次登录会提示修改密码。

exporter 部署

下载地址:https://github.com/prometheus/node_exporter/releases

  1. wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
  2. tar zxvf node_exporter-0.18.1.linux-amd64.tar.gz
  3. mv node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin/
  4. # 启动
  5. node_exporter &

启动后需要在 Prometheus 配置文件 prometheus.yml 中添加:

  1. - job_name: 'node'
  2. static_configs:
  3. - targets: ['127.0.0.1:9100']

然后重启 Prometheus 生效。

免责声明:
1.本站所有内容只做学习和交流使用。 版权归原作者所有。
2.保证站内提供的所有可下载源码资源(软件等)都是按“原样”提供,本站未做过任何改动;但本网站不保证本站提供的下载资源的准确性、安全性和完整性;同时本网站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。
3.本站部分内容均收集于网络!如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。请联系站长邮箱:admin#ibian.online(#换成@)处理!
服务器

linux DDoS & CC防护之(四)fail2ban 的安装及其简单应用

2025-2-24 19:36:26

中间件数据库

MySQL 高性能中间件 ProxySQL 初步了解和安装

2025-2-25 9:29:36

0 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
私信列表
搜索