logstash-output-jdbc遇到connection is not available,request time out after 10000ms的问题解决

上一篇logstash-output-jdbc使用中提到“运行bin/logstash -f test.conf时可能提示注册插件失败”,通过分析详细的错误日志,发现其赫然写着“connection is not available,request time out after 10000ms”,原来是mysql连接的问题,插件注册失败只是表象。

由于没有在logstash所在的机器A安装mysql,而是通过mysql connector 的jar包(logstash conf文件里指定了jar报路径),所以没有办法测试A到数据库机器B的连接是否成功,尝试过增加mysql connection_timeout的时间到300s,发现错误还是request time out after 10000ms,说明jar里有自己的时间设置。

百度良久,最后在mysql的my.ini文件(默认C:\PragramData\MySQL\MySQLServer 5.7目录下)中增加skip-name-resolve,重启mysql服务后,问题解决。原因是

MySQL处理用户连接时进行如下过程来验证用户的合法性(参考http://www.cnblogs.com/timeship/archive/2013/02/28/2937730.html):

When a new client connects to mysqld, mysqld spawns a new thread to handle the request. This thread first checks whether the host name is in the host name cache. If not, the thread attempts to resolve the host name: 
The thread takes the IP address and resolves it to a host name (using gethostbyaddr()). It then takes that host name and resolves it back to the IP address (using gethostbyname()) and compares to ensure it is the original IP address.
posted @ 2017-04-07 11:49  ttssrs  阅读(4382)  评论(0编辑  收藏  举报