4

I am running ElasticSearch6 in my docker files.

if i run http://localhost:9200/ in my browser i get this information.

{
"name" : "shakedeal-1",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "X4OkctATTgmlcdLzmtJ4Yg",
  "version" : {
    "number" : "6.5.4",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "d2ef93d",
    "build_date" : "2018-12-17T21:17:40.758843Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

Here are the contents of my docker/elasticSearch/config/elasticSearch.yml file.

---
## Default Elasticsearch configuration from elasticsearch-docker.
## from https://github.com/elastic/elasticsearch-docker/blob/master/build/elasticsearch/elasticsearch.yml
#
cluster.name: "docker-cluster"
node.name: "shakedeal-1"
network.host: 0.0.0.0

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1

## 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

Now if i install my magento2 using CLI command.

php bin/magento setup:install --base-url='http://tile500.co.pk/' \
--db-host='mysql' --db-name='Tile500New' --db-user='root' --db-password='tiger' \
--admin-firstname='Magento' --admin-lastname='User' --admin-email='sanaullahAhmad@gmail.com' \
--admin-user='admin' --admin-password='admin123' --language='en_US' \
--currency='USD' --timezone='America/Chicago' --use-rewrites=1 \
--search-engine='elasticsearch6' --elasticsearch-host='localhost' \
--elasticsearch-port='9200' 

I get this error

[Progress: 601 / 1206]
Installing search configuration...

In SearchConfig.php line 81:
                                                                                          
  Could not validate a connection to Elasticsearch. No alive nodes found in your cluster  
2
  • 1
    if you are running elastic search in a seperate container then localhost is the wrong hostname, you need to use the hostname of the ES container. – paj Aug 21 '20 at 14:38
  • Yes, thank you very much. Its worked. I change the setup: install option to --elasticsearch-host='es1:9200' and it worked for me. – Sanaullah Ahmad Aug 21 '20 at 14:50
10

I encountered this problem which is really tiring when installing a new Magento 2.4.

I think you have already found the solution but I wanted to share the solution for others.


In SearchConfig.php line 81: Could not validate a connection to Elasticsearch. No alive nodes found in your cluster


This error means that either you don't have Elasticsearch installed in your system or the host configuration which is not correct.

  1. check if Elasticsearch is installed :

    with example :

    sudo systemctl status elasticsearch
    
    //or
    
    curl -X GET 'http://localhost:9200'
    
    //or
    
    curl -X GET 'http://yourdomaine:9200'
    
  2. if you find that Elasticsearch is installed, you go directly to step 4, otherwise you go to step 3 then 4

  3. Elasticsearch installation : Reference

    3.1 We must have OpenJDK to make work Elasticsearch

    sudo apt install openjdk-11-jdk -y
    

    3.2 import the Elasticsearch public GPG key

    curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
    

    3.3 add the Elasticsearch source to the sources.list.d directory, where apt will search for new sources

    sudo echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
    

    3.4 update the packages to read the Elastic source

    sudo apt update
    

    3.5 install Elasticsearch

    sudo apt install elasticsearch -y
    

    3.6 we configure Elasticsearch host

    sudo nano /etc/elasticsearch/elasticsearch.yml
    

    uncomment and replace #network.host: 192.168.0.1 with network.host: localhost

     # ---------------------------------- Network -----------------------------------
     #
     # Set the bind address to a specific IP (IPv4 or IPv6):
     #
     #network.host: 192.168.0.1 //<- **** uncomment this line then replace it with : network.host: localhost
     #
     # Set a custom port for HTTP:
     #
     #http.port: 9200
     #
     # For more information, consult the network module documentation.
    

    3.7 We start Elasticsearch

     sudo systemctl start elasticsearch
     sudo systemctl enable elasticsearch
    

    3.8 We check the status

     sudo systemctl status elasticsearch
    
     //result : 
    
     //systemd[1]: Starting Elasticsearch...
    

    3.9 Working Elastic

     curl -X GET 'localhost:9200' 
    
     //Result something like : 
     {
       "name" : "wbfdfrbz",
       "cluster_name" : "elasticsearch",
       "cluster_uuid" : "_MpzR9k23l-Vy5vzlSQW",
       "version" : {
         "number" : "7.9.0",
         "build_flavor" : "default",
         "build_type" : "deb",
         "build_hash" : "a179a2a7fwq032d6g9361301700902wff217",
         "build_date" : "2020-08-11T21:36:48.204330Z",
         "build_snapshot" : false,
         "lucene_version" : "8.6.0",
         "minimum_wire_compatibility_version" : "6.8.0",
         "minimum_index_compatibility_version" : "6.0.0-beta1"
       },
      "tagline" : "You Know, for Search"
     }
    

 

  1. Magento command installation

    In step 3.6, we set the HOST value with : localhost (network.host: localhost) so we will set the same thing for --elasticsearch-host='localhost' and --elasticsearch-port=9200, we have keep the default port 9200 (#http.port: 9200).

    So an example for the Magento CLI installation :

    php bin/magento setup:install --base-url="http://yourdomaine.com/" --base-url-secure="http://yourdomaine.com/" --backend-frontname="admin" --session-save="files" --db-host="localhost" --db-name="your-db-name" --db-user="your-db-user" --db-password="your-db-password" --admin-firstname="Amir" --admin-lastname="Admin" --admin-email="amir@domaine.com" --admin-user="amir" --admin-password="Admin123" --language=fr_FR --currency=EUR --timezone=Europe/Paris --use-rewrites=1 --search-engine=elasticsearch7 --elasticsearch-host="localhost" --elasticsearch-port=9200
    

Enjoy !

1
  • What is the expected result from CURL if elasticsearch is installed?? I get 401 Authorization required. And why do we need curl, why not just entering the URL in the browser? – Black Dec 16 '20 at 9:14
2

You can refer to how to install the latest magento 2.4 here https://vi-magento.com/cai-dat-magento-2-4-voi-nginx-apache-php-7-3-va-mysql-thong-qua-composer-tren-ubuntu

0

I solved this problem with @paj solution given in comment to this question.

if you are running elastic search in a seperate container then localhost is the wrong hostname, you need to use the hostname of the ES container.

So checked my Docker container. enter image description here

As you can see my docker container name for elastic search is "es1", so i changed my Magento2 install command to

--elasticsearch-host='es1:9200'

and it worked for me.

it was --elasticsearch-host='localhost' before and was not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.