讓我們重新創建的場景。我開始在我的機器上安裝elasticsearch。現在我能夠在端口9200
[[email protected] ~]# hostname -i
192.168.109.128
[[email protected] ~]# curl http://localhost:9200
{
"status" : 200,
"name" : "Kali Node",
"cluster_name" : "kali",
"version" : {
"number" : "1.7.1",
"build_hash" : "b88f43fc40b0bcd7f173a1f9ee2e97816de80b19",
"build_timestamp" : "2015-07-29T09:54:16Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"
}
執行卷曲如果您檢查Java服務已開通你的服務器上的監聽TCP端口。
[[email protected] ~]# netstat -ntlp | awk '/[j]ava/'
tcp6 0 0 127.0.0.1:9200 :::* LISTEN 3422/java
tcp6 0 0 127.0.0.1:9300 :::* LISTEN 3422/java
你可以看到elasticsearch正在監聽127.0.0.1所以很明顯,你不能從網絡訪問端口9200。我們使用來自遠程服務器的wget來驗證它。
$ wget.exe 192.168.109.128:9200
--2015-12-25 13:30:18-- http://192.168.109.128:9200/
Connecting to 192.168.109.128:9200... failed: Connection refused.
讓改變elasticsearch配置使用以下命令
[[email protected] ~]# sed -i '/^network.bind_host:/s/network.bind_host: .*/network.bind_host: 0.0.0.0/' /etc/elasticsearch/elasticsearch.yml
或
只需打開elasticsearch配置文件來解決該問題,並找到「network.bind_host」和下面做以下更改
network.bind_host: 0.0.0.0
然後重新啓動您的elasticsearch服務
[[email protected] ~]# service elasticsearch restart
Restarting elasticsearch (via systemctl): [ OK ]
Now lets check the listening tcp port of java
[[email protected] ~]# netstat -ntlp | awk '/[j]ava/'
tcp6 0 0 :::9200 :::* LISTEN 3759/java
tcp6 0 0 :::9300 :::* LISTEN 3759/java
現在您可以在所有界面上監聽。
允許用戶從遠程機器
$ wget.exe 192.168.109.128:9200
--2015-12-25 13:39:12-- http://192.168.109.128:9200/
Connecting to 192.168.109.128:9200... connected.
HTTP request sent, awaiting response... 200 OK
Length: 328 [application/json]
Saving to: ‘index.html.1’
index.html.1 100%[====================================================>] 328 --.-KB/s in 0.009s
2015-12-25 13:39:12 (37.1 KB/s) - ‘index.html.1’ saved [328/328]
Try curl command
$ curl.exe http://192.168.109.128:9200
{
"status" : 200,
"name" : "Kali Node",
"cluster_name" : "kali",
"version" : {
"number" : "1.7.1",
"build_hash" : "b88f43fc40b0bcd7f173a1f9ee2e97816de80b19",
"build_timestamp" : "2015-07-29T09:54:16Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"
}
@scott_lotus其作品,也有人曾經誰需要這個解決方案應該記住從elasticsearch.yml中刪除#(取消正在修改的配置)例如「#network.host:xxx.xx.xx.xxx」爲「network.host:xxx.xx.xx.xxx」 –