1

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.

Ps. As recommended I asked the same question on Liferay forums: https://liferay.dev/ask#/questions/portal/liferay-7-3-on-docker-with-elasticsearch-connection-refused

Wunsz
  • 165
  • 3
  • 7
  • As this is a rather configuration related question, rather than programming related (see [help/on-topic]), consider moving it to the liferay forums, where it's on topic – Olaf Kock Nov 16 '20 at 05:41
  • As you recommended I asked on the forums though it's awaiting moderation. Adding link here: https://liferay.dev/ask#/questions/portal/liferay-7-3-on-docker-with-elasticsearch-connection-refused – Wunsz Nov 16 '20 at 08:13

1 Answers1

0

I had same problem. I solve it:

useful link: https://learn.liferay.com/dxp/latest/en/using-search/installing-and-upgrading-a-search-engine/elasticsearch/exercise-run-liferay-and-elasticsearch-using-docker.html

your db configs is OK.

docker-compose.yml:

liferay:
        image: liferay/portal:7.3.7-ga8
        container_name: liferay
        user: '1000'
        networks: 
            - mynetwork
        volumes: 
            - ./liferay/data:/opt/liferay/data
            - ./liferay/deploy:/opt/liferay/deploy
            - ./liferay/conf/portal-ext.properties:/opt/liferay/portal-ext.properties
            # - ./liferay/conf/osgi/configs:/opt/liferay/osgi/configs
            - type: bind
              source: ./liferay/conf/osgi/configs
              target: /opt/liferay/osgi/configs
            # - ./liferay/conf/osgi/modules/*.jar:/home/liferay/osgi/modules
            # - ./liferay/conf/tomcat/bin/setenv.sh:/home/liferay/tomcat/bin/setenv.sh
            # - ./liferay/conf/tomcat/lib/ext/*.jar:/home/liferay/tomcat/lib/ext
            # - ./liferay/conf/tomcat/conf/context.xml:/home/liferay/tomcat/conf
        depends_on: 
            - db
            - elasticsearch

    elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0
        container_name: elasticsearch
        volumes:
            - type: bind
              source: ./elasticsearch/config/elasticsearch.yml
              target: /usr/share/elasticsearch/config/elasticsearch.yml
              read_only: true
            - ./elasticsearch/data:/usr/share/elasticsearch/data
            - ./elasticsearch/plugins:/plugins
        ports:
            - "9200:9200"
            - "9300:9300"
        environment:
            ES_JAVA_OPTS: "-Xmx256m -Xms256m"
            ELASTIC_PASSWORD: 'YOUR-ES-PASSWORD'
            # Use single node discovery in order to disable production mode and avoid bootstrap checks.
            # see: https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
            discovery.type: single-node
            ingest.geoip.downloader.enabled: 'false'
        networks:
            - mynetwork
        deploy:
            resources:
                limits:
                    memory: 2G

elasticsearch.yml:

cluster.name: "LiferayElasticsearchCluster"
node.name: elasticsearch
network.host: 0.0.0.0
ingest.geoip.downloader.enabled: false  # optional
xpack.security.enabled: false

lifray_container: /opt/liferay/osgi/configs/com.liferay.portal.search.elasticsearch7.configuration.ElasticsearchConfiguration.config :

additionalConfigurations = ""
additionalIndexConfigurations = ""
additionalTypeMappings = ""
authenticationEnabled = B"true"
bootstrapMlockAll = B"false"
clusterName = "LiferayElasticsearchCluster"
discoveryZenPingUnicastHostsPort = "9300-9400"
embeddedHttpPort = I"9201"
httpCORSAllowOrigin = "/https?:\\/\\/localhost(:[0-9]+)?/"
httpCORSConfigurations = ""
httpCORSEnabled = B"true"
httpSSLEnabled = B"false"
indexNamePrefix = "liferay-"
indexNumberOfReplicas = ""
indexNumberOfShards = ""
logExceptionsOnly = B"true"
networkBindHost = ""
networkHost = ""
networkHostAddresses = [\
  "http://elasticsearch:9200"\  #place you can enter your elastic server addresses
]
networkPublishHost = ""
nodeName = ""
operationMode = "REMOTE"
overrideTypeMappings = ""
password = "YOUR-ES-PASSWORD"
productionModeEnabled = B"true"
proxyHost = ""
proxyPort = I"0"
proxyUserName = ""
remoteClusterConnectionId = ""
restClientLoggerLevel = "ERROR"
sidecarDebug = B"false"
sidecarDebugSettings = "-agentlib:jdwp\=transport\=dt_socket,address\=8001,server\=y,suspend\=y,quiet\=y"
sidecarHeartbeatInterval = L"10000"
sidecarHome = "elasticsearch7"
sidecarHttpPort = ""
sidecarJVMOptions = [\
  "-Xms1g",\
  "-Xmx1g",\
  "-XX:+AlwaysPreTouch"\
]
sidecarShutdownTimeout = L"10000"
trackTotalHits = B"true"
transportTcpPort = ""
truststorePath = "/path/to/localhost.p12"
truststoreType = "pkcs12"
username = "elastic"

before run liferay, please run elastic container and run this command:

docker-compose exec -it elasticsearch bash -c '/usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu && /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-kuromoji && /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-smartcn && /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-stempel'

also you can create custom image that installs automatically those plugins on image.

I hope this codes help you. (sorry for my terrible English)