上下文
刚开始使用elastic search
,安装在服务器上,可以curl
和telnet
开port 9200
,local machine(server)
但如果从另一台机器无法连接到它.
我在服务器和客户端都禁用了防火墙,因为我从互联网上获得的解决方案正在建议并尝试在下面的链接中找到的建议,但无法使其正常工作.
https://discuss.elastic.co/t/accessing-port-9200-remotely/21840
题
有人可以帮助我如何使这项工作,提前感谢
由于您刚安装了Elasticsearch,我想您使用的是ES 2.0或2.1.您需要知道,自2.0发布以来,Elasticsearch 默认绑定到localhost(作为一种安全措施,以防止您的节点在不知情的情况下连接到网络上的其他节点).
所以你需要做的只是编辑elasticsearch.yml
配置文件并更改network.bind_host
设置如下:
network.bind_host: 0
然后,您需要重新启动节点,并且可以从远程主机访问它.
让我们重新创建你的场景.我在我的机器上开始新安装的elasticsearch.现在我能够在端口9200上执行curl
[root@kali ~]# hostname -i 192.168.109.128 [root@kali ~]# 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" }
如果检查服务器上的侦听tcp端口是否已打开java服务.
[root@kali ~]# 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配置以解决问题
[root@kali ~]# 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服务
[root@kali ~]# service elasticsearch restart Restarting elasticsearch (via systemctl): [ OK ] Now lets check the listening tcp port of java [root@kali ~]# netstat -ntlp | awk '/[j]ava/' tcp6 0 0 :::9200 :::* LISTEN 3759/java tcp6 0 0 :::9300 :::* LISTEN 3759/java
现在你可以在所有界面上进行监听.
让我们从远程机器尝试wget命令
$ 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" }