Etcd Learning (2) cluster building Clustering

Source: Internet
Author: User
Tags etcd

1. Single etcd node (for test and Development)

I used to develop and test an etcd node, and started the command to directly create an etcd (I have added the bin directory of the etcd installation directory TO THE PATH environment variable ), then, the startup information shows that the etcd server listens on the default port 4001 and the peer server listens on the default port 7001.


2. Three etcd nodes form Clustering

To test the cluster function today, follow the tutorial above in guthub:

Reference: https://github.com/coreos/etcd/blob/master/Documentation/clustering.md

Let start by creating 3 new etcd instances.

We use-peer-addrTo specify server port and-addrTo specify client port and-data-dirTo specify the directory to store the log and info of the machine in the Cluster:

./etcd -peer-addr 127.0.0.1:7001 -addr 127.0.0.1:4001 -data-dir machines/machine1 -name machine1

Note: If you want to run etcd on an external IP address and still have access locally, you'll need to add-bind-addr 0.0.0.0So that it will listen on both external and localhost addresses. A similar argument-peer-bind-addrIs used to setup the listening address for the server port.

Let's join two more machines to this cluster using-peersArgument. A single connection to any peer will allow a new machine to join, but multiple can be specified for greater resiliency.

./etcd -peer-addr 127.0.0.1:7002 -addr 127.0.0.1:4002 -peers 127.0.0.1:7001,127.0.0.1:7003 -data-dir machines/machine2 -name machine2./etcd -peer-addr 127.0.0.1:7003 -addr 127.0.0.1:4003 -peers 127.0.0.1:7001,127.0.0.1:7002 -data-dir machines/machine3 -name machine3

Note:

We can also get the current leader in the Cluster:

curl -L http://127.0.0.1:4001/v2/leader

We can retrieve a list of machines in the cluster using the http api:

curl -L http://127.0.0.1:4001/v2/machines

Open the three terminals and run the above three commands in the original version.

Then, execute the get operation to view the content of the node I added to a single node:

curl -L http://127.0.0.1:4002/v2/keys/configA
The result shows that the key not found prompts that adding two nodes to form a cluster on the basis of the original node will lead to data loss?

After studying this command, I found that the data storage path was specified. I guess:

(1) As long as the etcd command <IP, port> is run at the same time, multiple etcd nodes can be started at the same time.

(2) Instant Start starts on the same <IP, port> at different times. As long as the data path is specified differently, it is not the same etcd node.


So I decided to turn off the three terminals that I just opened, or run the etcd command I used earlier (I do not know which data path to start by default ), then, execute the get operation to view the content of the node I added to a single node:

curl -L http://127.0.0.1:4002/v2/keys/configA

It seems that the three etcd nodes that I started later constitute clustering have no relationship with the etcd node I started earlier, because they do not use the same data path.


3. Three etcd nodes form clustering data persistence

The three etcd cluster nodes have been turned off just now, and now the three nodes are restarted. It is found that all the previously written nodes and values are still present, indicating that there is no problem with durability.

Then, I found the machines directory under the/home directory, deleted all the three following machines, machine2, and machine3, and started the cluster with the preceding three commands again, view the previously added node again and find that the node does not exist. This indicates that the cluster data is stored under the specified data path.

Note: To completely reuse your etcd server, clear all the previous data and delete the directory.


4. The three etcd nodes that should be accessed by clustering (for Operation requests)

Any of the three can be, even if it is not a leader


5. Three nodes are required to form clustering?

Not complete...


6. If the nodes in the cluster are distributed across multiple machines, will the results be the same?

Not complete...


Etcd Learning (2) cluster building Clustering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.