This article was first published in: https://www.itcoder.tech/posts/how-to-install-elasticsearch-on-centos-8/
Elasticsearch is an open source full-text search and analysis engine.It supports RESTful operations and allows you to store, search, and analyze large amounts of data in real time.Elasticsearch is one of the most popular search engines that powers applications with complex search requirements, such as large e-commerce stores and analytic applications.
This article focuses on installing Elasticsearch on CentOS 8.
1. Install Java
Elasticsearch is a Java application, so the first step is to install Java.
Run the following command as root or other sudo user to install the OpenJDK package:
sudo dnf install java-11-openjdk-devel
Verify the Java installation by printing a Java version:
java -version
The output will look like the following:
openjdk version "11.0.5" 2019-10-15 LTS OpenJDK Runtime Environment 18.9 (build 11.0.5+10-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode, sharing)
2. Install Elasticsearch
Elasticsearch is not available in the standard CentOS 8 source.We will install it from the Elasticsearch RPM source.
Import the source GPG using the rpm command:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Open your text editor and create the source file in the / etc/yum.repos.d directory:
sudo nano /etc/yum.repos.d/elasticsearch.repo
Paste the following into the file:
[elasticsearch-7.x] 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=1 autorefresh=1 type=rpm-md
Save the file and close your text editor.
Now that the source is enabled, install the Elasticsearch package, enter:
sudo dnf install elasticsearch
Once the installation process is complete, start and enable the service:
sudo systemctl enable elasticsearch.service --now
To verify that Elasticsearch is running, use the curl command to send an HTTP request to the local port 9200:
curl -X GET "localhost:9200/"
The output will look like the following:
{ "name" : "centos8.localdomain", "cluster_name" : "elasticsearch", "cluster_uuid" : "V_mfjn2PRJqX3PlZb_VD7w", "version" : { "number" : "7.6.0", "build_flavor" : "default", "build_type" : "rpm", "build_hash" : "7f634e9f44834fbc12724506cc1da681b0c3b1e3", "build_date" : "2020-02-06T00:09:00.449973Z", "build_snapshot" : false, "lucene_version" : "8.4.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
It will take 5-10s to start the service.If you see curl: (7) Failed to connect to localhost port 9200: Connection refused, wait a few seconds and try again.
To view information about the Elasticsearch service, use the following command:
sudo journalctl -u elasticsearch
Here you have installed Elasticsearch on your CentOS server.
3. Configuring Elasticsearch
Elasticsearch data is stored in the / var/lib/elasticsearch directory with a configuration file in / etc/elasticsearch.
By default, the Elasticsearch configuration file only listens to localhost.If the databases the client connects to are on the same host and you have a single-node cluster set up, you do not need to modify the default configuration file.
3.1 Remote Access
Out-of-the-box Elasticsearch does not implement authentication, so it can be accessed by anyone through the HTTP API.If you allow remote access to your Elasticsearch server, you need to configure your firewall and only allow access to Elasticsearch from trusted clients through port 9200.
For example, only access from 192.168.121.80 is allowed, enter the following command:
Run the following command to allow access to port 9200 from a remotely trusted IP address:
sudo firewall-cmd --new-zone=elasticsearch --permanent sudo firewall-cmd --reload sudo firewall-cmd --zone=elasticsearch --add-source=192.168.121.80/32 --permanent sudo firewall-cmd --zone=elasticsearch --add-port=9200/tcp --permanent sudo firewall-cmd --reload
Don't forget to modify `192.168.121.80` to your remote IP address.
Later, if you want to allow access from other IP addresses, use:
sudo firewall-cmd --zone=elasticsearch --add-source=<IP_ADDRESS> --permanent sudo firewall-cmd --reload
Once the firewall is configured, the next step is to modify the Elasticsearch configuration file and allow Elasticsearch to listen for external connections.
To do so, open the elasticsearch.yml configuration file:
sudo nano /etc/elasticsearch/elasticsearch.yml
The search contains network.host, removes the comment, and changes to:
network.host: 0.0.0.0
If you have more than one network interface, specify the interface IP address to force Elasticsearch to listen only on the specified network interface.
Restart the Elasticsearch service for the changes to take effect:
sudo systemctl restart elasticsearch
That's all.You can now connect to the Elasticsearch server from a remote location.
4. Summary
We have shown how to install Elasticsearch on CentOS 8.
If you have any questions, please contact us by:
WeChat: sn0wdr1am86
{{< figure src="/img/snowdream/itcoder-weixin.jpeg" >}}
WeChat Group:
Add WeChat above, note WeChat group
QQ: 3217680847
{{< figure src="/img/snowdream/itcoder-qq.jpeg" >}}
QQ group: 82695646
{{< figure src="/img/snowdream/itcoder-qqqun.jpeg" >}}