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

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="[email protected]" --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 !


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

Tags:

Magento2