"Zookeeper Linux Cluster Service"

Source: Internet
Author: User
Tags zookeeper

Today is Christmas Eve, first wish everyone happy Christmas Eve, since the girlfriend seems to be just Christmas Eve, haha, open a joke. Christmas Eve will be over, essays must also be written. In this article we will talk about Zookeeper Linux clusters.

Why cluster? Because one service is not enough. Cluster is for system expansion, system stability. A service hangs up, it's okay, I have other services. Clustering can bring many benefits, such as high availability, high concurrency, high traffic, but it also has its drawbacks. Because it is more than one server, how to ensure that the data on each server is consistent and the transaction becomes a problem. But Zookeeper helped us solve these problems, we will discuss the consistency and the affairs in detail later, enough to write many essays.

The previous essay is to write a standalone service, that is, a single server to provide services. The Zookeeper directory is/usr/local/src/zookeeper/zookeeper-3.4.6. We want to cluster now, so we need at least 3 Zookeeper registries. Let's take a look at my 3 registry directories,/usr/local/src/zookeeper/zookeeper-3.4.9,/usr/local/src/zookeeper/zookeeper-3.4.9.slave,/usr/ local/src/zookeeper/zookeeper-3.4.6. First of all to ensure that each registry can be a separate normal service, in fact, the difference between the cluster and monomer is the configuration, the monomer configuration is simple, the cluster configuration must contain other registry information.

Let's take a look at the/usr/local/src/zookeeper/zookeeper-3.4.6 configuration file:

focus on the last, server.1=127.0.0.1:2881:3881, server.2=127.0.0.1:2882:3882, server.3=127.0.0.1:2883:3883. For server reasons, my 3 registries were placed on the same server. Server.1, Server.2, and SERVER.3 represent 3 different registry service names. 1, 2, 3 indicates the identification code of 3 registry.

Rule server. n=IP:a:b,n means that the identification code is the encoding, IP represents the service address, A is the LF communication port, that is, with the Leader communication port, B is the election port. Since it is a cluster, you need to have a leader, others are followers. Who will be the leader, this needs an election, so B port is required. With leadership, need and leadership communication requires a dedicated communication port, which is A. As for why not set a and B to the same port, I personally think that if set to a port, port problems, it will not be able to communicate with the leader, and can not be elected. This is very likely to make the entire cluster unusable, although you have N servers, but under the half-election principle it is very likely that the leader will not be elected.

Because I'm on the same server, all I can see is that the A and B ports of Server.1, SERVER.2, server.3 are different. If it is placed on a different server, such as server.1=192.168.0.1:2881:3881, server.2=192.168.0.2:2881:3881, server.3=192.168.0.3:2881:3881, then A and B port can be the same.

Continue the above topic, Server.1, Server.2, SERVER.3, how to know/usr/local/src/zookeeper/zookeeper-3.4.6 is which service it? Can see Datadir=/usr/local/src/zookeeper/zookeeper-3.4.6/data, in the data directory below we want to produce a file called myID, which stores the service representation code, that is, the code.

This is 1, that is, Server.1 is/usr/local/src/zookeeper/zookeeper-3.4.6 service, 127.0.0.1:2881:3881, communication port 2881, election port 3881.

The other two/usr/local/src/zookeeper/zookeeper-3.4.9,/usr/local/src/zookeeper/zookeeper-3.4.9.slave, are the same.

We start all the registries and then JPS to see.

Finally we have to remember to add 2181, 2182, 2183 ports to the firewall rules, as in the previous article,-a rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 2181-j ACC EPT. Restart the firewall.

OK, let's try to see if the cluster is successful. First register the Dubbo service to the cluster and then randomly call through the Dubbo client to see if the registry that provides the service is different.

First look at Dubbo Service registration:  

<dubbo:applicationname= "Demo-provider"/><Dubbo:registryID= "Test"Group= "Test"Protocol= "Zookeeper"Address= "192.168.0.106:2181,192.168.0.106:2182,192.168.0.106:2183" /><Dubbo:protocolname= "Dubbo"Port= "20881"/><Dubbo:serviceInterface= "Www.test.com.dubbo.xml.IUser"ref= "UserService"version= "0.0.1"/><BeanID= "UserService"class= "Www.test.com.dubbo.xml.UserImpl"/>

Dubbo Client Subscriptions:  

<dubbo:applicationname= "Demo-consumer"/><Dubbo:registryProtocol= "Zookeeper"ID= "Test"Group= "Test"Address= "192.168.0.106:2181,192.168.0.106:2182,192.168.0.106:2183"/><dubbo:referenceID= "UserService"Interface= "Www.test.com.dubbo.xml.IUser"version= "0.0.1"/>

let's see if the Dubbo service is registered successfully.  

Yes, Dubbo%3a%2f%2f192.168.0.102%3a20881%2fwww.test.com.dubbo.xml.iuser, this is the Dubbo service provider address.

Let's get a random service to see which registry is serving.

First time get

Second time acquisition

Third time get

Ok,linux cluster on to here, thank you for watching, hope to help!

"Zookeeper Linux Cluster Service"

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.