Software & AppsOperating SystemLinux

How To Run Elasticsearch on Ubuntu on WSL without systemd

Ubuntu 15

Elasticsearch is a powerful open-source search and analytics engine that makes data easy to explore. It’s used for log and event data analysis, full-text search, and many other applications that require efficient search functionality. However, running Elasticsearch on Ubuntu on Windows Subsystem for Linux (WSL) without systemd can be a bit tricky due to the lack of systemctl support in WSL. In this article, we will guide you through the process of running Elasticsearch on Ubuntu on WSL using Docker.

Prerequisites

Before we start, make sure you have the following installed on your machine:

  • Windows Subsystem for Linux (WSL) with Ubuntu
  • Docker Desktop for Windows

If you haven’t installed these yet, you can find the installation guides on the Microsoft WSL Documentation and Docker Desktop for Windows Documentation respectively.

Step 1: Install Docker on WSL

Once you have WSL and Docker Desktop installed, you need to ensure that Docker is running properly on WSL. You can do this by running the following command in your WSL terminal:

docker run hello-world

This command will download a test image and run it in a container. If Docker is installed correctly, it will display a “Hello from Docker!” message.

Step 2: Increase the mmap limits

Elasticsearch uses a mmapfs directory by default to store its indices. The default operating system limits on mmap counts might be too low, which could result in out of memory exceptions. To increase the mmap limit, run the following command:

sudo sysctl -w vm.max_map_count=262144

vm.max_map_count is a Linux kernel setting that defines the maximum number of memory map areas a process may have. The -w flag writes the changes to the system immediately.

Step 3: Create a Docker network for Elasticsearch

Creating a Docker network for Elasticsearch will allow your Elasticsearch container to communicate with other containers. Run the following command to create a new network:

docker network create elastic

The network create command creates a new Docker network. elastic is the name we’re giving to this network.

Step 4: Start Elasticsearch

Now, let’s start Elasticsearch using the Docker image provided by Elasticsearch. Run the following command:

docker run --name es01 --net elastic -p 9200:9200 -p 9300:9300 -it docker.elastic.co/elasticsearch/elasticsearch:8.4.1

Here’s what each parameter does:

  • --name es01: This names the container “es01”.
  • --net elastic: This connects the container to the “elastic” network we created earlier.
  • -p 9200:9200 -p 9300:9300: These flags map the container’s ports 9200 and 9300 to the host’s ports 9200 and 9300 respectively. Port 9200 is the default port for HTTP communication, while port 9300 is used for node-to-node communication.
  • -it: This flag ensures that you can interact with the container via the terminal.
  • docker.elastic.co/elasticsearch/elasticsearch:8.4.1: This is the Docker image for Elasticsearch version 8.4.1.

Step 5: Run Kibana

Kibana is a data visualization dashboard for Elasticsearch. It’s useful for visualizing and navigating through your Elasticsearch data. To run Kibana, open a new WSL terminal session and run the following command:

docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.4.1

Similar to the Elasticsearch command, this command names the container “kib-01”, connects it to the “elastic” network, and maps the container’s port 5601 to the host’s port 5601. Port 5601 is the default port for Kibana.

Step 6: Clean Up

To keep your Docker environment clean, it’s good practice to remove containers that are no longer in use. First, list all containers with the following command:

docker ps --all

Then, remove any containers you don’t need anymore:

docker rm <exited_container_name_or_id>

Replace <exited_container_name_or_id> with the name or ID of the container you want to remove.

Conclusion

By following these steps, you should now have a working instance of Elasticsearch running on Ubuntu on WSL without systemd. Remember to keep your Docker environment clean by removing unused containers, and enjoy exploring your data with Elasticsearch and Kibana!

Can I run Elasticsearch on Windows Subsystem for Linux (WSL) without systemd?

Yes, you can run Elasticsearch on WSL without systemd by using Docker. Follow the steps outlined in this article to set it up.

Do I need to have Docker installed on WSL to run Elasticsearch?

Yes, Docker is required to run Elasticsearch on WSL. Make sure you have Docker Desktop for Windows installed and running properly on your WSL environment.

What is the purpose of increasing the mmap limits for Elasticsearch?

Elasticsearch uses a mmapfs directory to store its indices. Increasing the mmap limits ensures that Elasticsearch has enough memory map areas to function properly and avoid out of memory exceptions.

How do I create a Docker network for Elasticsearch?

To create a Docker network for Elasticsearch, use the command docker network create <network_name>. In the article, we used docker network create elastic to create a network named "elastic".

Which version of Elasticsearch is used in the provided Docker command?

The Docker command in the article uses Elasticsearch version 8.4.1. You can change the version by modifying the tag in the command to match the desired version.

What is Kibana used for?

Kibana is a data visualization dashboard that works with Elasticsearch. It allows you to explore, analyze, and visualize your data stored in Elasticsearch.

How do I remove unused Docker containers?

To remove unused Docker containers, use the command docker rm <container_name_or_id>. You can list all containers with the command docker ps --all to identify the containers you want to remove. Replace <container_name_or_id> with the name or ID of the container you want to remove.

Leave a Comment

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