![](/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.