A, zookeeper working mechanism

zookeeper working mechanism

Zookeeper is distributed services architecture, it is a subproject apache hadoop, mainly used to solve data management problems it encountered in distributed applications, such as cluster management, unified naming service, distributed configuration management, distributed message queue, distributed lock, distributed notification and coordination

Zookeeper no specific function, his role in the coordination of large data is big data framework, providing a coordinated service

Zookeeper's working mechanism:
Zookeeper from the design point of view, is a server-based distributed management framework Observer pattern design, he is responsible for storing and managing data, and then accept the registration of the observer, once these data changes state, zookeeper will responsible for notifying those observers have been registered on the zookeeper, react accordingly.
All in all, we zookeeper only need to do two things.
The first thing: the data stored in
second thing: notice

Understand: that is, between students and lecturers need to communicate with the teacher, appointment of course, but because something can not be a lecturer, teacher this time the need to coordinate and inform the students, the class teacher's role is the role of zookeeper,

在实际中的应用:
  Server1    server2   server3

  Client1     client2    client3

三台server,是一个集群, 没有zookeeper的时候,三个client会直接连接三个server,中间没有任何东西,就是直连,但是当serverA 挂了之后,client1是不知道的,client1还是会连接serverA,但是serverA根本不会理client1,

如果我们加上zookeeper集群之后,结构如下:
  Server1    server2   server3
             | 1、(服务端在启动时去注册信息,将自己的信息保存到zookeeper里边)
        zookeeper集群(类似于中间件)
             | 2、(client从zookeeper获取当前在线服务器列表,并注册监听)
  Client1     client2    client3

我们上边说了,zookeeper干两件事,一件事是存数据,一件事是通知,三台server,会把自己提供的服务和端口的信息,保存到zookeeper里边 ,

Client就是从zookeeper里边读取数据,看哪台能够正常连接

**
1、服务端在启动时去注册信息,将自己的信息保存到zookeeper里边
2、client从zookeeper获取当前在线服务器列表,并注册监听
3、server2挂了,
4、zookeeper会主动通知在在zk上注册的主机,就是三台client,告诉他们server2 已经挂了,这就是zk完成的第二件事
5、zk进行通知了之后,三个client,会再次向zookeeper进行注册监听,这是zookeeper提供服务的一个过程
**

Zookeeper = + file system notification mechanism zookeeper is to achieve the coordination of these two functions, (file system that store data)

Guess you like

Origin blog.51cto.com/13930997/2454349