![](/img/trans.png)
[英]JHipster Elasticsearch with Amazon Elasticsearch Service
[英]Elasticsearch and jhipster
我正在将jhipster生成的应用程序与MySQL数据库一起使用。 我的应用程序已在Ubuntu 18.04上使用nginx部署在tomcat上(使用mvnw软件包-Pprod生成的.war文件)。 为了部署,我使用了.war.orig文件。
在Ubuntu服务器上,我已按照此处的指南中的说明安装了elasticsearch(我使用的是Elasticsearch版本6.3): https ://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch- 于Ubuntu 16-04
/etc/elasticsearch/elasticsearch.yml文件如下所示:
network.host: localhost
http.port: 9200
在application-prod.yml中,我具有以下elasticsearch配置:
data:
elasticsearch:
cluster-name:
cluster-nodes: localhost:9200
当我在tomcat上部署应用程序时,会发生以下错误:
2018-06-17 22:58:49.675 ERROR 28733 --- [1-8080-exec-161] o.z.p.spring.web.advice.AdviceTrait : Internal Server Error
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{localhost}{127.0.0.1:9300}]
该应用程序正在运行,但是对后端的每个请求(登录除外)都会导致内部服务器错误500。
命令curl -X GET 'http://localhost:9200'
提供了正确的返回值。
我有没有配置错误?
你可以试试这个吗?
data:
elasticsearch:
cluster-name: <cluster_name>
cluster-nodes: <usually it is same as cluster name, default qSea>
properties:
host: <ip address>
user: <username:password>
port: 9300
enableSsl: false
path:
logs: target/elasticsearch/log
data: target/elasticsearch/data
另外,我猜您正在通过传输层进行通信。 您可以使用以下方法构建传输客户端(如果未安装x-pack,则可以对其进行更改):
private static TransportClient buildTransPortClient() {
String host = "<IP Address>";
int port = 9300; // port is 9300 not 9200
Settings settings = Settings.builder().put("client.transport.nodes_sampler_interval", "5s")
.put("client.transport.sniff", false).put("transport.tcp.compress", true).put("cluster.name", "<cluster_name>")
.put("xpack.security.transport.ssl.enabled", false).put("request.headers.X-Found-Cluster", "<cluster_name>")
.put("xpack.security.user", "<user_name and password. by default it is elastic:changeme (of course if you have installed x-pack)>").build();
TransportClient client = null;
try {
client = new PreBuiltXPackTransportClient(settings);
for (InetAddress address : InetAddress.getAllByName(host)) {
if ((address instanceof Inet6Address) || (address instanceof Inet4Address)) {
client.addTransportAddress(new InetSocketTransportAddress(address, port));
}
}
} catch (UnknownHostException e) {
System.out.println("Unable to get the host" + e.getMessage());
} catch (Exception e) {
System.out.println("exception aaya hai");
e.printStackTrace();
}
return client;
}
然后可以测试。 如果此方法有效,则您的jhipster应用程序可与Elasticsearch正常运行。
在尝试了多种解决方案之后,我终于放弃了。
事实证明,最快(也是唯一可行的)解决方案是通过docker-compose -f src/main/docker/elasticsearch.yml up
来设置docker-compose -f src/main/docker/elasticsearch.yml up
(当然,您也可以为此购买专用解决方案,想要避免)。
我上面发布的内容仍然是application-prod.yml配置。
仅供参考:请记住在设置elasticsearch之后重新创建数据库并重新部署应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.