1.引言

1.1目的

zabbix+grafana实现图形化监控

2.部署环境

服务器ip服务版本
192.168.5.137zabbix-server6.0.21
192.168.5.137grafana10.2.2
192.168.5.152zabbix-client6.0.21

3.部署zabbix-server

3.1 创建zabbix目录

mkdir zabbix

3.2 编写docker-compose文件

cd zabbixvim docker-compose.yamlversion: '3'services:mysql:image: mysql:8.0container_name: mysqlvolumes:- ./mysql/data:/var/lib/mysql- ./mysql/conf:/etc/mysql/conf.d- ./mysql/logs:/var/log/mysql- /etc/localtime:/etc/localtimerestart: alwaysprivileged: trueenvironment:- MYSQL_ROOT_PASSWORD=myrootpass- MYSQL_DATABASE=zabbix- MYSQL_USER=zabbix- MYSQL_PASSWORD=mypass- TZ=Asia/Shanghai- LANG=en_US.UTF-8expose:- "3306"networks:zabbix-net:command: --character-set-server=utf8 --collation-server=utf8_binzabbix-gateway:image: zabbix/zabbix-java-gateway:6.0-centos-latestcontainer_name: zabbix-gatewayvolumes:- /etc/localtime:/etc/localtimerestart: alwaysprivileged: trueports:- "10052:10052"networks:zabbix-net:zabbix-snmptraps:image: zabbix/zabbix-snmptraps:6.0-centos-latestcontainer_name: zabbix-snmptrapsvolumes:- /etc/localtime:/etc/localtime- ./snmptraps:/var/lib/zabbix/snmptraps- ./mibs:/var/lib/zabbix/mibsrestart: alwaysprivileged: trueports:- "1162:1162/udp"networks:zabbix-net:zabbix-server:image: zabbix/zabbix-server-mysql:6.0-centos-latestcontainer_name: zabbix-servervolumes:- /etc/localtime:/etc/localtime- ./snmptraps:/var/lib/zabbix/snmptraps- ./mibs:/var/lib/zabbix/mibs- ./alertscripts:/usr/lib/zabbix/alertscripts- ./externalscripts:/usr/lib/zabbix/externalscriptsrestart: alwaysprivileged: trueenvironment:- ZBX_LISTENPORT=10051- DB_SERVER_HOST=mysql- DB_SERVER_PORT=3306- MYSQL_DATABASE=zabbix- MYSQL_USER=zabbix- MYSQL_PASSWORD=mypass- MYSQL_ROOT_PASSWORD=myrootpass- ZBX_CACHESIZE=1G- ZBX_HISTORYCACHESIZE=512M- ZBX_HISTORYINDEXCACHESIZE=16M- ZBX_TRENDCACHESIZE=256M- ZBX_VALUECACHESIZE=256M- ZBX_STARTPINGERS=64- ZBX_IPMIPOLLERS=1- ZBX_ENABLE_SNMP_TRAPS=true- ZBX_STARTTRAPPERS=1- ZBX_JAVAGATEWAY_ENABLE=true- ZBX_JAVAGATEWAY=zabbix-gateway- ZBX_STARTJAVAPOLLERS=1ports:- "10051:10051"networks:zabbix-net:links:- mysql- zabbix-gatewayzabbix-web:image: zabbix/zabbix-web-nginx-mysql:6.0-centos-latestcontainer_name: zabbix-webvolumes:- ./font/simfang.ttf:/usr/share/zabbix/assets/fonts/DejaVuSans.ttf- /etc/localtime:/etc/localtimerestart: alwaysprivileged: trueenvironment:- ZBX_SERVER_NAME=Zabbix 6.0- ZBX_SERVER_HOST=zabbix-server- ZBX_SERVER_PORT=10051- DB_SERVER_HOST=mysql- DB_SERVER_PORT=3306- MYSQL_DATABASE=zabbix- MYSQL_USER=zabbix- MYSQL_PASSWORD=mypass- MYSQL_ROOT_PASSWORD=myrootpass- PHP_TZ=Asia/Shanghaiports:- "80:8080"networks:zabbix-net:links:- mysql- zabbix-servernetworks:zabbix-net:driver: bridgeipam:config:- subnet: 10.10.10.0/24gateway: 10.10.10.1

3.3 启动zabbix容器

docker-compose -f docker-compose.yaml up –d

3.4 查看zabbix容器

docker ps

3.5 访问zabbix的web页面

url:http://192.168.5.137:80

4.部署grafana

4.1创建grafana目录

mkdir grafana

4.2 编写grafana.yaml文件

cd grafanavim grafana.yamlversion: '3.9'services:grafana:image: grafana/grafanacontainer_name: grafanaports:- "3000:3000"environment:- TZ=Asia/Shanghainetworks:- grafanavolumes:- ./grafana:/var/lib/grafananetworks:grafana:driver: bridge

4.3启动grafana容器

docker-compose -f grafana.yaml up –d

4.4 安装grafana的zabbix数据源

进入grafana容器docker exec -it grafana bash安装zabbix数据源grafana cli plugins install alexanderzobnin-zabbix-app查看是否安装成功grafana cli plugins ls重启grafana容器docker restart grafana

4.5 访问grafana的web页面

url:http://192.168.5.137:3000

5.部署zabbix-client

5.1 创建zabbix目录

mkdir zabbix

5.2 编写zabbix.yaml文件

cd zabbixvim zabbix.yamlversion: '3'services:zabbix-agent:image: zabbix/zabbix-agent:latestenvironment:- ZBX_SERVER_HOST=192.168.5.137- ZBX_HOSTNAME=testvolumes:- ./agentd/zabbix_agentd.conf:/etc/zabbix/zabbix_agentd.confports:- "10050:10050"

5.3 启动zabbix客户端

docker-compose -f zabbix.yaml up –d

6.添加zabbix监控

6.1 添加zabbix客户端ip

6.2 监控zabbix客户端CPU

6.3添加cpu触发器

6.4 添加图形化界面

6.5 查看监控到的数据

7.配置grafana

7.1 添加zabbix插件


7.2搜索添加zabbix数据源


7.3 添加zabbix服务端信息



7.4 开启zabbix模板

7.5 添加zabbix监控数据




至此zabbix+grafana部署完成。