24

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
6
  • do you have elasticsearch? with auth enabled?
    – MagenX
    Aug 1 '20 at 16:47
  • No I have tried to install the latest magento version in my locally linux mint. Aug 2 '20 at 4:03
  • Have you fix it? Aug 5 '20 at 10:12
  • By disabling this elastic search module. It's working. Aug 5 '20 at 11:16
  • Also confirmed after adding 80 port connection becomes successful but while running indexing command getting error. Aug 19 '20 at 5:30

21 Answers 21

27

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!...

10
  • I had tried this one also and able to run setup upgrade command but getting error in indexing. So not able to indexing and products are not displayed on front end. Aug 28 '20 at 5:44
  • I have the same problem. Aug 28 '20 at 10:22
  • 1
    Hi All, I have found another bug in 2.4 and now reported the problem and also the fix under: github.com/magento/magento2/issues/29805 Aug 29 '20 at 8:00
  • 1
    I feel you. Magento is giving me headache every single day. I have never seen such a unprofessional company.
    – Black
    Sep 23 '20 at 11:21
  • 1
    With 2.4.2 you have to do php bin/magento module:disable {Magento_ElasticsearchCatalogPermissions,Magento_Elasticsearch,Magento_InventoryElasticsearch,Magento_Elasticsearch6,Magento_Elasticsearch7}
    – Thanu
    Mar 3 at 4:21
11

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
5
  • 1
    Does not work either. Still get the error. And curl elasticsearch:9200 returns curl: (6) Could not resolve host: elasticsearch; Unknown Error
    – Black
    Aug 19 '20 at 10:34
  • Probably you don't have ElasticSearch installed or you must specify the right address instead of elasticsearch:9200, for example, curl 127.0.0.1:9200 Aug 19 '20 at 16:34
  • So I need to lease an external elasticsearch server to be able to operate magento 2? Before 2.4.0 it was working without an external server??
    – Black
    Aug 20 '20 at 7:29
  • In M2.4 ElasticSearch is required, so you can have it installed in your current server or you can use an external server, the same that you do today with your MySQL. Aug 20 '20 at 20:47
  • 1
    Magento is too expensive at this point, I will have a look at shopware.
    – Black
    Sep 23 '20 at 8:41
9

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

2
  • Elasticsearch Server Hostname : localhost Elasticsearch Server Port : 9200 worked for me
    – Nitesh
    Mar 9 at 7:01
  • saved my day.. thanks May 20 at 7:14
4

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'
2
  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
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.

1

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

1

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

1

5 Easy Steps to resolve this issue.

1st Step: Make sure you Installed Elasticsearch Correctly. (This comment will help you in best installation, - CLick here )

2nd Step If you installing magento 2.4.x after Elasticsearch then elastic search will get disabled which re-create the same Error - Could not validate a connection to Elasticsearch. No alive nodes found in your cluster

3rd Step Reenable and Start Elastic Search using this sudo systemctl start elasticsearch sudo systemctl enable elasticsearch

4th Step Verify That Elastic search working now - curl -X GET 'localhost:9200'

5th Step Complete Magento Setup Using - php -dmemory_limit=5G bin/magento setup:install \ --base-url=https://yourdomain.com \ --db-host=localhost \ --db-name=db name \ --db-user=db user \ --db-password=db pass \ --admin-firstname=first name \ --admin-lastname=last name \ --admin-email=your email id \ --admin-user=admin \ --admin-password=choose admin password \ --language=en_US \ --currency=USD \ --timezone=America/Chicago \ --use-rewrites=1 \ --search-engine=elasticsearch7 \ --elasticsearch-host="localhost" \ --elasticsearch-port=9200

I recommend to install elastic search before installing magento setup on server.

I hope this will end your search for issue issue solution.

0

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.

4
  • Does not work either.
    – Black
    Aug 19 '20 at 10:29
  • 1
    Please check your php version should be 7.4 and Elasticsearch version 7.6.x. Aug 19 '20 at 13:39
  • Please put that info in your answer, so that I can upvote.
    – Black
    Aug 21 '20 at 9:13
  • @Black I have already mention in comment. Did you checked your PHP and Elasticsearch version ? Aug 21 '20 at 11:48
0

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,
        ];
0

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.

0

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

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.

0

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

0

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
0

If you don't want to install elasticsearch for magento2 and you don't need elasticsearch for search engine you can install this module:

https://github.com/zepgram/module-disable-search-engine/tree/v0.0.1

0

I needed to disable authentication, otherwise Magento thought elasticsearch is not running.

Edit your config file, e.g. with nano or vim:

nano ES_PATH_CONF/elasticsearch.yml

Remove the following config:

xpack.security.enabled: true

Note: You should only remove authentication if your node is not public.

0

The easiest solution I found to this problem was to just run the elastic search instance and leave it running. To do this just go to where you installed elastic search and locate the bin directory (in my case it is C:\xampp\htdocs\elasticsearch-7.13.2\bin) then right-click on the file named elasticsearch.bat and run it as Administrator. This will trigger a console script that will create an instance of the elastic search. Do not close the console window of the running instance, Then try running the command again and you won't get the error. This works for me, you will sometimes also get this error when running "bin/magento setup:upgrade" the solution is the same.

0
sudo systemctl stop elasticsearch.service

sudo systemctl start elasticsearch.service

This work for me! Just stop and start elasticsearch.

0

First you can confirm that Elastic Search is installed: service elasticsearch status

If its installed on Port 9200 then check: curl localhost:9200

If not installed then: sudo apt update

Then run the installation: sudo apt install elasticsearch

First, reload the systemd configuration: sudo systemctl daemon-reload

Then, enable the Elasticsearch service with: sudo systemctl enable elasticsearch.service

And finally, after the service is enabled, start Elasticsearch: sudo systemctl start elasticsearch.service

If you make changes to configuration files, or need to restart Elasticsearch for any reason, use: sudo systemctl restart elasticsearch.service

Then made configuration in admin, that may looks like this, enter image description here

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.