目录
五、添加被监控端
1、在web1[192.168.88.100]上部署node exporter
2、在Prometheus服务器上添加监控节点
3、浏览器查看添加结果
六、Grafana的部署
概述
部署步骤
七、监控MySQL数据库
1、配置MySQL
2、配置mysql exporter
3、配置prometheus监控mysql
五、添加被监控端
监控方式:
Prometheus客户端分为pull和push两种提交数据的方式
Pull——服务端主动向客户端拉取数据,客户端要安装导出器exporters作为守护进程
Push——客户端安装pushgateway插件,然后运维人员用脚本把监控数据组织成键值形式提交给pushgateway,再由它提交给服务端
node-exporter用于监控硬件和系统的常用指标
exporter运行于被监控端,以服务的形式存在。每个exporter所使用的端口号都不一样。
服务名:node_exporter
服务端口:9100
1、在web1[192.168.88.100]上部署node exporter
# 拷贝node_exporter到web1
[root@prometheus ~]# scp prometheus_soft/node_exporter-1.5.0.linux-amd64.tar.gz 192.168.88.100:/root/
# 解压即部署
[root@web1 ~]# tar xf node_exporter-1.5.0.linux-amd64.tar.gz
[root@web1 ~]# mv node_exporter-1.5.0.linux-amd64 /usr/local/node_exporter
#创建服务文件,并启动服务
[root@web1 ~]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
[root@web1 ~]# systemctl daemon-reload
[root@web1 ~]# systemctl enable node_exporter.service --now
[root@web1 ~]# ss -tlnp | grep :9100
LISTEN 0 128 *:9100 *:* users:(("node_exporter",pid=7371,fd=3))
2、在Prometheus服务器上添加监控节点
#修改配置文件,追加以下内容。特别注意缩进
[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
...略...
- job_name: "web1"
static_configs:
- targets: ["192.168.88.100:9100"]
#重启服务
[root@prometheus ~]# systemctl restart prometheus.service
3、浏览器查看添加结果
六、Grafana的部署
概述
Grafana是一个跨平台的开源的度量分析和可视化工具,通过将采集的数据查询然后可视化的展示
展示方式: 快速灵活的客户端图表,面板插件有热图、折线图、图表等
数据源:Graphite,InfluxDB,OpenTSDB、Prometheus、Elasticsearch、CloudWatch、KairosDB等
服务名:grafana-server
服务端口:3000
部署步骤
1、装包、启服务
[root@prometheus ~]# yum install -y prometheus_soft/grafana-enterprise-9.3.2-1.x86_64.rpm
[root@prometheus ~]# systemctl enable grafana-server.service --now
2、登录grafana
访问http://192.168.88.5:3000。初始用户名和密码都是admin。第一次登陆时,要求改密码,本例中密码改为tedu.cn。如果登陆报错,请更换其他浏览器。
修改主题
对接Prometheus
添加仪表盘
查看仪表盘
3.展示node1的监控信息
grafana模板下载:Grafana dashboards | Grafana Labs
导入主机监控模板。
`
七、监控MySQL数据库
服务名:mysqld_exporter
端口:9104
1、配置MySQL
[root@web1 ~]# yum install -y mysql-server
[root@web1 ~]# systemctl enable mysqld --now
[root@web1 ~]# mysql
mysql> create user dbuser1@localhost identified by '123456';
mysql> grant all privileges on *.* to dbuser1@localhost;
mysql> quit
2、配置mysql exporter
# 安装
[root@prometheus ~]# scp prometheus_soft/mysqld_exporter-0.14.0.linux-amd64.tar.gz 192.168.88.100:/root/
[root@web1 ~]# tar xf mysqld_exporter-0.14.0.linux-amd64.tar.gz
[root@web1 ~]# mv mysqld_exporter-0.14.0.linux-amd64 /usr/local/mysqld_exporter
# 编写用于连接mysql服务的配置文件
[root@web1 ~]# vim /usr/local/mysqld_exporter/.my.cnf
[client]
host=127.0.0.1
port=3306
user=dbuser1
password=123456
# 创建service文件
[root@web1 ~]# vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target
[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \
--config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
[Install]
WantedBy=multi-user.target
[root@web1 ~]# systemctl daemon-reload
[root@web1 ~]# systemctl enable mysqld_exporter.service --now
3、配置prometheus监控mysql
#在配置文件中追加内容
[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
...略...
- job_name: "mysql"
static_configs:
- targets: ["192.168.88.100:9104"]
#重启服务
[root@prometheus ~]# systemctl restart prometheus.service
- 查看状态
5、在Grafana中展示数据