zabbix安装
安装
init.sh1 2 3 4 5 6 7 8 9 10 11
| # 安装软件仓库 rpm -Uvh https://repo.zabbix.com/zabbix/5.2/rhel/8/x86_64/zabbix-release-5.2-1.el8.noarch.rpm # 这是代理 (非必要) export https_proxy=http://10.10.103.241:7890 http_proxy=http://10.10.103.241:7890 all_proxy=socks5://10.10.103.241:7890 # 安装服务 (服务端) dnf install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-agent -y # 安装服务 (客户端) dnf install zabbix-agent -y # 开启远程访问 setsebool -P httpd_can_network_connect_db on setsebool -P httpd_can_connect_zabbix on
|
导入Sql文件
1 2
| cd /usr/share/doc/zabbix-server-mysql/ zcat create.sql.gz > create.sql
|
开启Web
1 2
| cd /etc/nginx/conf.d/ vim zabbix.conf
|
配置&启动
初始化配置
访问 http://ip
按照步骤来
这里踩了两次坑,一次是开启数据库远程访问 setsebool -P httpd_can_network_connect_db on
, 一次是不兼容 MySQL 8.0
中文字体处理
在图表部分,中文显示方块,为字体兼容问题,替换字体即可.
小米温馨提示,很多教程使用 雅黑 作为替换字体,还望悉知,雅黑 、 平方 等字体存在版权问题。因此本米替换上去的是 思源黑体
- 下载 下载字体 约488.5MB 内含多种字体、字重自行选择
- 上传 上传并覆盖
/usr/share/zabbix/assets/fonts/graphfont.ttf
MsSQL监控
数据库监控在日常是经常使用的,因此单独放出来给大家参考
MySQL脚本
提取数据的脚本
docker
/etc/zabbix/script/docker_mysql_status.sh1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #!/bin/bash #Desc:zabbix 监控 MySQL 状态 #Date:2020-11-23 #by:AirMs DOCKER_NAME="mysql-dev" #主机 HOST="10.10.101.231" #用户 USER="root" #密码 PASSWORD="root" #端口 PORT="3306" #MySQL连接 CONNECTION="-h ${HOST} -u ${USER} -P ${PORT} -p${PASSWORD}"
if [ $# -ne "1" ];then echo "arg error!" fi
case $1 in Uptime) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} status 2>/dev/null| grep -w "Uptime" |awk '{print $2}'` echo $result ;; Questions) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} status 2>/dev/null| grep -w "Uptime" |awk '{print $6}'` echo $result ;; Com_update) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Com_update" |awk '{print $4}'` echo $result ;; Slow_queries) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Slow_queries" |awk '{print $4}'` echo $result ;; Com_select) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Com_select" |awk '{print $4}'` echo $result ;; Com_rollback) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Com_rollback" |awk '{print $4}'` echo $result ;; Com_insert) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Com_insert" |awk '{print $4}'` echo $result ;; Com_delete) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Com_delete" |awk '{print $4}'` echo $result ;; Com_commit) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Com_commit" |awk '{print $4}'` echo $result ;; Bytes_sent) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Bytes_sent" |awk '{print $4}'` echo $result ;; Bytes_received) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Bytes_received" |awk '{print $4}'` echo $result ;; Com_begin) result=`docker exec -it ${DOCKER_NAME} /usr/bin/mysqladmin ${CONNECTION} extended-status 2>/dev/null |grep -w "Com_begin" |awk '{print $4}'` echo $result ;;*) echo "Usage:$0(Uptime|Questions|Com_update|Slow_queries|Com_select|Com_rollback|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)" ;; esac
|
host
/etc/zabbix/script/mysql_status.sh1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #!/bin/bash #Desc:zabbix 监控 MySQL 状态 #Date:2019-5-6 #by:Lee-YJ
#主机 HOST="10.10.101.210" #用户 USER="root" #密码 PASSWORD="root" #端口 PORT="3306" #MySQL连接 CONNECTION="mysqladmin -h ${HOST} -u ${USER} -P ${PORT} -p ${PASSWORD}"
if [ $# -ne "1" ];then echo "arg error!" fi
case $1 in Uptime) result=`${CONNECTION} status 2>/dev/null |awk '{print $2}'` echo $result ;; Questions) result=`${CONNECTION} status 2>/dev/null |awk '{print $6}'` echo $result ;; Com_update) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_update" |awk '{print $4}'` echo $result ;; Slow_queries) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Slow_queries" |awk '{print $4}'` echo $result ;; Com_select) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_select" |awk '{print $4}'` echo $result ;; Com_rollback) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_rollback" |awk '{print $4}'` echo $result ;; Com_insert) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_insert" |awk '{print $4}'` echo $result ;; Com_delete) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_delete" |awk '{print $4}'` echo $result ;; Com_commit) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_commit" |awk '{print $4}'` echo $result ;; Bytes_sent) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Bytes_sent" |awk '{print $4}'` echo $result ;; Bytes_received) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Bytes_received" |awk '{print $4}'` echo $result ;; Com_begin) result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_begin" |awk '{print $4}'` echo $result ;;*) echo "Usage:$0(Uptime|Questions|Com_update|Slow_queries|Com_select|Com_rollback|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)" ;; esac
|
Zabbix-Agent 脚本
/etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf1 2 3 4 5 6
| #获取MySQL性能指标,这个是上一步编辑好的脚本 UserParameter=mysql.status[*],/etc/zabbix/script/docker_mysql_status.sh $1 #获取MySQL运行状态 UserParameter=mysql.ping,mysqladmin -u zabbix -h 10.10.101.211 -p zabbix ping 2>/dev/null | grep -c alive #获取MySQL版本 UserParameter=mysql.version,mysql -V
|
配置
执行添加监控项目和图表配置