上下文
刚刚开始使用elastic search
,已将其安装在服务器上,curl
和telnet
可以port 9200
local machine(server)
,但如果是另一个,则无法连接到class MailOccurence {
private final Mail mail;
private final Long recurrence;
public MailOccurence(final Mail mail, final Long recurrence) {
this.mail = mail;
this.recurrence = recurrence;
}
public Mail getMail() { return mail; }
public Long getRecurrence() { return recurrence; }
}
机。
我在服务器和客户端都禁用了防火墙,因为我从互联网上获得的解决方案正在建议并尝试了以下链接中找到的建议,但无法使其正常工作。
https://discuss.elastic.co/t/accessing-port-9200-remotely/21840
问题
有人可以帮助我如何使这项工作,提前谢谢
答案 0 :(得分:15)
由于您刚刚安装了Elasticsearch,我想您使用的是ES 2.0或2.1。您需要知道自2.0版本以来,Elasticsearch binds to localhost by default(作为一种安全措施,可以防止您的节点在不知情的情况下连接到网络上的其他节点)。
所以您需要做的只是编辑elasticsearch.yml
配置文件并更改network.bind_host
设置,如下所示:
network.bind_host: 0
然后,您需要重新启动节点,并且可以从远程主机访问它。
答案 1 :(得分:6)
让我们重新创建你的场景。我在我的机器上开始新安装的elasticsearch。现在我能够在端口9200
上执行curlSystem.Collections.Generic.List<TravelingAdmin.Controllers.Detail>
如果检查服务器上的侦听tcp端口是否已打开java服务。
[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"
}
您可以看到elasticsearch正在侦听 127.0.0.1 ,因此很明显您无法从网络访问端口9200。让我们使用来自远程服务器的wget验证它。
[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配置以解决问题
$ 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配置文件,然后找到&#34; network.bind_host &#34;并在下面进行以下更改
[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: 0.0.0.0
现在你可以在所有界面上进行监听。
让我们从远程机器
尝试wget命令[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
答案 2 :(得分:2)
对于ElasticSearch版本5,您可以编辑配置文件/etc/elasticsearch/elasticsearch.yml
并添加以下行
network.bind_host: 0
http.cors.allow-origin: "*"
http.cors.enabled: true
远程计算机上的Head或HQ等插件需要cors,因为它们会产生Ajax XMLHttpRequest请求
您还可以定义network.host: 0
,因为它是设置bind_host和publish_host的快捷方式
来源:
答案 3 :(得分:0)
我遇到了同样的问题,这对我有用:
在/etc/elasticsearch/elasticsearch.yml
中:
在/etc/kibana/kibana.yml
中:
在您的nginx文件/etc/nginx/sites-available/yoursite.com
server {
listen 80;
server_name 192.168.1.50;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users;
location / {
proxy_pass http://192.168.1.50:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
systemctl restart elasticsearch
systemctl restart kibana
systemctl restart nginx
netstat -nltp
现在应该看起来像: 192.168.1.50:5061 192.168.1.50:9200
telnet 192.168.1.50 9200