Elasticsearch Installation On Centos 7

admin13 April 2024Last Update :

Prerequisites for Elasticsearch Installation

Before diving into the installation process, it’s essential to ensure that your CentOS 7 system meets the necessary prerequisites. Elasticsearch requires Java, as it is built on top of the Lucene library, which is written in Java.

  • Java: Install either OpenJDK or Oracle JDK. Elasticsearch recommends using the latest version of Java for optimal performance.
  • System Requirements: Ensure your server has at least 2GB of RAM for Elasticsearch to perform effectively. More memory may be required depending on your use case.
  • Network Configuration: Adjust firewall settings to allow traffic on port 9200, which is the default port used by Elasticsearch.

Installing Java

To install Java on CentOS 7, you can choose between OpenJDK and Oracle JDK. Here’s how to install OpenJDK:

yum install java-1.8.0-openjdk

Verify the installation with the following command:

java -version

Elasticsearch Repository Configuration

Elasticsearch packages are distributed through a YUM repository. To add the Elasticsearch repository to your system, follow these steps:

Importing Elasticsearch PGP Key

Firstly, import the Elasticsearch public GPG key into rpm:

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

Adding the Elasticsearch Repository

Create a new repository file for Elasticsearch:

vi /etc/yum.repos.d/elasticsearch.repo

Add the following content to 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

Installing Elasticsearch

With the repository configured, you can now proceed to install Elasticsearch using the yum package manager.

yum install elasticsearch

After the installation completes, enable and start the Elasticsearch service:

systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service

Configuring Elasticsearch

Post-installation, configuring Elasticsearch is crucial to ensure it operates correctly within your environment.

Basic Configuration

Edit the Elasticsearch configuration file located at /etc/elasticsearch/elasticsearch.yml. You’ll want to set the network host and possibly the cluster name or node name:

network.host: localhost
cluster.name: my-cluster
node.name: "my-node-1"

Memory Allocation

It’s also important to configure the heap size for Elasticsearch. Edit the jvm.options file:

vi /etc/elasticsearch/jvm.options

And set the Xms and Xmx settings to define the minimum and maximum heap sizes respectively:

-Xms1g
-Xmx1g

Remember to adjust these values based on your server’s available RAM.

Securing Elasticsearch

Security is paramount when deploying any application. For Elasticsearch, you should consider implementing the following security measures:

  • User Authentication: Set up user authentication to control access to your Elasticsearch cluster.
  • Encryption: Use SSL/TLS encryption to secure data in transit.
  • Firewall Rules: Configure firewalls to restrict access to trusted sources only.

Setting Up User Authentication

Starting with Elasticsearch 6.x, X-Pack is included by default, providing security features such as authentication. Enable basic authentication by editing the elasticsearch.yml file and adding:

xpack.security.enabled: true

Then, restart Elasticsearch and set passwords for built-in users using the elasticsearch-setup-passwords utility.

/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive

Maintaining and Monitoring Elasticsearch

Regular maintenance and monitoring are vital to keep your Elasticsearch cluster healthy.

Cluster Health Check

You can check the health of your cluster using the following curl command:

curl -X GET "localhost:9200/_cluster/health?pretty"

Updating Elasticsearch

Keep your Elasticsearch instance up-to-date with the latest security patches and features by regularly updating the software through the yum package manager.

yum update elasticsearch

Troubleshooting Common Issues

When working with Elasticsearch on CentOS 7, you might encounter some common issues related to configuration, networking, or permissions.

  • Service Fails to Start: Check the Elasticsearch logs located at /var/log/elasticsearch/ for detailed error messages.
  • Networking Issues: Verify that your firewall settings are not blocking communication on the ports Elasticsearch uses (default is 9200 and 9300).
  • Permission Errors: Ensure that the Elasticsearch directories and files have the correct ownership and permissions.

Frequently Asked Questions

How do I upgrade Elasticsearch on CentOS 7?

To upgrade Elasticsearch, you can use the yum package manager. First, back up your data, then run yum update elasticsearch and restart the service.

Can I change the default port that Elasticsearch uses?

Yes, you can change the default HTTP and transport ports by modifying the elasticsearch.yml configuration file.

Is it necessary to disable swap on a machine running Elasticsearch?

While not strictly necessary, it is highly recommended to disable swap because swapping can cause significant latency issues for Elasticsearch.

What is the best way to back up an Elasticsearch cluster?

The best practice is to use the Snapshot and Restore feature provided by Elasticsearch, which allows you to take snapshots of your indices and store them in a repository.

References

For further reading and external resources, consult the following links:

Leave a Comment

Your email address will not be published. Required fields are marked *


Comments Rules :

Breaking News