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
  • 17,888
Zain
  • 23
  • Elastic's response to this issue: https://discuss.elastic.co/t/how-do-you-configure-elasticsearch-on-ubuntu-bash-for-windows-10/194888/3 . This is an Elastic issue, not an Ubuntu issue. – user535733 Sep 06 '22 at 11:27
  • Sorry, retracted that last comment - I see that even the unit file points to a systemd dependency. There's probably still a way to run it manually, but it isn't necessarily obvious from the unit file. – NotTheDr01ds Sep 06 '22 at 14:08
  • Well, I installed elasticsearch 7 and it's working now. It was giving the problem on version 8 – Zain Sep 06 '22 at 14:24
  • Writing up an answer now for 8.4.1 if you're willing to use Docker. – NotTheDr01ds Sep 06 '22 at 14:29
  • Also would recommend you add a self-answer for the "use version 7" option. – NotTheDr01ds Sep 06 '22 at 14:41

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
  • 17,888