Elasticsearch is a popular open-source search and analytics tool for various types of data, including text, numeric, and geospatial. Installing and configuring Elasticsearch on CentOS 7 requires a careful step-by-step process to ensure proper functionality and optimization for specific use cases. Below is a detailed guide on installing and performing basic configuration of Elasticsearch on CentOS 7.
Prerequisites
Before starting the installation, ensure that your system is up-to-date and you have full administrative privileges (root access).
1. Installing Java
Elasticsearch requires Java, so the first step is to install the Java Runtime Environment (JRE) or Java Development Kit (JDK). Elasticsearch supports OpenJDK, which can be installed using the following command:
sudo yum install java-1.8.0-openjdk
After installation, verify the Java installation by running the following command:
java -version
2. Importing the Elasticsearch GPG Key
To secure and verify the authenticity of downloaded packages, import the Elasticsearch GPG key:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
3. Adding the Elasticsearch Repository
Create a new Elasticsearch repository file in /etc/yum.repos.d/
:
sudo vi /etc/yum.repos.d/elasticsearch.repo
And insert the following content into it:
[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
4. Installing Elasticsearch
After adding the repository, you can install Elasticsearch using the yum
command:
sudo yum install elasticsearch
5. Configuring Elasticsearch
After installation, you need to modify the Elasticsearch configuration file (/etc/elasticsearch/elasticsearch.yml
). Open this file in an editor and adjust the following parameters according to your configuration needs:
network.host
: Set to the local IP address of the server for remote access orlocalhost
for local access.http.port
: Port on which Elasticsearch will be available (default is 9200).cluster.name
: Name of your Elasticsearch cluster.node.name
: Name of your node within the cluster.
Ensure that you have made necessary changes for your environment and save the file.
6. Starting and Enabling the Elasticsearch Service
Enable the Elasticsearch service to start automatically on system boot:
sudo systemctl enable elasticsearch.service
Then start the service:
sudo systemctl start elasticsearch.service
7. Verifying Elasticsearch Functionality
To verify that Elasticsearch is running and accessible, use curl or a web browser to access http://localhost:9200
. You should receive a response with information about your Elasticsearch installation.
curl -X GET "localhost:9200/"
Installing and performing basic configuration of Elasticsearch on CentOS 7 is not a complex process, but it requires careful adherence to steps and settings. After completing the installation and configuration, Elasticsearch is ready for further customization and optimization to suit your project's needs.