JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

How to install Elasticsearch on CentOS

Author:JIYIK Last Updated:2025/04/06 Views:

Elasticsearch is an open source search engine developed based on Java, so you need to install the Java runtime environment to run it properly.

Specifically, Elasticsearch is a distributed search engine built on Apache Lucene. It uses Java to implement the underlying core functions of data storage, indexing, and searching, and provides powerful full-text search and real-time data analysis capabilities. Therefore, to run Elasticsearch on a server, you must first install the Java runtime environment.

It should be noted that different versions of Elasticsearch may have different requirements for Java, so before installing Elasticsearch, you should first check the official documentation of Elasticsearch to understand the required Java version and configuration requirements. At the same time, it is recommended to use the official Java implementation such as Oracle JDK or OpenJDK to ensure the stability and performance of Elasticsearch.


Preliminary preparation

1. Install Java:

Elasticsearch requires Java 8 or higher. We can install Java 8 using the following command:

$ sudo yum install java-1.8.0-openjdk -y

2. Configure Java environment variables:

We need to configure the Java path in the system environment variables so that Elasticsearch can find Java. Add the following to the /etc/profile file:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export PATH=$PATH:$JAVA_HOME/bin

3. Configure kernel parameters:

On CentOS, Elasticsearch requires some kernel parameter tuning to achieve optimal performance. Kernel parameters can be configured by editing the /etc/sysctl.conf file:

$ sudo vim /etc/sysctl.conf

Add the following content:

vm.max_map_count=262144
fs.file-max=65536

Then save the file and execute the following command for the changes to take effect:

$ sudo sysctl -p

4. Verify the configuration of Java and kernel parameters:

We can verify that Java was installed correctly with the following command:

$ java -version

If it returns a Java version, Java has been successfully installed.

We can verify that the kernel parameters have been configured correctly using the following command:

$ sudo sysctl -a | grep vm.max_map_count
$ sudo sysctl -a | grep fs.file-max

If it returns the same value as what we set in the /etc/sysctl.conf file, then the kernel parameters have been configured successfully.

These steps will ensure that Elasticsearch runs properly and performs optimally on CentOS.


Install Elasticsearch

1. Add the Elasticsearch repository:

Download and install the public key for Elasticsearch using the following command:

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

Then add the Elasticsearch repository using the following command:

$ sudo vim /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

2. Install Elasticsearch:

Install Elasticsearch using the following command:

$ sudo yum install elasticsearch -y

3. Edit the Elasticsearch configuration file:

Edit the /etc/elasticsearch/elasticsearch.yml file and set the following parameters:

cluster.name: <your_cluster_name>
node.name: <your_node_name>
network.host: <your_server_ip>

Among them, <your_cluster_name>is our cluster name, <your_node_name>is our node name, and <your_server_ip>is our server IP address.

4. Start the Elasticsearch service and enable it to start at boot:

Start the Elasticsearch service with the following command:

$ sudo systemctl enable elasticsearch
$ sudo systemctl start elasticsearch

5. Verify that Elasticsearch is installed correctly:

We can verify that Elasticsearch was installed correctly with the following command:

$ curl -X GET "http://localhost:9200/"

If output similar to the following is returned, Elasticsearch has been successfully installed:

{
  "name" : "your_node_name",
  "cluster_name" : "your_cluster_name",
  "cluster_uuid" : "sDFsLc9XQTyDYp_KBz50tA",
  "version" : {
    "number" : "7.11.2",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "3e5a16cfec50876d20ea77b075070932c6464c7d",
    "build_date" : "2021-03-06T05:54:38.141101Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Error starting Elasticsearch

After the installation is complete, we may encounter an error when starting Elasticsearch: Job for elasticsearch.service failed because a fatal signal was delivered to the control process

This error may be caused by Elasticsearch taking up too much memory at startup, causing the Linux system to send a fatal signal to the Elasticsearch process, causing it to stop running.

We can try to solve this problem in the following ways:

1. Allocate more memory to Elasticsearch

You can try to increase the Elasticsearch JVM heap memory limit to a higher value so that Elasticsearch can use more memory. You can edit the Elasticsearch configuration file /etc/elasticsearch/jvm.options and find the following two parameters:

-Xms1g
-Xmx1g

Change it to a larger value, for example:

-Xms4g
-Xmx4g

This will set both the minimum and maximum heap memory limits for Elasticsearch to 4GB. You will need to restart Elasticsearch after changing this.

2. Reduce Elasticsearch resource usage

If your system resources are limited or you cannot allocate more memory to Elasticsearch, you can try to reduce Elasticsearch's use of system resources by:

  • Disable unused plugins
  • Compress and archive old Elasticsearch log files
  • Delete the old Elasticsearch index
  • Adjust index settings so that Elasticsearch uses less memory and disk space

3. Check system resource usage

You can use the topor htopcommand to view system resource usage to determine if there are any resource bottlenecks.

If the above methods still do not solve the problem, please check other error messages in the Elasticsearch log file to obtain more valuable content.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Restart PostgreSQL in Ubuntu 18.04

Publish Date:2025/04/09 Views:72 Category:PostgreSQL

This short article shows how to restart PostgreSQL in Ubuntu. Restart PostgreSQL Server in Ubuntu You can restart Postgres server in Ubuntu using the following command. Order: sudo service postgres restart Sometimes the above command does n

Issues to note when installing Apache on Linux

Publish Date:2025/04/08 Views:78 Category:OPERATING SYSTEM

As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of A

How to decompress x.tar.xz format files under Linux

Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM

A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr

Summary of vim common commands

Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM

In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme

Detailed explanation of command return value $? in Linux

Publish Date:2025/04/08 Views:58 Category:OPERATING SYSTEM

? is a special variable. This variable represents the return value of the previous command. That is to say, when we run certain commands, these commands will return a code after running. Generally, if the command is successfully run, the re

Common judgment formulas for Linux script shell

Publish Date:2025/04/08 Views:159 Category:OPERATING SYSTEM

In shell script programming, predicates are often used. There are two ways to use predicates, one is to use test, and the other is to use []. Let's take a look at how to use these two methods through two simple examples. Example 1 # test –

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial