Elasticsearch packages are provided by Elasticsearch B.V.. Elasticsearch is a Java application, so you'll have to install a Java Runtime Environment prior to installing Elasticsearch binaries for things to work.

Step-by-step video guide:

Steps to install Elasticsearch on CentOS and Red Hat (RHEL):

  1. Install the latest Java Runtime Environment.
    # yum install --assumeyes java-1.8.0-openjdk
  2. Download and install the public signing key Elasticsearch repository.
    # rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
  3. Create and add Elasticsearch repository information into /etc/yum.repos.d/elasticsearch.repo.
    # cat >> /etc/yum.repos.d/elasticsearch.repo <<EOF
    name=Elasticsearch repository for 6.x packages
  4. Install Elasticsearch package along with dependencies.
    # yum install --assumeyes elasticsearch
    ##### snipped
     Package            Arch        Version        Repository              Size
     elasticsearch      noarch      6.4.0-1        elasticsearch-6.x       93 M
    Transaction Summary
    Install  1 Package
    ##### snipped

    Even though yum supposedly resolve and install package dependencies, elasticsearch might not list java as a dependency thus you might come to this error if you don't manually install java as in the previous step.

    Running transaction
    which: no java in (/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin)
    could not find java; set JAVA_HOME or ensure java is in PATH
    error: %pre(elasticsearch-0:6.4.0-1.noarch) scriptlet failed, exit status 1
    Error in PREIN scriptlet in rpm package elasticsearch-6.4.0-1.noarch
      Verifying  : elasticsearch-6.4.0-1.noarch                             1/1
      elasticsearch.noarch 0:6.4.0-1
  5. Configure Elasticsearch if necessary by editing /etc/elasticsearch/elasticsearch.yml.
    1. Listen to host's IP Address to enable connection from remote host.

  6. Configure firewall for Elasticsearch service.
    1. Enable network access to port 9200and 9300.
      # firewall-cmd --permanent --add-port=9200/tcp
      # firewall-cmd --permanent --add-port=9300/tcp
    2. Reload firewall rules and keep state information.
      # firewall-cmd --reload
  7. Configure Elasticsearch service to automatically start during boot.
    # systemctl enable elasticsearch
    Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
  8. Start Elasticsearch service.
    # systemctl start elasticsearch

    The service will take a while to start

  9. Test if installation is successful.
    $ curl
      "name" : "CbbCFrX",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "IfiakkGkTXy20Xncr_ZZXw",
      "version" : {
        "number" : "6.4.0",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "build_hash" : "595516e",
        "build_date" : "2018-08-17T23:18:47.308994Z",
        "build_snapshot" : false,
        "lucene_version" : "7.4.0",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      "tagline" : "You Know, for Search"

    You will not be able to connect immediately to Elasticsearch because the service takes quite a while to start and will get the following error if you try to connect immediately.

    curl: (7) Failed to connect to port 9200: Connection refused

Discuss the article:

Comment anonymously. Login not required.