0

Getting error like - Could not validate a connection to Elasticsearch. No alive nodes found in your cluster

I am using docker for magento 2.4.1 while installation i am getting this error.

My docker-compose.yml.

 version: '3'
 services:
 nginx:
 build:
 args:
 nginx_port: 80
 nginx_version: ${NGINX_VERSION}
 context: ./docker/nginx
 depends_on:
 - php-fpm
 restart: always
 volumes:
 - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:cached
 - ./src/magento:/var/www/magento:cached
 php-fpm:
 build:
 args:
 php_version: ${PHP_VERSION}
 context: ./docker/php-fpm
 env_file:
 - .env
 depends_on:
 - cron
 - elasticsearch
 - mysql
 - rabbitmq
 - redis-fpc
 - redis-obj
 - redis-ses
 restart: always
 volumes:
 - ./src/magento:/var/www/magento:cached
 - ./config/composer/auth.json:/var/www/.composer/auth.json:cached
 - ./config/php/php.ini:/usr/local/etc/php/php.ini:cached
 cron:
 build:
 args:
 php_version: ${PHP_VERSION}
 context: ./docker/cron
 restart: always
 volumes:
 - ./src/magento:/var/www/magento:cached
 mysql:
 environment:
 - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
 - MYSQL_USER=${MYSQL_USER}
 - MYSQL_PASSWORD=${MYSQL_PASSWORD}
 - MYSQL_DATABASE=${MYSQL_DATABASE}
 image: percona:${MYSQL_VERSION}
 ports:
 - "3306:3306"
 restart: always
 volumes:
 - mysql-log:/var/log/mysql
 - mysql-lib:/var/lib/mysql
 redis-obj:
 image: redis:${REDIS_VERSION}
 ports:
 - "6379:6379"
 restart: always
 redis-fpc:
 command: redis-server /usr/local/etc/redis/redis.conf
 image: redis:${REDIS_VERSION}
 ports:
 - "6380:6380"
 restart: always
 volumes:
 - ./config/redis/fpc.conf:/usr/local/etc/redis/redis.conf
 redis-ses:
 command: redis-server /usr/local/etc/redis/redis.conf
 image: redis:${REDIS_VERSION}
 ports:
 - "6381:6381"
 restart: always
 volumes:
 - ./config/redis/ses.conf:/usr/local/etc/redis/redis.conf
 elasticsearch:
 image: elasticsearch:${ELASTICSEARCH_VERSION}
 environment:
 - ELASTICSEARCH_URL=http://elasticsearch:9200
 - "ES_JAVA_OPTS=-Xmx2g -Xms2g"
 - bootstrap.memory_lock=true
 - http.cors.enabled=true
 - http.cors.allow-origin=*
 - cluster.name=adlp-cluster
 - discovery.type=single-node
 ulimits:
 memlock:
 soft: -1
 hard: -1
 volumes:
 - data01:/usr/share/elasticsearch/data
 ports:
 - 9200:9200
 networks:
 - elastic
 #healthcheck:
 # test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
 # interval: 30s
 # timeout: 30s
 # retries: 3
 restart: always
 rabbitmq:
 image: rabbitmq:${RABBITMQ_VERSION}-management
 ports:
 - "5672:5672"
 - "15672:15672"
 restart: always
 volumes:
 mysql-log:
 mysql-lib:
 data01:
 driver: local
 networks:
 elastic:
 driver: bridge
 
 /*******************My .env file *********************************/
 
 # Versions
 NGINX_VERSION=1.18
 PHP_VERSION=7.4
 MAGENTO_VERSION=2.4
 MYSQL_VERSION=8.0
 REDIS_VERSION=6
 ELASTICSEARCH_VERSION=7.6.2
 RABBITMQ_VERSION=3.8.9
 
 # MySQL
 MYSQL_ROOT_PASSWORD=magento
 MYSQL_USER=magento
 MYSQL_PASSWORD=magento
 MYSQL_DATABASE=magento
 
 # Magento (required) - see https://devdocs.magento.com/guides/v2.2/install-gde/install/cli/install-cli-install.html
 MAGENTO_ADMIN_FIRSTNAME=Magento
 MAGENTO_ADMIN_LASTNAME=Development
 [email protected]
 MAGENTO_ADMIN_USER=dev
 MAGENTO_ADMIN_PASSWORD=password1
 
 # Magento (optional)
 MAGENTO_BASE_URL=http://m2.local.docker.com/
 MAGENTO_BACKEND_FRONTNAME=admin
 MAGENTO_DB_HOST=mysql
 MAGENTO_DB_NAME=magento
 MAGENTO_DB_USER=magento
 MAGENTO_DB_PASSWORD=magento
 # MAGENTO_DB_PREFIX
 MAGENTO_LANGUAGE=en_US
 MAGENTO_CURRENCY=USD
 MAGENTO_TIMEZONE=America/New_York
 MAGENTO_USE_REWRITES=1
 MAGENTO_USE_SECURE=1
 MAGENTO_BASE_URL_SECURE=https://m2.local.docker.com/
 MAGENTO_USE_SECURE_ADMIN=1
 # MAGENTO_ADMIN_USE_SECURITY_KEY
 # MAGENTO_SESSION_SAVE
 # MAGENTO_KEY
 # MAGENTO_CLEANUP_DATABASE
 # MAGENTO_DB_INIT_STATEMENTS
 # MAGENTO_SALES_ORDER_INCREMENT_PREFIX
 
 # Magento (optional, Magento Commerce only)
 # MAGENTO_AMQP_HOST
 # MAGENTO_AMQP_PORT
 # MAGENTO_AMQP_USER
 # MAGENTO_AMQP_PASSWORD
 # MAGENTO_AMQP_VIRTUALPORT
 # MAGENTO_AMQP_SSL
 
 # Magento (optional, Redis)
 MAGENTO_REDIS_OBJ_SERVER=redis-obj
 MAGENTO_REDIS_OBJ_PORT=6379
 MAGENTO_REDIS_OBJ_DATABASE=0
 #MAGENTO_REDIS_OBJ_PASSWORD
 #MAGENTO_REDIS_FPC_SERVER=redis-fpc
 #MAGENTO_REDIS_FPC_PORT=6380
 #MAGENTO_REDIS_FPC_DATABASE=0
 #MAGENTO_REDIS_FPC_PASSWORD
 #MAGENTO_REDIS_FPC_COMPRESS_DATA=1
 MAGENTO_REDIS_SES_SERVER=redis-ses
 MAGENTO_REDIS_SES_PORT=6381
 MAGENTO_REDIS_SES_DATABASE=0
 #MAGENTO_REDIS_SES_PASSWORD
 #MAGENTO_REDIS_SES_TIMEOUT
 #MAGENTO_REDIS_SES_PERSISTENT_ID
 #MAGENTO_REDIS_SES_COMPRESSION_THRESHOLD
 #MAGENTO_REDIS_SES_COMPRESSION_LIB
 #MAGENTO_REDIS_SES_LOG_LEVEL
 #MAGENTO_REDIS_SES_MAX_CONCURRENCY
 #MAGENTO_REDIS_SES_BREAK_AFTER_FRONTEND
 #MAGENTO_REDIS_SES_BREAK_AFTER_ADMINHTML
 #MAGENTO_REDIS_SES_FIRST_LIFETIME
 #MAGENTO_REDIS_SES_BOT_LIFETIME
 #MAGENTO_REDIS_SES_DISABLE_LOCKING
 #MAGENTO_REDIS_SES_MIN_LIFETIME
 #MAGENTO_REDIS_SES_MAX_LIFETIME
# Magento (optional, Varnish)
VCL_CONFIG=/data/varnish.vcl

MY installation command.

sudo docker exec -it 47fc7052a3fa php bin/magento setup:install --base-url=https://m2.docker.com --base-url-secure=https://m2.docker.com --db-host=mysql --db-name=magento --db-user=magento --db-password=magento --backend-frontname=admin --admin-firstname=Magento --admin-lastname=Admin [email protected] --admin-user=admin --admin-password=admin@123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --elasticsearch-host=localhost:9200 --elasticsearch-port=9200 

Here is curl test output.

curl -X GET "localhost:9200/_cat/nodes?v&pretty"
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.24.0.2 22 93 2 0.78 1.13 1.39 dilm * c6c5a3e48cfe

Any help will be appreciated.

asked Dec 1, 2020 at 19:01
1
  • Hi, how did you fix this? I get the same error while building on the server. Commented Jul 22, 2021 at 15:31

4 Answers 4

1

After building up your container update host url for elasticsearch. Type following command from CLI

bin/magento config:set catalog/search/elasticsearch7_server_hostname elasticsearch

By default, elasticsearch host url is localhost

answered Jan 14, 2022 at 16:04
1
  • ooo man struggling on this for like more than an hour although tried changing this same value in the database manually but don't know why it didn't worked now its working Commented Apr 7, 2022 at 18:49
0

In your .env file the elasticsearch host is http://elasticsearch:9200 while in your install-command elasticsearch host is set to localhost. Change the elasticsearch host in your Magento Configuration (Backend) to http://elasticsearch.

answered Dec 1, 2020 at 22:44
0

In my case Elasticsearch wa installed via brew (Mac) on Host.

And for access from Docker used Elasticsearch host - like host.docker.internal http://host.docker.internal

just try in Docker cli

curl -X GET "http://host.docker.internal:9200/_cat/nodes?v&pretty"

answered Jan 9, 2022 at 16:29
0

Make sure 'catalog/search/elasticsearch7_server_hostname' is set with proper hostname in core_config_data of db table.

For local magento I have set the value to 'localhost'. Please check screenshot for more clarification - https://i.sstatic.net/lynIX.png

answered Jan 19, 2023 at 8:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.