2015-12-24 34 views
8

語境安裝在服務器彈性搜索,但如果從另一臺計算機無法連接到它

有剛上local machine(server)開始使用elastic search,它安裝在服務器上,可以curltelnetport 9200但如果從無法連接到它另一臺機器。

我的服務器和客戶端上禁用防火牆作爲解決方案,我從互聯網上得到了提示,並也嘗試下面的鏈接中找到的建議,但無法得到它的工作。

https://discuss.elastic.co/t/accessing-port-9200-remotely/21840

問題

有人能幫助我如何得到這個工作,在此先感謝

回答

13

既然你剛剛安裝Elasticsearch,我想你正在使用ES 2.0 2.1。你要知道,自從2.0版本,Elasticsearch binds to localhost by default(作爲安全措施,以防止您的節點無法連接到其他節點在網絡上而不讓你知道)。

所以,你需要做的僅僅是編輯您的elasticsearch.yml配置文件並更改network.bind_host設置是這樣的:

network.bind_host: 0 

然後,您需要重新啓動您的節點,這將是從遠程主機訪問。

+0

@scott_lotus其作品,也有人曾經誰需要這個解決方案應該記住從elasticsearch.yml中刪除#(取消正在修改的配置)例如「#network.host:xxx.xx.xx.xxx」爲「network.host:xxx.xx.xx.xxx」 –

5

讓我們重新創建的場景。我開始在我的機器上安裝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" 
} 
+0

已經解決 –

+0

Som我們需要在編輯配置後重新啓動SSH連接(例如PuTTY) –

+0

感謝您對問題的詳細解釋,+1 –

1

嘗試wget命令對於ElasticSearch 5版本,可以編輯配置文件/etc/elasticsearch/elasticsearch.yml並添加以下行需要像插件

network.bind_host: 0 
http.cors.allow-origin: "*" 
http.cors.enabled: true 

的CORS Head或HQ在遠程機器上,因爲他們使Ajax XMLHttpRequest請求

您也可以定義network.host: 0,因爲它是一個快捷方式,其設置bind_host和publish_host

來源:

相關問題