×

扫描二维码登录本站

QQ登录

只需一步,快速开始

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


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





上一篇:Grafana加Zabbix--部署分布式监控系统
下一篇:用户体验来谈Zabbix与监控宝的差异和互补
monicazhang

写了 2297 篇文章,拥有财富 12859,被 21 人关注

您需要登录后才可以回帖 登录 | 立即注册
B Color Link Quote Code Smilies

成为第一个吐槽的人

手机版|小黑屋|最新100贴|论坛版块|ITIL先锋论坛 |粤ICP备11099876号|网站地图
Powered by Discuz! X3.4 Licensed  © 2001-2017 Comsenz Inc.
返回顶部