RE: RE: Liferay 7.3 on Docker with Elasticsearch - Connection refused

Bartosz Jabłoński, modified 4 Years ago. New Member Posts: 2 Join Date: 11/16/20 Recent Posts

I have a problem with Liferay + Elasticsearch setup with docker-compose. When starting the compose bundle Liferay complains that it cannot connect to remote elasticsearch instance with exception:

 2020-11-15 21:39:55.042 ERROR [main][ElasticsearchEngineConfigurator:93] bundle com.liferay.portal.search.elasticsearch7.impl:2.0.30 (655)[com.liferay.portal.search.elasticsearch7.internal.ElasticsearchEngineConfigurator(1604)] : The activate method has thrown an exception 
 java.lang.RuntimeException: java.net.ConnectException: Connection refused
  at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.cluster.HealthClusterRequestExecutorImpl.getClusterHealthResponse(HealthClusterRequestExecutorImpl.java:102)
  at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.cluster.HealthClusterRequestExecutorImpl.execute(HealthClusterRequestExecutorImpl.java:49)
  at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.cluster.ElasticsearchClusterRequestExecutor.executeClusterRequest(ElasticsearchClusterRequestExecutor.java:51)
  at com.liferay.portal.search.engine.adapter.cluster.HealthClusterRequest.accept(HealthClusterRequest.java:40)
  at com.liferay.portal.search.engine.adapter.cluster.HealthClusterRequest.accept(HealthClusterRequest.java:22)
  at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.cluster.ElasticsearchClusterRequestExecutor.execute(ElasticsearchClusterRequestExecutor.java:44)
  at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.ElasticsearchSearchEngineAdapterImpl.execute(ElasticsearchSearchEngineAdapterImpl.java:69)
  at com.liferay.portal.search.elasticsearch7.internal.ElasticsearchSearchEngine.waitForYellowStatus(ElasticsearchSearchEngine.java:334)
  at com.liferay.portal.search.elasticsearch7.internal.ElasticsearchSearchEngine.initialize(ElasticsearchSearchEngine.java:109)
  at com.liferay.portal.kernel.search.SearchEngineProxyWrapper.initialize(SearchEngineProxyWrapper.java:59)
  at com.liferay.portal.search.elasticsearch7.internal.BaseSearchEngineConfigurator.setSearchEngine(BaseSearchEngineConfigurator.java:500)
  at com.liferay.portal.search.elasticsearch7.internal.BaseSearchEngineConfigurator.initSearchEngine(BaseSearchEngineConfigurator.java:407)
  at com.liferay.portal.search.elasticsearch7.internal.BaseSearchEngineConfigurator.initialize(BaseSearchEngineConfigurator.java:341)
  at com.liferay.portal.search.elasticsearch7.internal.ElasticsearchEngineConfigurator.activate(ElasticsearchEngineConfigurator.java:52)
    # Loong stack trace with Casued by "java.net.ConnectException: Connection refused"


At the same time I can connect via curl to the machines and they respond:
 

liferay@a4b06641f395 /opt/liferay 
$ curl es-node-1:9200
{
  "name" : "es-node-1",
  "cluster_name" : "docker-elasticsearch",
  "cluster_uuid" : "iUW--n_ORe-zv40sBzUdpQ",
  "version" : {
    "number" : "7.9.3",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "c4138e51121ef06a6404866cddc601906fe5c868",
    "build_date" : "2020-10-16T10:36:16.141335Z",
    "build_snapshot" : false,
    "lucene_version" : "8.6.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

liferay@a4b06641f395 /opt/liferay 
$ curl es-node-1:9300
curl: (1) Received HTTP/0.9 when not allowed

I have following `docker-compose.yml` file:
 

version: '3.2'

services:
  web:
    image: liferay/portal:7.3.4-ga5
    ports:
      - "3002:8080"
    depends_on:
      - appdb
      - liferaydb
      - es-node-1
      - es-node-2
    environment:
      LIFERAY_LIFERAY_PERIOD_HOME: /opt/liferay
      LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_DRIVER_UPPERCASEC_LASS_UPPERCASEN_AME: com.mysql.cj.jdbc.Driver
      LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_USERNAME: user
      LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_URL: jdbc:mysql://liferaydb/liferay_db?useFastDateParsing=false
      LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_PASSWORD: user_pass
      LIFERAY_PASSWORDS_PERIOD_ENCRYPTION_PERIOD_ALGORITHM_PERIOD_LEGACY: SHA
      LIFERAY_WEB_PERIOD_SERVER_PERIOD_HTTP_PERIOD_PORT: 8080
      LIFERAY_WEB_PERIOD_SERVER_PERIOD_PROTOCOL: http
      LIFERAY_WEB_PERIOD_SERVER_PERIOD_HOST: liferay.dev
      LIFERAY_LIVE_PERIOD_USERS_PERIOD_ENABLED: 1
    volumes:
      - ${PWD}/static/portal-ext.properties:/opt/liferay/portal-ext.properties
      - ${PWD}/deploy:/opt/liferay/deploy
      - ${PWD}/data/VAADIN:/opt/liferay/tomcat/webapps/ROOT/html/VAADIN
      - ${PWD}/static/ElasticsearchConfiguration.config:/opt/liferay/osgi/configs/com.liferay.portal.search.elasticsearch7.configuration.ElasticsearchConfiguration.config

  appdb:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root_pass
      MYSQL_DATABASE: portlet_db
      MYSQL_USER: user
      MYSQL_PASSWORD: user_pass
    volumes:
      - ${PWD}/data/appdb:/var/lib/mysql

  liferaydb:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root_pass
      MYSQL_DATABASE: liferay_db
      MYSQL_USER: user
      MYSQL_PASSWORD: user_pass
    volumes:
      - ${PWD}/data/liferaydb:/var/lib/mysql

  es-node-1:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
    environment:
      - node.name=es-node-1
      - cluster.name=docker-elasticsearch
      - bootstrap.memory_lock=true
      - discovery.seed_hosts=es-node-2
      - cluster.initial_master_nodes=es-node-1,es-node-2
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    deploy:
      resources:
        limits:
          memory: 1g
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200

  es-node-2:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
    environment:
      - node.name=es-node-2
      - cluster.name=docker-elasticsearch
      - bootstrap.memory_lock=true
      - discovery.seed_hosts=es-node-1
      - cluster.initial_master_nodes=es-node-1,es-node-2
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata2:/usr/share/elasticsearch/data

volumes:
  esdata1:
  esdata2:

Contents of `portal-ext.properties` define data source for my portlet:
 

jdbc.ext.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.ext.url=jdbc:mysql://appdb:3306/portlet_db
jdbc.ext.username=user
jdbc.ext.password=user_pass

Contents of `ElasticsearchConfiguration.config` define connection to Elastic:
 

operationMode=REMOTE
transportAddresses=["es-node-1:9300","es-node-2:9300"]
clusterName=docker-elasticsearch
logExceptionsOnly=true

Does anybody have any idea what is wrong? I tried with and without quotes in the `.config` file but I doesn't seem to work.

Rafał Pydyniak, modified 4 Years ago. New Member Posts: 16 Join Date: 6/24/20 Recent Posts

Hello,

has anyone found a solution for that? I have the same issue on Liferay DXP 7.3 GA1

Best regards

Bartosz Jabłoński, modified 4 Years ago. New Member Posts: 2 Join Date: 11/16/20 Recent Posts

What I eventually did is I switched to elastic 6 and it worked...

I don't know if that solution is applicable for you. Funny enough - the documentation states that it is compatible with elastic 7...

thumbnail
Sergio Sanchez, modified 4 Years ago. Regular Member Posts: 149 Join Date: 7/6/11 Recent Posts

Hi, you should be using port 9200 and not 9300 in your connector config ( com.liferay.portal.search.elasticsearch7.configuration.ElasticsearchConfiguration.config file)

Since Liferay Portal/DXP 7.3 the connector uses the HTTP connection.

Hope it helps

Rafał Pydyniak, modified 4 Years ago. New Member Posts: 16 Join Date: 6/24/20 Recent Posts

Hello,

thanks for the answer! Is the property the same? Sadly there is no docs for 7.3 for this and also I can't see anything in breaking changes.
Below is my .config file:

operationMode="REMOTE"
transportAddresses="elasticsearch:9200"
clusterName="elasticsearch

And sadly it does not work

thumbnail
Russell Bohl, modified 4 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

I believe the first thing you need to do is read the docs: Liferay and Elasticsearch

 

Specifically, in Connecting to Elasticsearch, you'll see that 7.3 uses the HTTP connection, whereeas you have configured the transport connection. In addition, wile configuring operationMode will still work, you might as well use the non-deprecated replacement for it, productionModeEnabled:

A simple 7.3 connector configuration enables production mode ( productionModeEnabled="true") and sets the URL to each Elasticsearch node ( networkHostAddresses=["http://es-node:9200"]).

Rafał Pydyniak, modified 4 Years ago. New Member Posts: 16 Join Date: 6/24/20 Recent Posts

Hello,

thanks! I couldn't find that - I could only find the documentation for 7.2 (https://help.liferay.com/hc/en-us/articles/360029031671-Configuring-the-Liferay-Elasticsearch-Connector). It indeed seems to be working now

Best regards