【问题标题】:Elasticsearch and jhipsterElasticsearch 和 jhipster
【发布时间】:2018-11-26 19:46:29
【问题描述】:

我正在使用 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-on-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' 命令给出了正确的返回值。

我是否配置错误?

【问题讨论】:

  • 你使用的是什么版本的 JHipster?要使用的正确 Elasticsearch 版本取决于 spring-data-elasticsearch 库。在 JHipster v4 中,它是 2.x

标签: java spring spring-boot elasticsearch jhipster


【解决方案1】:

在尝试了多种解决方案后,我终于放弃了。

事实证明,最快(也可能是唯一可行的)解决方案是通过 docker-compose -f src/main/docker/elasticsearch.yml up 设置弹性搜索(当然您也可以为此购买专用解决方案,我想避免这样做)。

application-prod.yml 配置与我在上面发布的一样。

仅供参考:记得在设置 elasticsearch 后重新创建数据库并重新部署应用程序。

【讨论】:

    【解决方案2】:

    你可以试试这个:

    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 配合使用。

    【讨论】:

    • 我应该指定集群名称还是可以像在默认配置中一样将其留空?
    猜你喜欢
    • 2016-04-13
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    相关资源
    最近更新 更多