zookeeper build a cluster analysis and principle

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

A, zookeeper sources:

Zookeeper is an open source implementation of chubby google is distributed

Two, zookeeper definition:

Distributed Coordination Service

Three, zookeeper architecture:

Here Insert Picture Description
3.1 Role
Here Insert Picture Description
3.2, Watcher (listening) mechanismHere Insert Picture Description
(1) there is a write request, the request is passed follower
(2) fllower forwards the request to the Leader
(3) Leader will request onward transport follower, vote
(4) follower his thoughts returned to the leader
Precautions: majority
principle: the principle --------------- node more than half of the singular best
3.3, features a zookeeper
· final consistency
in distributed systems , after some time, eventually data between nodes in a consistent state characteristics.
Note: The data over time will eventually reach an agreement
· atomic
update only success or failure, there is no intermediate state characteristic
note: there is no intermediate status update affairs
· reliability
in ZooKeeper, if the message was accepted a server, it will It accepted all server features.
Note: The message was either accept all Zookeeper servers, either all of the server does not accept Zookeeper
* real-time
Zookeeper ensure the client gets just updated features.
Note: The client obtains the data must be Zookeeper just a cluster of new
-order of
all ZooKeeper Server end, consistent with the sequential nature of a news release
Note: Each Zookeeper not necessarily receive data at the same time, but each internal Zokeeper order of the data received are consistent
3.4, zab protocol
broadcast mode
has been elected leader, began to provide services
recovery mode
no leader (cluster has just started, leader of a newly dead yet up)
looking - wait and see
fllowing - but follow the idea fllower
leading - - heir (ready to be inherited) Leader
observering the Observer
3.5, the file node znode-zookeeper's
definitions: znode is a data storage unit Zookeeper data
classification:
long: always there, zookeeper restart will not be lost even if
temporary (-e): when the customer end created znode, only occupied with this client, once the client stops, disconnect, temporary znode will be deleted
sequence (-s): prevent name collisions, the node will follow after a 10-digit sequence number
to start client end:
zkCli.sh -server IP: Port (2181)
3.6, and programming commands ZooKeeper
1. command
1.1 connection specified ZooKeeper
./zkCli.sh -server IP: Port (2181)
1.2 command Action
ls /: List "/ "the following other nodes
create -e / name1 xiaozhang create temporary node, exit or quit by the end of the command, the session node disappear
create -s / name2 xiaowang order to create a node
creae -e -s / name3 xiaoli create temporary data nodes
get / name acquired by node name
rmr / name specifies the name of the deleted node
/ name3 xiaoxiao content node set the SET
1.3 program
development steps:
eclipes established java project ------> Add zookeeper designed to jar package to the build path -------> create java class ------> write code ----- "zookeeper cry with customers operating zookeeper side objects
created zookeeper client object
Zookeeper client = new Zookeeper ( "192.168.110.131 ", 1000, null)
refer to: ip, timeout, listening

//创建节点
/*String create = client.create("/name", "kk".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
System.out.println(create);*/	

/ name designated to create a znode node name in the "/" under
Ids.OPEN_ACL_UNSAFE permission is granted to everyone outside of all ADMIN
CreateMode.PERSISTENT specified node is created persistent node

 //获取指定节点
  /*byte[] data = client.getData("/name/sex", true, null);
   String string = new String(data);
   System.out.println(string);*/

  //设置指定节点内容
  //Stat stat = client.setData("/name", "2222".getBytes(), client.exists("/name", true).getVersion());
  
  //获取指定节点子节点
/*List<String> list = client.getChildren("/name", true);
  for (String str : list) {
    System.out.println(str);
    }*/
    
   //删除指定节点
    client.delete("/name",-1);

Guess you like

Origin blog.csdn.net/power_k/article/details/92800307