|
|
|
|
<h1><center>Grafana集成Zabbix企业级监控解决方案</center></h1>
|
|
|
|
|
|
|
|
|
|
作者:行癫(盗版必究)
|
|
|
|
|
|
|
|
|
|
------
|
|
|
|
|
|
|
|
|
|
## 一:环境介绍
|
|
|
|
|
|
|
|
|
|
#### 1.Zabbix简介
|
|
|
|
|
|
|
|
|
|
是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案;zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题
|
|
|
|
|
|
|
|
|
|
#### 2.Grafana简介
|
|
|
|
|
|
|
|
|
|
Grafana 是一个开源的数据可视化和监控平台,它提供了强大的仪表盘和图表功能,可用于实时监控、数据分析和可视化展示
|
|
|
|
|
|
|
|
|
|
#### 3.监控集群简介
|
|
|
|
|
|
|
|
|
|
| 服务器 | IP地址 | 版本 |
|
|
|
|
|
| ---------------------------- | ----------------------- | ------------ |
|
|
|
|
|
| Zabbix-Server | 10.9.12.208 | 6.4.3 |
|
|
|
|
|
| Zabbix-Agent(Kubernetes集群) | 10.9.12.206-10.9.12.203 | 6.4.3+1.27.3 |
|
|
|
|
|
| Zabbix-Mysql | 10.9.12.206:30140 | 8.0.30 |
|
|
|
|
|
| Grafana-Server | 10.9.12.211 | 1.10.2 |
|
|
|
|
|
|
|
|
|
|
![image-20231117103700023](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117103700023.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117103742234](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117103742234.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117103937503](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117103937503.png)
|
|
|
|
|
|
|
|
|
|
## 二:Zabbix配置
|
|
|
|
|
|
|
|
|
|
#### 1.安装zabbix
|
|
|
|
|
|
|
|
|
|
略
|
|
|
|
|
|
|
|
|
|
备注:操作系统 centos stream 9 zabbix-server 6.4.3
|
|
|
|
|
|
|
|
|
|
#### 2.安装Mysql
|
|
|
|
|
|
|
|
|
|
略
|
|
|
|
|
|
|
|
|
|
备注:该数据库采用kubernetes集群Deployment创建,也可以服务器部署mysql 8.0
|
|
|
|
|
|
|
|
|
|
下载地址:
|
|
|
|
|
|
|
|
|
|
https://xingdiancloud.oss-cn-hangzhou.aliyuncs.com/xingdianoos/zabbix-mysql.yaml
|
|
|
|
|
|
|
|
|
|
https://github.com/blackmed/zabbix-mysql.git
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: ConfigMap
|
|
|
|
|
metadata:
|
|
|
|
|
name: mysql-config-zabbix
|
|
|
|
|
data:
|
|
|
|
|
mysql.cnf: |
|
|
|
|
|
[mysqld]
|
|
|
|
|
character-set-server=utf8mb4
|
|
|
|
|
collation-server=utf8mb4_general_ci
|
|
|
|
|
init-connect='SET NAMES utf8mb4'
|
|
|
|
|
|
|
|
|
|
[client]
|
|
|
|
|
default-character-set=utf8mb4
|
|
|
|
|
|
|
|
|
|
[mysql]
|
|
|
|
|
default-character-set=utf8mb4
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
apiVersion: apps/v1
|
|
|
|
|
kind: Deployment
|
|
|
|
|
metadata:
|
|
|
|
|
name: mysql-zabbix
|
|
|
|
|
labels:
|
|
|
|
|
app: mysql-zabbix
|
|
|
|
|
spec:
|
|
|
|
|
replicas: 1
|
|
|
|
|
selector:
|
|
|
|
|
matchLabels:
|
|
|
|
|
app: mysql-zabbix
|
|
|
|
|
template:
|
|
|
|
|
metadata:
|
|
|
|
|
labels:
|
|
|
|
|
app: mysql-zabbix
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- name: mysql-zabbix
|
|
|
|
|
image: mysql:8.0.30
|
|
|
|
|
ports:
|
|
|
|
|
- containerPort: 3306
|
|
|
|
|
env:
|
|
|
|
|
- name: TZ
|
|
|
|
|
value: Asia/Shanghai
|
|
|
|
|
- name: MYSQL_ROOT_PASSWORD
|
|
|
|
|
value: '123456'
|
|
|
|
|
- name: MYSQL_DATABASE
|
|
|
|
|
value: zabbix
|
|
|
|
|
- name: MYSQL_USER
|
|
|
|
|
value: zabbix
|
|
|
|
|
- name: MYSQL_PASSWORD
|
|
|
|
|
value: '123456'
|
|
|
|
|
volumeMounts:
|
|
|
|
|
- mountPath: /var/lib/mysql
|
|
|
|
|
name: mysql-zabbix
|
|
|
|
|
- mountPath: /etc/mysql/conf.d
|
|
|
|
|
name: conf-volume
|
|
|
|
|
readOnly: true
|
|
|
|
|
volumes:
|
|
|
|
|
- name: mysql-zabbix
|
|
|
|
|
nfs:
|
|
|
|
|
path: /data/mysql_zabbix
|
|
|
|
|
server: 10.9.12.250
|
|
|
|
|
- name: conf-volume
|
|
|
|
|
configMap:
|
|
|
|
|
name: mysql-config-zabbix
|
|
|
|
|
---
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Service
|
|
|
|
|
metadata:
|
|
|
|
|
name: zabbix-service
|
|
|
|
|
spec:
|
|
|
|
|
selector:
|
|
|
|
|
app: mysql-zabbix
|
|
|
|
|
type: NodePort
|
|
|
|
|
ports:
|
|
|
|
|
- port: 3306
|
|
|
|
|
targetPort: 3306
|
|
|
|
|
nodePort: 30140
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 3.安装zabbix-agent
|
|
|
|
|
|
|
|
|
|
略
|
|
|
|
|
|
|
|
|
|
注意:修改配置文件,关联zabbix-server
|
|
|
|
|
|
|
|
|
|
#### 4.创建主机群组
|
|
|
|
|
|
|
|
|
|
略
|
|
|
|
|
|
|
|
|
|
注意:群组名为kubernetes
|
|
|
|
|
|
|
|
|
|
#### 5.创建监控项模板
|
|
|
|
|
|
|
|
|
|
注意:采用自定义key的方式,对应的脚本和配置文件如下(zabbix-agent端)
|
|
|
|
|
|
|
|
|
|
信息采集脚本:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
#disk io monitor index
|
|
|
|
|
|
|
|
|
|
#tps 每秒传输次数 它表示每秒磁盘完成的读写操作次数。磁盘的 TPS 越高,意味着磁盘的读写能力越强
|
|
|
|
|
|
|
|
|
|
disk_tps=`iostat | grep vda | awk '{print $2}'`
|
|
|
|
|
|
|
|
|
|
#kB_read/s 是衡量磁盘读取速度的指标,表示每秒从磁盘读取的数据量
|
|
|
|
|
|
|
|
|
|
disk_read=`iostat | grep vda | awk '{print $3}'`
|
|
|
|
|
|
|
|
|
|
#kB_wrtn/s 是指磁盘的写入速度,表示每秒向磁盘写入的数据量
|
|
|
|
|
|
|
|
|
|
disk_write=`iostat | grep vda | awk '{print $4}'`
|
|
|
|
|
|
|
|
|
|
#kB_dscd/s 是指磁盘每秒从缓存中被丢弃的数据量
|
|
|
|
|
|
|
|
|
|
disk_dscd=`iostat | grep vda | awk '{print $5}'`
|
|
|
|
|
|
|
|
|
|
#kB_read 表示从磁盘读取的总数据量
|
|
|
|
|
|
|
|
|
|
disk_read_kb=`iostat | grep vda | awk '{print $6}'`
|
|
|
|
|
|
|
|
|
|
#kB_wrtn 表示自系统启动以来从磁盘写入的总数据量
|
|
|
|
|
|
|
|
|
|
disk_write_kb=`iostat | grep vda | awk '{print $7}'`
|
|
|
|
|
|
|
|
|
|
echo -e "disk_tps=$disk_tps
|
|
|
|
|
disk_read=$disk_read
|
|
|
|
|
disk_write=$disk_write
|
|
|
|
|
disk_dscd=$disk_dscd
|
|
|
|
|
disk_kb_read=$disk_read_kb
|
|
|
|
|
disk_kb_write=$disk_write_kb"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
配置文件关联采集脚本:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
UserParameter=disk.io[*],bash /etc/zabbix/disk_io.sh | awk -F "=" '/^$1/{print $$2}'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
重启服务,配置生效
|
|
|
|
|
|
|
|
|
|
![image-20231117114912697](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117114912697.png)
|
|
|
|
|
|
|
|
|
|
#### 6.创建主机
|
|
|
|
|
|
|
|
|
|
注意:采用自动发现,配置自动发现规则,设置动作直接添加主机,关联主机群组和模板
|
|
|
|
|
|
|
|
|
|
![image-20231117115009292](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117115009292.png)
|
|
|
|
|
|
|
|
|
|
## 三:Grafana配置
|
|
|
|
|
|
|
|
|
|
#### 1.安装Grafana
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud-grafana ~]# yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-10.2.1-1.x86_64.rpm
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 2.运行Grafana
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud-grafana ~]# systemctl start grafana-server
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 3.浏览器访问
|
|
|
|
|
|
|
|
|
|
注意:默认端口:3000 配置文件:/etc/grafana/grafana.ini 默认用户:admin 默认密码:admin
|
|
|
|
|
|
|
|
|
|
![image-20231117115752524](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117115752524.png)
|
|
|
|
|
|
|
|
|
|
#### 4.添加数据源插件
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud-grafana ~]# grafana-cli plugins install alexanderzobnin-zabbix-app
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
插件地址:https://grafana.com/grafana/plugins/all-plugins/?search=za
|
|
|
|
|
|
|
|
|
|
重启服务使插件生效
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud-grafana ~]# systemctl restart grafana-server
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Grafana-Web界面启用插件
|
|
|
|
|
|
|
|
|
|
![image-20231117143105075](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143105075.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117143124634](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143124634.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117143215517](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143215517.png)
|
|
|
|
|
|
|
|
|
|
## 四:Grafana集成Zabbix
|
|
|
|
|
|
|
|
|
|
#### 1.添加数据源
|
|
|
|
|
|
|
|
|
|
![image-20231117143328453](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143328453.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117143407615](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143407615.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117143431283](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143431283.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117143630084](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143630084.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117143707099](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143707099.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117143733033](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143733033.png)
|
|
|
|
|
|
|
|
|
|
#### 2.数据图形化分析
|
|
|
|
|
|
|
|
|
|
创建仪表盘
|
|
|
|
|
|
|
|
|
|
![image-20231117143853435](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143853435.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117143915451](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143915451.png)
|
|
|
|
|
|
|
|
|
|
添加可视化
|
|
|
|
|
|
|
|
|
|
![image-20231117143933663](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143933663.png)
|
|
|
|
|
|
|
|
|
|
关联数据源
|
|
|
|
|
|
|
|
|
|
![image-20231117143957395](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117143957395.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117144133698](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117144133698.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117144311514](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117144311514.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117144336855](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117144336855.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117144400009](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117144400009.png)
|
|
|
|
|
|
|
|
|
|
![image-20231117144621604](https://diandiange.oss-cn-beijing.aliyuncs.com/image-20231117144621604.png)
|