20

How can I have multiple nodes in my ElasticSearch? I'm using the following in elasticsearch.yml but only the last node starts, and the browser complains: The page at file://localhost/ says: undefined.

node.name: "No Data"
node.master: true
node.data: false

node.name: "Data One"
node.master: false
node.data: true

node.name: "Data Two"
node.master: false
node.data: true
Michael
  • 13,838
  • 18
  • 52
  • 81

4 Answers4

36

I think the simplest way to do it is by specifying these parameters on the command line. To start three nodes you just need to run the following three commands in elasticsearch home directory:

$ bin/elasticsearch -Des.node.data=false -Des.node.master=true -Des.node.name=NoData
$ bin/elasticsearch -Des.node.data=true -Des.node.master=false -Des.node.name=DataOne
$ bin/elasticsearch -Des.node.data=true -Des.node.master=false -Des.node.name=DataTwo

Another solution is to create 3 different config files and start three nodes with -Des.config=path-to-config-file parameter.

imotov
  • 28,277
  • 3
  • 90
  • 82
  • Great, I was able to start them that way and the 'Overview' page shows all three nodes. However cluster health is red and my indexes are all Unassigned. – Michael Nov 20 '12 at 18:15
  • 2
    Sorry, didn't realized it's done on existing cluster. It happens because you already started data node as the first node before. So all your data is store in the directory `data/elasticsearch/0`. Now that you started master first, it "took" this directory but because it's non-data node, it couldn't use data there. You can shut down all nodes rename directory `0` into `1` and `1` into `0` and start all nodes again in the same order. This way your data will be in the node that start the second. If data is important, it might be a good idea to make an extra copy of directory 0 before you start. – imotov Nov 20 '12 at 18:33
  • Thanks for the explanation. I restarted it as you said and all nodes loaded fine but they didn't load the data so I deleted the indices directory (data wasn't important), restarted, and now when I load data again it's being distributed between the two data nodes. Just what I wanted. Thanks again! – Michael Nov 21 '12 at 10:35
  • And then how would you go about accessing the different nodes from your elasticsearch client? Would they just be on different ports? – kalenjordan Oct 11 '13 at 19:43
  • Sorry that might have been a dumb question. I think for what I'm trying to accomplish I just need to create separate indexes a la what they said here: http://stackoverflow.com/questions/11404637/multiple-elasticsearch-indexes – kalenjordan Oct 11 '13 at 19:45
  • @kalenjordan By default these nodes will be listening for REST requests on ports 9200, 9201 and 9202. – imotov Oct 11 '13 at 21:05
  • Yep, got that, thanks. At first I was thinking that I should setup one instance on one port for staging and another instance on another port for prod, but realized it would probably be better to use the same instance for both and simply use a different index for staging vs. prod. – kalenjordan Oct 14 '13 at 18:25
2

First off, you should be trying to access elasticsearch using [http://localhost:9200/][1], if you are using the default port bindings.

I would set up your master node to also be a data node, there is no reason not to. If you are trying to start 3 nodes on a single machine. But, starting 3 nodes all on the same machine doesn't make sense as anything other than an experiment. What are you trying to accomplish?

Paul Sanwald
  • 10,899
  • 6
  • 44
  • 59
  • 1
    Just trying it out locally to see how it works. I'll be testing it out on some servers later to see if there's any benefit of having a no data master node that 'will be the "coordinator" of the cluster' – Michael Nov 21 '12 at 10:47
  • 1
    ok, cool. from my experience, the only advantage to have a "no data" master node, is that you'll have a consistent ip/dns for the machine of the coordinator. because if you run all your data nodes as also available to become master, obviously any of them can be master at any time and you need to figure out which one currently is :). – Paul Sanwald Nov 21 '12 at 16:16
  • 1
    Thanks for the comment. I did test the new setup (1 no data node as master, 2 data nodes with http disabled) and compared its performance against my current setup (3 data nodes) and it performed worse both with read and write. My guess is that it's wasteful to have a node acting just as a 'load balancer' - it's much more useful as another data node. – Michael Nov 22 '12 at 10:02
  • "I would set up your master node to also be a data node, there is no reason not to" - if you are running a very large index (billions of records), there is good reason NOT to use the master as a data node. See slide 9 on https://speakerdeck.com/player/dbd4429ac6f446fd9a67781df52b7300?# – Zack Aug 11 '16 at 01:01
2

In windows for 6.x version, command attributes change to

elasticsearch -EsomeYamlPropety=someValue

First You need change an elasticsearch.yml properties to:

http.port: 9200-9299
transport.tcp.port: 9300-9399
node.max_local_storage_nodes: 2

Because You cant run nodes on single port, and when I try to use command with argument -Ehttp.port=9201 nodes where cant see each other and they create two different clusters with the same name.

Run the first node by a standard command:

.\bin\elasticsearch

Run the second node by command with attributes:

.\bin\elasticsearch -Enode.name=NodeTwo -Enode.master=false
Vlad
  • 1,017
  • 1
  • 15
  • 18
1

for running 3 elasticsearch node on one machine, you should use these configs in elasticsearch.yml file of each node:

for master node :

cluster.name: mycluster
node.name: "node1"
node.master: true
node.data: true
network.host: 127.0.0.1
http.port: 9200-9299
transport.tcp.port: 9300-9399
discovery.zen.minimum_master_nodes: 2

for data nodes :

cluster.name: mycluster
node.name: "data-node-name"
node.master: false
node.data: true
network.host: 127.0.0.1
http.port: 9200-9299
transport.tcp.port: 9300-9399
discovery.zen.minimum_master_nodes: 2

and then u should run each node by :

cd path/to/elasticsearch/bin
path\bin>elasticsearch.bat
siawash
  • 11
  • 3