zookeeper installation,

Zookeeper overview:

ZooKeeper is an open source distributed, to provide coordinated services to distributed applications Apache project.
ZooKeeper from the design point of view to understand the pattern: a distributed service management framework based observer design pattern, which is responsible for data storage and management of concern to everyone, and then accept the registration of the observer, once the status of these data changes, it ZooKeeper He will be responsible for notifying those observers have been registered on the ZooKeeper react accordingly.
For example: a server cluster, a group of clients, all through ZooKeeper registration, if a service node goes down, you can monitor ZooKeeper cluster server down several state and notifies the client.

ZooKeeper features:

1. ZooKeeper: a leader (Leader), more followers (Follower) cluster composed.
2. As long as more than half of the cluster nodes survival, ZooKeeper cluster will be able to normal service.
3. Global data consistency: Each Server retain an identical copy of the data, Client regardless of which connect to the Server, the data are consistent.
4. Update request order from the request to update the same Client execute in the order they were sent.
The atomic data updating, a data update either succeed or fail.
6. real-time, within a certain time frame, Client can read the latest data.

ZooKeeper data structure

ZooKeeper data model structure and the like Unix file systems, a whole can be seen as a tree, each node is called a ZNode. Each ZNode default 1MB capable of storing data, each ZNode are uniquely identified by its path.

ZooKeeper scenarios

Services provided include: unified naming services, unified configuration management, unified cluster management, offline dynamic server node, soft load balancing.

Internal principle of ZooKeeper

Election mechanism
Half mechanism: More than half of the cluster machines to survive, the cluster is available. Therefore, for installation odd ZooKeeper server.
Although ZooKeeper Master and Slave not specified in the configuration file, but when the cluster work, there is a node for the Leader, Follower of other nodes, Leader election mechanism is through internal temporarily produced.
Initialization election mechanism to explain the cluster: a cluster of five servers, for example, when the first server is started, to their vote, then do not meet the half mechanism (configuration file has been configured five servers); a second server starts when, cast their vote, this time still does not meet half of the mechanism, the ticket also voted first server to a second server; a third server to start, cast their votes at this time or do not meet half of the mechanism, so the first, second server will vote for a third server, is now in line with the half mechanism, so Leader for the third server.

ZooKeeper node type

Persistent (Persistent)
persistence directory node:
after ZooKeeper client disconnects the node still exists.
Persistent directory node sequence number
after ZooKeeper client disconnects, the node is still present, but ZooKeeper numbered sequentially to the node name.
Description: Sets the sequence identity when creating znode, appends a value znode name, is a monotonically increasing sequence number counter, maintained by the parent node.
Note: In a distributed system, the sequence number may be used to globally ordered for all events, so that the client may infer the time order of the sequence number by.
2. A short
temporary directory node
after ZooKeeper client is disconnected, the node is removed.
Temporary sequentially numbered directory node
after ZooKeeper client is disconnected, the node is removed, but ZooKeeper to the node names are numbered sequentially.

Principle listener

A) the principle listener Detailed
1. First, there must be a main () thread.
2. Create the main () thread ZooKeeper client, then it will create two threads, one for LAN communication (connet), one for listening (listener).
3. Send events by listening to connect to ZooKeeper thread will be registered.
4. registered in the list of registered listeners ZooKeeper monitor events added to the list.
5. ZooKeeper to monitor or change the data path, this message will be sent to the listener thread.
6. listener internal thread calls the process () method (programmers to write their own way).

B) common monitor
changes 1. monitor node data

  1 get path [watch]


2. monitor changes in the child node changes

  1 ls path [watch]

Write data flow

1. Client write data on Server1 ZooKeeper transmits a write request.
2. If Server1 is not the Leader, it will Server1 received request further forwarded to the Leader, because each of ZooKeeper Server there is a Leader. The Leader will be broadcast to each write request Server, Server after each successful write will notify Leader.
3. When the Leader received most of the Server data write is successful, then that data write success. If the three nodes of the cluster, as long as there are two nodes of data writing is successful, then that data write gong (half mechanism). After write succeeds, Leader will tell Server1 data write success.
4. Server1 will further inform the Client data write is successful, then you believe that the success of the entire write operation.

zookeeper installation

 

zookeeper是java开发的,可以运行在windows,linux环境。安装之前需要先安装号jdk.

安装步骤:
第一步:安装jdk(linux环境下安装jdk的文档在右边栏的文件中)
第二步:把zookeeper的压缩包上传到linux系统。
第三步:解压缩压缩包
tar -zxvf zookeeper-3.4.6.tar.gz
第四步:进入zookeeper-3.4.6目录,创建data文件夹。
第五步:把zoo_sample.cfg改名为zoo.cfg
[root@localhost conf]# mv zoo_sample.cfg zoo.cfg
第六步:修改data属性:dataDir=/root/zookeeper-3.4.6/data
第七步:启动zookeeper
[root@localhost bin]# ./zkServer.sh start
关闭:[root@localhost bin]# ./zkServer.sh stop
查看状态:[root@localhost bin]# ./zkServer.sh status

 

启动命令:./bin/zkServer.sh start

停止命令:./bin/zkServer.sh stop  

重启命令:./bin/zkServer.sh restart

状态查看命令:./bin/zkServer.sh status

zookeeper使用教程:https://www.w3cschool.cn/zookeeper/

Guess you like

Origin www.cnblogs.com/zouhong/p/12290030.html