2

I'm using WSL on Windows 11 (with Ubuntu 22.04 LTS) and trying to use Elasticsearch on it. When I run sudo systemctl start elasticsearch.service, I get the error:

System has not been booted with systemd as init system (PID 1). Can't operate.

I understand systemctl is not available on WSL. So, I tried its alternative, service elasticsearch start, but then I get the error: elasticsearch: unrecognized service.

I understand there's been similar phrased questions on this website but I have already tried the alternative command but it's not working. So, please help how I can resolve this issue.

NotTheDr01ds
  • 22,082
Zain
  • 23
  • 1
  • 3

1 Answers1

0

While I'm sure it's possible to bring Elasticsearch up directly on Ubuntu on WSL, (a) I haven't done it, and (b) there's likely an easier way.

Elasticseach provides a Docker image with all dependencies.

To install and run it, I used a slightly modified form of the Elasticsearch doc for WSL:

  • Install Docker Desktop for Windows

  • Restart Ubuntu

  • Increase the mmap limits with:

    sudo sysctl -w vm.max_map_count=262144
    

    See this Stack Overflow question/answer for information on how to persist this.

  • Create a Docker network for Elasticsearch with:

    docker network create elastic
    
  • Start Elasticsearch with:

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

    The first time you run it, it will pull the images as well, so there will be a slight delay. This won't occur on subsequent runs.

  • Make a note of (i.e. copy to Notepad or something else) the tokens that are displayed, as they will start to scroll off the page once other operations start to occur (e.g. you run Kibana).

  • Run Kibana in a separate Ubuntu on WSL session (e.g. new tab in Windows Terminal) via:

    docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.4.1
    
  • When done, remember to clean up old containers with:

    docker ps --all
    docker remove <exited_container_name_or_id>
    
NotTheDr01ds
  • 22,082