Skip to content

ElasticSearch Setup

Bobby Warner edited this page Nov 20, 2024 · 1 revision

To install and set up Elasticsearch 7.x on Ubuntu 22.04, follow these steps:

1. Install Java (OpenJDK)

Elasticsearch 7 requires Java 11 or later. Most installations will use OpenJDK, but you can also use Oracle JDK.

To install OpenJDK 11, run:

sudo apt update
sudo apt install openjdk-11-jdk

Verify the installation:

java -version

You should see output similar to:

openjdk version "11.x.x"

2. Install the Elasticsearch APT Repository

Elasticsearch is not available in the default Ubuntu repositories, so you'll need to add its official repository.

  1. Download and install the public signing key for the Elasticsearch packages:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo tee /etc/apt/trusted.gpg.d/elasticsearch.asc
  1. Add the Elasticsearch APT repository:
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'

3. Install Elasticsearch

Now, update your package list and install Elasticsearch:

sudo apt update
sudo apt install elasticsearch

4. Configure Elasticsearch

Elasticsearch is installed but needs configuration to be properly used.

  1. Edit the main configuration file:
sudo nano /etc/elasticsearch/elasticsearch.yml

Here are some common settings you might want to modify:

  • Network host: If you plan to run Elasticsearch on a specific interface or IP address, change the network.host setting. For example, to bind to all network interfaces, set:

    network.host: 0.0.0.0
  • Cluster name: If you want to set a specific name for your Elasticsearch cluster (optional), set:

    cluster.name: my-cluster
  • Node name: You can set a specific node name for each instance if needed:

    node.name: node-1

After modifying, save the file and exit.

5. Enable and Start Elasticsearch Service

Enable the Elasticsearch service to start on boot, and then start the service:

sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch

You can check the status of Elasticsearch to ensure it's running:

sudo systemctl status elasticsearch

6. Test Elasticsearch

To verify that Elasticsearch is running correctly, use curl to make an HTTP request:

curl -X GET "localhost:9200/"

You should see a JSON response with information about your Elasticsearch node, similar to this:

{
  "name" : "node-1",
  "cluster_name" : "my-cluster",
  "cluster_uuid" : "exampleuuid",
  "version" : {
    "number" : "7.x.x",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "examplehash",
    "build_date" : "2020-06-01T13:28:45.022056Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0"
  },
  "tagline" : "You Know, for Search"
}

7. Set Up Firewall (if necessary)

If you have a firewall running on your server, you need to allow traffic on port 9200 (the default Elasticsearch HTTP port). For example, if you're using ufw:

sudo ufw allow 9200

8. (Optional) Enable Elasticsearch to Start Automatically

You can also configure Elasticsearch to automatically start on boot:

sudo systemctl enable elasticsearch

9. Install Kibana (Optional, but recommended for visualization)

If you want a web-based interface to manage and interact with your Elasticsearch data, you can install Kibana.

  1. Install Kibana:
sudo apt install kibana
  1. Configure Kibana (if needed) by editing the kibana.yml configuration file:
sudo nano /etc/kibana/kibana.yml

Set the server.host to 0.0.0.0 to allow external access (or configure it for specific IP addresses):

server.host: "0.0.0.0"
  1. Enable and start the Kibana service:
sudo systemctl enable kibana
sudo systemctl start kibana
  1. Access Kibana in your browser:


Conclusion

You now have Elasticsearch 7.x installed and running on Ubuntu 22.04. Optionally, you can install Kibana for easy management and visualization of data. Make sure to secure your Elasticsearch instance before using it in production, especially if it’s exposed to the internet.