Zabbix错误提示MySQL server has gone away解决

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

Zabbix错误提示MySQL server has gone away解决

相信细心的同学在使用Zabbix的过程中,会遇到[Z3005] query failed: [2006] MySQL server has gone away 这个错误提示,虽然出现错误提示,但实际并不会影响Zabbix Server的正常使用。那么,这个问题能不能解决呢?本文将带你彻底解决此问题的出现。

    欢迎关注OneOaaS 微信公众号,获得更多Zabbix相关知识和运维知识。

1

错误现象

22773:20160108:172513.801 [Z3005] query failed: [2006] MySQL server has gone away [select hostid,key_,state,filter,error,lifetime from items where itemid=34993]

22968:20160108:172517.815 [Z3005] query failed: [2006] MySQL server has gone away [select hostid,key_,state,filter,error,lifetime from items where itemid=32057]

2

分析

如果你之前没有遇到这个问题,第一想到的应该是去网上搜索,MySQL出现 [2006] MySQL server has gone away,根据网络搜索的结果,会得出以下解决办法:

#vim /etc/my.cnf

max_allowed_packet=300M

wait_timeout=200000

interactive_timeout = 200000

然后重启MySQL,经过测试,该方法无果而终,问题依旧。

3

解决办法

继续寻找解决办法,在Zabbix的JIRA里面看到此问题为Zabbix Server的BUG,已在2.5中解决,但对于2.5以下版本,该bug没有修复。

解决办法如下


#vim src/libs/zbxdb/db.c

int    zbx_db_connect(char *host, char *user, char *password, char *dbname, char *dbschema, char *dbsocket, int port)

{
     
int   ret = ZBX_DB_OK, last_txn_error, last_txn_level;
#if defined(HAVE_IBM_DB2)
     
char           *connect = NULL;
#elif defined(HAVE_MYSQL)
       my_bool         mysql_reconnect = 1
;                                                                                  
#elif defined(HAVE_ORACLE)
     
char   *connect = NULL;
     
sword err = OCI_SUCCESS;




#elif defined(HAVE_MYSQL)
    conn = mysql_init(NULL);

    if (NULL == mysql_real_connect(conn, host, user, password, dbname, port, dbsocket, CLIENT_MULTI_STATEMENTS))
    {
            zabbix_errlog(ERR_Z3001, dbname, mysql_errno(conn), mysql_error(conn));
            ret = ZBX_DB_FAIL;

}


    if (0 != mysql_options(conn, MYSQL_OPT_RECONNECT, &mysql_reconnect))
             zabbix_log(LOG_LEVEL_WARNING, "Cannot set MySQL reconnect option.");

                                                             
    if (ZBX_DB_OK == ret && 0 != mysql_select_db(conn, dbname))
    {
            zabbix_errlog(ERR_Z3001, dbname, mysql_errno(conn), mysql_error(conn));
            ret = ZBX_DB_FAIL;

}

注意红色字体的代码

./configure --host=x86_64-redhat-linux-gnu --build=x86_64-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/sha

re --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-dependency-tracking --enable-server --enable-proxy --enable-java --enable-agent --enable-ipv6 --with-net-snmp --with-libcurl --with-openipmi --with-unixodbc --with-ldap --with-ssh2 --with-libcurl --with-libxml2 --sysconfdir=/etc/zabbix --datadir=/var/lib --enable-server --with-mysql



重新编译完成后,整个世界清静了,问题完美解决!




本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1733492,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
4月前
|
SQL 关系型数据库 MySQL
MySQL Server 层四个日志
MySQL Server 层四个日志
68 0
MySQL Server 层四个日志
|
4月前
|
SQL 关系型数据库 MySQL
使用Flink CDC从SQL Server同步数据到MySQL
使用Flink CDC从SQL Server同步数据到MySQL
156 1
|
10天前
|
关系型数据库 MySQL Linux
Linux联网安装MySQL Server
Linux联网安装MySQL Server
22 0
|
2月前
|
关系型数据库 MySQL 数据库
Host 'XXX' is not allowed to connect to this MySQL server 解决方案
Host 'XXX' is not allowed to connect to this MySQL server 解决方案
|
3月前
|
关系型数据库 MySQL 数据库
Client does not support authentication protocol requested by server; consider upgrading MySQL client
Client does not support authentication protocol requested by server; consider upgrading MySQL client
|
4月前
|
关系型数据库 MySQL 数据库
远程连接mysql报错:1130 - Host XXX is not allowed to connect to this MySQL server
远程连接mysql报错:1130 - Host XXX is not allowed to connect to this MySQL server
84 0
|
4月前
|
关系型数据库 MySQL 数据安全/隐私保护
(解决)Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
(解决)Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
39 0
|
4月前
|
关系型数据库 MySQL Linux
MySQL【部署 01】Linux root 用户部署 mysql-5.7.28 及 not allowed to connect to this MySQL server 和中文乱码问题处理
MySQL【部署 01】Linux root 用户部署 mysql-5.7.28 及 not allowed to connect to this MySQL server 和中文乱码问题处理
51 0
|
4月前
|
SQL Oracle 关系型数据库
选择适合您网站的 SQL 托管:MS SQL Server、Oracle、MySQL 和 MS Ac
如果您希望您的网站能够存储和检索数据,您的Web服务器应该能够访问使用SQL语言的数据库系统。以下是一些常见的SQL托管选项:
51 1
|
4月前
|
SQL Oracle 关系型数据库
浅谈对数据库(MySQL、Oracle、SQL Server)的认识
浅谈对数据库(MySQL、Oracle、SQL Server)的认识

推荐镜像

更多