Start and stop elasticsearch nodes in windows
Asked Answered
T

3

9

I am trying to start elasticsearch as a process and stop it without closing the command prompt. For creating a new process, I am using:

C:\Users\User1\Desktop\Work\ElasticSearch\elasticsearch-1.3.1\bin>start /B elasticsearch
C:\Users\User1\Desktop\Work\ElasticSearch\elasticsearch-1.3.1\bin>start /B elasticsearch
C:\Users\User1\Desktop\Work\ElasticSearch\elasticsearch-1.3.1\bin>[2014-08-19 15:23:26,351][WARN ][bootstrap                ] jvm uses the c
lient vm, make sure to run `java` with the server vm for best performance by adding `-server` to the command line
[2014-08-19 15:23:26,433][INFO ][node                     ] [Batroc the Leaper] version[1.3.1], pid[5800], build[2de6dc5/2014-07-28T14:45:15
Z]

The process runs on port 9200.

How can I get the process PID or name to use taskkill to kill this process using this command or something similar from either the already open command prompt or the existing command prompt in which the elasticsearch node process is running:

taskkill /PID <pid>

Pid of 5800(shown in process log in console above) did not work. Windows task manager did not have a process by the name elasticsearch. It only has a cmd process for the command prompt in which the elasticsearch is running and when I kill that process, the elasticsearch also gets killed.

Tribble answered 20/8, 2014 at 17:5 Comment(0)
H
5

I'd install and run Elasticsearch as a Windows service:

Windows users can configure Elasticsearch to run as a service to run in the background or start automatically at startup without any user interaction. This can be achieved through service.bat script under bin/ folder which allows one to install, remove, manage or configure the service and potentially start and stop the service, all from the command-line.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-service-win.html

It let's you run commands like start and stop to run and terminate elasticsearch from a script without having to track process ids or keep the same command prompt open.

UPDATE:

To run multiple instances of Elasticsearch at the same time as services you will need to pass in a unique serviceid when installing the service:

The script requires one parameter (the command to execute) followed by an optional one indicating the service id (useful when installing multiple Elasticsearch services).

Regarding what port and IP address ES is running on it should be no different - but I'd check your config files (elasticsearch.yml) and your logging config (logging.yml). More detail on configuration options here:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html

Hydrocele answered 20/8, 2014 at 17:29 Comment(4)
There are two issues with this: 1. When running elastic search as a service, I am not able to ping to the node from outside the system on which it is running. Whereas if the node is started from command prompt, the console output shows the IP address and port number at which this process is running. I am able to ping the node with that info. How can we figure out the port on which the service is running? How can that be contacted from outside(since it appears it is only running locally)? 2. How can I start multiple nodes as a service using the service.bat/service manager and their features?Tribble
Thanks for the pointers. But starting as a service is not visible outside. Locally I am able to go to 10.128.48.123:9200(the logs show this IP address and port). But this IP and port is not open for an outside client. Should I do anything additionally to open up the service to the outside clients?Tribble
Set your network host to the IP address you want to bind to: elasticsearch.org/guide/en/elasticsearch/reference/current/…Hydrocele
Thanks for the comment. Answering my own question, I had to add elasticsearch to the allowed list of programs to Windows firewall settings. Instructions are here: sevenforums.com/tutorials/…Tribble
T
6

If you Installing Elasticsearch as a Service on Windows, you can start/stop from the Services control panel, more info like start/stop use CMD see in the link.

enter image description here


The way above is convenient and correct. I try some other ways to stop ElasticSearch and record here,

Before knowing the method above, first I guess ElasticSearch may be a process in the Task Manager, so I found by name and really found a process name ElasticSearch.exe, but after I kill that process, I still can get ElasticSearch Info from http://localhost:9200/ which is the ElasticSearch port on my computer, that means ElasticSearch is still running.

Later I came up with that maybe I can kill it by port, I find an article using PowerShell to kill process by port, so I start a PowerShell, then execute Stop-Process -Id (Get-NetTCPConnection -LocalPort 9200).OwningProcess -Force, and it tells me:

Stop-Process : Cannot stop "java (22356)" process,Access Denied。 + Stop-Process -Id (Get-NetTCPConnection -LocalPort 9200).OwningProcess ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (System.Diagnostics.Process (java):Process) [Stop-Process],ProcessCommandException

it might caused by not run as Administrator, but from the information I can tell that the real process running ElasticSearch is java.exe, and its process ID is 22356, after killing java.exe using Task Manager, I cannot connect to http://localhost:9200/, that mean I successfully stopped ElasticSearch.

Townswoman answered 4/7, 2018 at 4:34 Comment(0)
H
5

I'd install and run Elasticsearch as a Windows service:

Windows users can configure Elasticsearch to run as a service to run in the background or start automatically at startup without any user interaction. This can be achieved through service.bat script under bin/ folder which allows one to install, remove, manage or configure the service and potentially start and stop the service, all from the command-line.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-service-win.html

It let's you run commands like start and stop to run and terminate elasticsearch from a script without having to track process ids or keep the same command prompt open.

UPDATE:

To run multiple instances of Elasticsearch at the same time as services you will need to pass in a unique serviceid when installing the service:

The script requires one parameter (the command to execute) followed by an optional one indicating the service id (useful when installing multiple Elasticsearch services).

Regarding what port and IP address ES is running on it should be no different - but I'd check your config files (elasticsearch.yml) and your logging config (logging.yml). More detail on configuration options here:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html

Hydrocele answered 20/8, 2014 at 17:29 Comment(4)
There are two issues with this: 1. When running elastic search as a service, I am not able to ping to the node from outside the system on which it is running. Whereas if the node is started from command prompt, the console output shows the IP address and port number at which this process is running. I am able to ping the node with that info. How can we figure out the port on which the service is running? How can that be contacted from outside(since it appears it is only running locally)? 2. How can I start multiple nodes as a service using the service.bat/service manager and their features?Tribble
Thanks for the pointers. But starting as a service is not visible outside. Locally I am able to go to 10.128.48.123:9200(the logs show this IP address and port). But this IP and port is not open for an outside client. Should I do anything additionally to open up the service to the outside clients?Tribble
Set your network host to the IP address you want to bind to: elasticsearch.org/guide/en/elasticsearch/reference/current/…Hydrocele
Thanks for the comment. Answering my own question, I had to add elasticsearch to the allowed list of programs to Windows firewall settings. Instructions are here: sevenforums.com/tutorials/…Tribble
W
0

You can stop it using net stop elasticsearch

First open powershell as admin the run the command below:

net stop elasticsearch
Western answered 13/5, 2022 at 18:44 Comment(1)
It says, service name is invalid.Anthracoid

© 2022 - 2024 — McMap. All rights reserved.