Ubuntu本地无法启动Kibana:Service Unavailable错误排查与解决
问题背景
我在Ubuntu系统上部署了Elasticsearch 6.6,确认9200端口运行正常,还通过以下命令成功导入了测试数据:
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/product/default/_bulk?pretty" --data-binary "@test-data.json"
但启动同版本的Kibana时,控制台却抛出了一堆连接错误:
error [06:27:47.587] [warning][process] Service Unavailable :: {"path":"/_cluster/settings","query":{"include_defaults":true},"statusCode":503,"response":" 503 Service Unavailable \nNo server is available to handle this request.\n\n\n"}
at respond (/home/svaibhav/Downloads/kibana-6.6.0-linux-x86_64/node_modules/elasticsearch/src/lib/transport.js:308:15)
at checkRespForFailure (/home/svaibhav/Downloads/kibana-6.6.0-linux-x86_64/node_modules/elasticsearch/src/lib/transport.js:267:7)
at HttpConnector. (/home/svaibhav/Downloads/kibana-6.6.0-linux-x86_64/node_modules/elasticsearch/src/lib/connectors/http.js:165:7)
at IncomingMessage.wrapper (/home/svaibhav/Downloads/kibana-6.6.0-linux-x86_64/node_modules/elasticsearch/node_modules/lodash/lodash.js:4935:19)
at IncomingMessage.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
log [06:27:48.009] [warning][admin][elasticsearch] Unable to revive connection: http://localhost:9200/
log [06:27:48.009] [warning][admin][elasticsearch] No living connections
排查与解决过程
一开始以为是Elasticsearch没启动或者权限问题,但测试9200端口的API是正常的,这就很奇怪。后来查端口占用情况才发现:9200端口同时有两个服务在监听,一个是IPv4的TCP连接,另一个是IPv6的TCP连接。
而Elasticsearch实际是绑定在IPv6的9200端口上运行,但Kibana默认会优先尝试连接IPv4的9200端口,这就导致了连接失败,抛出503错误。
找到问题根源后,我修改了Elasticsearch的配置文件elasticsearch.yml,将http.port从默认的9200改成了未被占用的9201,然后重启Elasticsearch和Kibana,问题就完全解决了。
内容的提问来源于stack exchange,提问作者Vaibhav

