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
重新編譯完成後,整個世界清靜了,問題完美解決!
原文鏈接
http://mp.weixin.qq.com/s?__biz=MzA5NjgwNzM0OQ==&mid=401336090&idx=1&sn=ef5735cba4fb2ef0a9b8eab92cc473c0#rd