Magento 2.4.0 - Getting Error Could not validate a connection to Elasticsearch. No alive nodes found in your cluster

magento.stackexchange https://magento.stackexchange.com/questions/318939

  •  14-04-2021
  •  | 
  •  

Question

I am getting below error while installing Magento 2.4.0 using command line.

Could not validate a connection to Elasticsearch. No alive nodes found in your cluster

enter image description here

I have run below two commands.

composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento240

php -dmemory_limit=-1 bin/magento setup:install --base-url="http://127.0.0.1/magento240" --db-host="localhost" --db-name="magento240" --db-user="root" --db-password="root123" --admin-firstname="admin" --admin-lastname="admin" --admin-email="admin@admin.com" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin"

Also used below commands.

php -dmemory_limit=-1 bin/magento setup:install --base-url="http://127.0.0.1/magento240" --db-host="localhost" --db-name="magento240" --db-user="root" --db-password="root123" --admin-firstname="admin" --admin-lastname="admin" --admin-email="admin@admin.com" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --search-engine=mysql

php -dmemory_limit=-1 bin/magento setup:install --base-url="http://127.0.0.1/magento240" --db-host="localhost" --db-name="magento240" --db-user="root" --db-password="root123" --admin-firstname="admin" --admin-lastname="admin" --admin-email="admin@admin.com" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --elasticsearch-host=elasticsearch --elasticsearch-username=elastic --elasticsearch-password=changeme

Thank you.

Was it helpful?

Solution 3

I have installed Elasticsearch in my Linux Mint & It's working fine. Here is the steps.

Run the below command to Install Elasticsearch In locally.

Download and install the public signing key :

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

Installing from the APT repositoryedit

You may need to install the apt-transport-https package on Debian before proceeding :

sudo apt-get install apt-transport-https

Save the repository definition to /etc/apt/sources.list.d/elastic-7.x.list :

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

You can install the Elasticsearch Debian package with :

sudo apt-get update && sudo apt-get install elasticsearch

Elasticsearch is not started automatically after installation. How to start and stop Elasticsearch depends on whether your system uses SysV init or systemd (used by newer distributions).

ps -p 1

Running Elasticsearch with SysV init : Use the update-rc.d command to configure Elasticsearch to start automatically when the system boots up :

sudo update-rc.d elasticsearch defaults 95 10

Elasticsearch can be started and stopped using the service command :

sudo -i service elasticsearch start

sudo -i service elasticsearch stop

Configure Apache and Elasticsearch : Set up a proxy (Set up a proxy for Apache 2.4)

Enable mod_proxy as follows :

a2enmod proxy_http or sudo a2enmod proxy_http

Use a text editor to open /etc/apache2/sites-available/000-default.conf

Add the following directive at the top of the file :

Listen 8080

Add the following at the bottom of the file :

<VirtualHost *:8080>
    ProxyPass "/" "http://localhost:9200/"
    ProxyPassReverse "/" "http://localhost:9200/"
</VirtualHost>

Restart Apache :

service apache2 restart or sudo service apache2 restart

Verify the proxy works by entering the following command :

For example, if your proxy uses port 8080:

curl -i http://localhost:8080/_cluster/health

If curl request success then messages display like below :

HTTP/1.1 200 OK
Date: Sun, 23 Aug 2020 06:05:56 GMT
Server: Apache/2.4.18 (Ubuntu)
content-type: application/json; charset=UTF-8
content-length: 389

{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":1,"active_shards":1,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":1,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_percent_as_number":50.0}

Go to Admin Panel -> Stores -> Settings -> Configuration -> Catalog -> Catalog Search. Change the settings like below.

Search Engine : Search Engine7

Elasticsearch Server Hostname : localhost

Elasticsearch Server Port : 8080

Elasticsearch Index Prefix : magento2

Enable Elasticsearch HTTP Auth : No

Elasticsearch Server Timeout : 15

Now save the configuration & run below cache clean command.

php bin/magento cache:clean

Now click on Test Connection button.

After successful you will receive Successful! Test again? in Test Connection button.

Ref : Dev Docs & Elasticsearch

For More Click here

OTHER TIPS

I upgraded my Magento 2.3.5 into 2.4.0 and now facing this error, very annoying to say the least,... I fixed it by disabling the Elastic Search module... injecting this into a Magento "update" is totally un-called for, very frustrating and annoying.

After disabling these, my php /bin/magento setup:upgrade works fine now:

php bin/magento module:disable {Magento_Elasticsearch,Magento_InventoryElasticsearch,Magento_Elasticsearch6,Magento_Elasticsearch7}

I thought upgrading into 2.4.0 would make life better, I can't believe there are so many problems just to get into 2.4.0.... don't know what I am walking into, ... I hope my installation that I am about to deploy does not break as a result of so many unwanted modules added into the 2.4.0 update before even trying it yet!...

The issue is the ElasticSearch config in your command.

To start the verification, you can run this curl command below to validate your ElasticSearch, you can change the host elasticsearch to your host.

curl elasticsearch:9200

These are the issues in your commands:

1º - Don't specify the ElasticSearch host

2º - It's using MySQL which is not supported

3º - It seems to be a generic configuration and not the right one, as your password is changeme

Try this command below.

php -d memory_limit=-1 bin/magento setup:install \
--base-url="http://127.0.0.1/magento240" \
--db-host="127.0.0.1" \
--db-name="magento240" \
--db-user="root" \
--db-password="root123" \
--admin-firstname="admin"  \
--admin-lastname="admin"  \
--admin-email="admin@admin.com"  \
--admin-user="admin"  \
--admin-password="admin123"  \
--language="en_US"  \
--currency="USD"  \
--timezone="America/Chicago"  \
--use-rewrites="1"  \
--backend-frontname="admin"  \
--elasticsearch-host=elasticsearch

Run this command

php bin/magento config:set catalog/search/engine '' -f

Or

Remove Value From Database

SELECT * FROM `core_config_data` WHERE `path` LIKE 'catalog/search/engine'
  1. this is not a solution to disable Elasticsearch modules

php bin/magento module:disable {Magento_Elasticsearch,Magento_InventoryElasticsearch,Magento_Elasticsearch6,Magento_Elasticsearch7}

If you disable these modules then you will get out from

Could not validate a connection to Elasticsearch

But it gives you an error on the category listing page.

  1. Other solution in the above post is to

Remove value from the database

SELECT * FROM `core_config_data` WHERE `path` LIKE 'catalog/search/engine'

It will also get a ride from Could not validate a connection to Elasticsearch error but on product listing page it will not show any product, products will not display on frontend.

Solution

You need to re-activate the ElasticSearch modules if you have de-activated them. ElasticSearch is required to run Magento 2.4. From Magento website: "As of Magento 2.4.0, Elasticsearch 7.6.x is required for all installations."

If you don't want to use Elasticsearch, you need to implement another catalog search solution as MySQL search has been removed, from the 2.4. changelog:

"The MySQL search engine has been removed from Magento 2.4.0 and replaced as the default search engine with Elasticsearch. Elasticsearch provides superior search capabilities as well as catalog performance optimizations. All merchants must have Elasticsearch to install and deploy Magento 2.4.0."

You should have to install Magento 2.4.* with ElasticSearch. Vrajesh Patel and another guide on how to install Magento 2.4.* with Elastic search. Many sites also guide you to configure ElasticsSeach with your Magento.

I am using docker setup for easy installation of ElasticsSearch

FROM docker.elastic.co/elasticsearch/elasticsearch:7.6.2

You need to install elasticsearch first if you did not have already.

Then you have to add a search object to the system -> default -> catalog in your app/etc/env.php OR make the settings in the magento backend accordingly:

<?php
return [
   ...
   'system' => [
        'default' => [
            'catalog' => [
                'search' => [
                    'elasticsearch5_server_hostname' => 'localhost',
                    'elasticsearch5_server_port' => '9200',
                    'elasticsearch5_index_prefix' => 'magento2',
                    'elasticsearch5_enable_auth' => '0',
                    'elasticsearch5_server_timeout' => '15',
                    'elasticsearch6_server_hostname' => 'localhost',
                    'elasticsearch6_server_port' => '9200',
                    'elasticsearch6_index_prefix' => 'magento2',
                    'elasticsearch6_enable_auth' => '0',
                    'elasticsearch6_server_timeout' => '15',
                    'elasticsearch7_server_hostname' => 'https://elastic-search-host.com',
                    'elasticsearch7_server_port' => '9200',
                    'elasticsearch7_index_prefix' => 'company_xy_',
                    'elasticsearch7_enable_auth' => '1',
                    'elasticsearch7_server_timeout' => '15',
                    'elasticsearch7_username' => 'xy',
                    'elasticsearch7_password' => 'xy'
                ],
            ],
        ],
    ],
 ...

Then execute:

php bin/magento setup:upgrade

If you are in deploy mode production, then additional commands might be necessary, like php bin/magento setup:di:compile and php bin/magento setup:static-content:deployment.

After debugging this, I can see that the upgrade script is calling the "ping" function, which is looking for the following:

  1. host: (must be "localhost")
  2. port: (must be 9200)

Therefore, to overcome the installation at least, I needed to create another Virtual Host on my Apache that listens on localhost:9200. Doing so, the Upgrade script completed successfully.

My installation now works, however, what's been crippled is clicking on any menu item, this is currently returning "no products" despite having more than 9000 in the database... debugging this further, it's clear that Magento is intentionally (or could be a bug in 2.4) crippling the products from showing unless an Elastic Search is installed and gives it the thumbs-up.

I don't like this, but at least to over the installation issue (as reported by the person creating this ticket), you need an active listener (Apache Virtual Host in my case) listening on "localhost:9200". That's the only way.

The listener does not need to have anything inside,... the "ping()" function is only looking for the port to connect, it would then disconnect and continue the installation.

The ping function is located under:

vendor/magento/module-elasticsearch/Model/Adapter/Elasticsearch.php

I posted a previous answer by disabling the ElsasticSearch modules, this was ok, but the system could not pass this stage, so, had to put these back and do the VH:9200, without making any modifications to Magento, the upgrade script worked fine.

I hope this helps. H

I have faced same issue while installing Magento 2.4.0 using command line and I have fixed issue to add elastic search hostname in installation command

Hostname: --elasticsearch-host=els235

Example of Magento 2.4.0 installation command:

php bin/magento setup:install --base-url=http://myproject.com/ \
--db-host=db --db-name=test --db-user=test --db-password=uiOUTYdfghjkdrt \
--admin-firstname=Kirti --admin-lastname=Nariya --admin-email=kirtinariya80@gmail.com \
--admin-user=admin --admin-password=admin123 --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1 \
--elasticsearch-host=els235

Note: You can use elasticsearch-host as your instance elasticsearch-host.

Magento is looking for this config in core_config_data catalog/search/elasticsearch7_server_hostname in my case:

\Magento\Elasticsearch\Model\Config::prepareClientOptions

        $defaultOptions = [
            'hostname' => $this->getElasticsearchConfigData('server_hostname'),
            'port' => $this->getElasticsearchConfigData('server_port'),
            'index' => $this->getElasticsearchConfigData('index_prefix'),
            'enableAuth' => $this->getElasticsearchConfigData('enable_auth'),
            'username' => $this->getElasticsearchConfigData('username'),
            'password' => $this->getElasticsearchConfigData('password'),
            'timeout' => $this->getElasticsearchConfigData('server_timeout') ? : self::ELASTICSEARCH_DEFAULT_TIMEOUT,
        ];

Download elasticsearch from this URL https://www.elastic.co/downloads/elasticsearch

Then unzip it in windows localhost htdocs folder please rename the folder to elasticsearch

After that open

htdocs\elasticsearch\bin

and in that find elasticsearch.bat file Right-click on that file and click Run as administrator.

Now the command window will open and elasticsearch is now working Don't close it while you are using all your command you mentioned in other command prompts.

Expected result: Composer should create this project bin/magento setup:install should install the database

Binaries that triggered this bug: composer create project bin/magento install

Result I get: Could not validate a connection to Elasticsearch. No alive nodes found in your cluster

How I fixed it: Using docker-network, I was able to analyze one of the 3 networks that the ECE tool creates on your local machine. It turns out, the docker image: magento/magento-cloud-docker-elasticsearch:7.7-1.1 is not exposing the port 9200 or Port 9300. It is possible java binary it is hard coded to 127.0.0.1 or to localhost.

Experience required to fix this bug: experience with java Spring framework YAML files CentOS operating system, Network topologies

Proposed fix: In order to expose the port to other docker containers, one must use IP address: 0.0.0.0

Workaround: You can use Elasticsearch container IP address. For example

php -d memory_limit=-1 bin/magento setup:install
--base-url=http://b2b.docker
--db-host=127.0.0.1:32774
--db-name=magento2
--db-user=magento2
--db-password=magento2
--admin-firstname=Xavier
--admin-lastname=Baez
--admin-email=xavierbaez@gmail.com
--admin-user=admin
--admin-password=password
--language=en_US
--currency=USD
--timezone=America/Los_Angeles
--use-rewrites=1
--search-engine=elasticsearch7
--elasticsearch-host=172.24.0.2
--elasticsearch-port=9200
--elasticsearch-enable-auth=0

For Magento2.4, we must configure elasticsearch or disable elasticsearch7,elasticsearch6 and elasticsearch module before magento2 install command.

=> First download and configure elasticsearch in ubuntu

Download and install elasticsearch

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

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

sudo apt update && sudo apt install elasticsearch

configure elasticsearch

  1. open elastic configuration file with below command

sudo nano /etc/elasticsearch/elasticsearch.yml

  1. change or write host name in elasticsearch.yml file.

network.host: localhost

3.start elasticsearch

   sudo systemctl start elasticsearch

check status of elastic search

 sudo systemctl status elasticsearch

Run magento2 install command

sudo php bin/magento setup:install --base-url="http://127.0.0.1/magento/" --db-host="localhost" --db-name="magento" --db-user="root" --db-password=root --admin-firstname="admin" --admin-lastname="admin" --admin-email="admin@admin.com" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="INR" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --elasticsearch-host=localhost --search-engine=elasticsearch7 --elasticsearch-enable-auth=0

If you are trying to install Magento2.4 locally (i.e. in a docker container or xampp) it is a bit frustrating that Magento "checks" if there is an elasticsearch available during install. My elasticsearch is of course not at "localhost" because that is where my Magento2.4 installation is. Thanks to Heider Sati's answer about the ping I realized how to fix this for my local installation.

In the end I installed Magento2.4 without the elastic search modules (as suggested by Heider Sati) and then got a local instance of elasticsearch running but found that Magento would indeed "ping" to localhost for it as soon as I did a setup:upgrade after (re)enabling the elasticsearch modules. I did a search for "localhost" in the 3 elasticsearch modules and changed the hostname to my local elasticsearch ip. For instance in vendor/magento/module-elasticsearch-7/etc/config.xml I changed

<engine>elasticsearch6</engine>
<elasticsearch6_server_hostname>localhost</elasticsearch6_server_hostname>

to

<engine>elasticsearch6</engine>
<elasticsearch6_server_hostname>172.17.0.3</elasticsearch6_server_hostname>

which is the ip of my local elasticsearch. I did this for all 3 config files (you could even change the port here (which is 9200 by default) and then run setup:upgrade successfully. Magento "pings" for my local elasticsearch and then continues to install the modules. Then you can configure your settings in the backend and you have a locally installed magento instance at localhost that uses your locally installed elasticsearch.

The issue is related to limitation of elasticsearch.

You need to set the vm.max_map_count to 262144

vm.max_map_count=262144

Follow the instruction from this link - https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

First, check the Elastic Search Version on your machine.

curl 'localhost:9200'

The output will be like this:

{
  "name" : "***********",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "******",
  "version" : {
    "number" : "7.10.2",      //  << ----- version
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
    "build_date" : "2021-01-13T00:42:12.435326Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

For Elastic Search 6: execute the below command.

php bin/magento setup:install --search-engine=elasticsearch6 --elasticsearch-host="localhost" --elasticsearch-port=9200

for Elastic Search 7 (just update the version)

php bin/magento setup:install --search-engine=elasticsearch7 --elasticsearch-host="localhost" --elasticsearch-port=9200
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top