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 can power applications with complex search requirements, such as large e-commerce stores and analytics applications.
This article mainly involves installing Elasticsearch on CentOS 8.
Elasticsearch is a Java application, so the first step is to install Java.
Run the following command as root or another sudo user to install the OpenJDK package:
sudo dnf install java-11-openjdk-devel
Verify the Java installation by printing the Java version:
java -version
The output will look like this:
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)
Elasticsearch is not available in the standard CentOS 8 source. We will install it from the Elasticsearch RPM source.
Use the rpm
command to import the source GPG:
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 content into the file:
[ elasticsearch-7.x]
name=Elasticsearch repository for7.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 and enter:
sudo dnf install elasticsearch
Once the installation process is complete, start and enable this 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 this:
{" 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
, please wait a few seconds and try again.
To view information about the Elasticsearch service, use the following command:
sudo journalctl -u elasticsearch
At this point, you have installed Elasticsearch on your CentOS server.
Elasticsearch data is stored in the /var/lib/elasticsearch
directory, and the configuration file is in /etc/elasticsearch
.
By default, Elasticsearch is configured to only listen on localhost. If the database that the client connects to is on the same host, and you set up a single-node cluster, you do not need to modify the default configuration file.
Elasticsearch out of the box does not implement authentication, so it can be accessed by anyone through HTTP API. If you allow remote access to your Elasticsearch server, you need to configure your firewall and only allow trusted clients to access Elasticsearch through port 9200.
For example, to only allow access from 192.168.121.80
, enter the following command:
Run the following command to allow access to port 9200
from a remote 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`192.168.121.80`Modify it 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 monitor external connections.
To do this, open the elasticsearch.yml
configuration file:
sudo nano /etc/elasticsearch/elasticsearch.yml
Search contains network.host
, remove the comment, and modify it to:
network.host:0.0.0.0
If you have multiple network interfaces, specify the interface IP address to force Elasticsearch to only listen on the specified network interface.
Restart the Elasticsearch service to make the changes take effect:
sudo systemctl restart elasticsearch
that's it. You can now connect to the Elasticsearch server from a remote location.
We have shown how to install Elasticsearch on CentOS 8.
Recommended Posts