With the latest version of Magento, Magento 2.4 removing the MySQL search capability and forcing the use of Elasticsearch 7.x, many users may be frantically searching for the latest guide to install Elasticsearch in your server.
As most of the guides around the net are either outdated or may not work well in a CentOS 7 environment with cPanel/WHM installed, I hope this installation guide will be helpful to those of you running CentOS 7. You will need root access to follow this guide.
Firstly, create a yum repository in your server for Elasticsearch 7.x:-
nano /etc/yum.repos.d/elasticsearch.repo
Add the following content to the file:-
[elasticsearch] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=0 autorefresh=1 type=rpm-md
Then, run the Elasticsearch installation:-
yum -y install --enablerepo=elasticsearch elasticsearch
Once the installation is complete, modify the file below:-
nano /etc/sysconfig/elasticsearch
Add this to any new line in the file above to reference a temporary directory:-
ES_TMPDIR=/usr/share/elasticsearch/tmp
Create the temporary directory referenced above and set the appropriate file permissions:-
mkdir /usr/share/elasticsearch/tmp chmod 777 /usr/share/elasticsearch/tmp
Make sure Elasticsearch will be started automatically whenever the server reboots:-
/bin/systemctl daemon-reload /bin/systemctl enable elasticsearch.service
Start Elasticsearch:-
/bin/systemctl start elasticsearch.service
Nice…
Have you tried it with WordPress?
Yes, it’ll work with WordPress as well as long as the plugin you use support Elasticsearch 7.x.
Got to learn a lot from your article… Thanks a lot for sharing such useful information with us. Was looking for something exactly like this..
Thank you! Is this still working well for you? Are there any security issues?
I have also seen this guide: https://support.cpanel.net/hc/en-us/articles/360055446413-How-To-Install-Run-Elasticsearch and see that they use:
ES_TMPDIR=/tmp
I see your method uses 777 for the tmp directory, which way is better?
Yes it should still work without any security issues provided that this is a dedicated environment (not shared hosting).
Using “/tmp” for “ES_TMPDIR” is fine as well if you are sure that the “/tmp” directory in the server has sufficient space. Otherwise the safer option is to create a temporary directory and give it the 777 permission so it can be read and written by Elasticsearch.
Sorry I couldn’t edit my last comment, running this: /usr/share/elasticsearch/bin/elasticsearch –version
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
could not find java in JAVA_HOME at /usr/local/jdk/bin/java