时间:2023-06-26 10:18:01 | 来源:网站运营
时间:2023-06-26 10:18:01 来源:网站运营
虚拟IP管理系统:[zk: localhost:2181(CONNECTED) 0] create /groups ""Created /groups[zk: localhost:2181(CONNECTED) 1] create /nodes ""Created /nodes[zk: localhost:2181(CONNECTED) 3] create /servers ""Created /servers[zk: localhost:2181(CONNECTED) 4] create /tasks ""Created /tasks[zk: localhost:2181(CONNECTED) 5] ls /[groups, servers, nodes, zookeeper, tasks]
当一个agent服务起来时,会在/nodes下注册一个znode并且watch创建的znode。也会在/tasks下执行同样的操作。# For node1[zk: localhost:2181(CONNECTED) 7] create /nodes/node-192-168-1-4 ""Created /nodes/node-192-168-1-3[zk: localhost:2181(CONNECTED) 9] ls /nodes/node-192-168-1-4 true[]# For node1[zk: localhost:2181(CONNECTED) 7] create /tasks/node-192-168-1-4 ""Created /nodes/node-192-168-1-4[zk: localhost:2181(CONNECTED) 9] ls /tasks/node-192-168-1-4 true[]
# For server[zk: localhost:2181(CONNECTED) 10] create /groups/group1 ""Created /groups/group1[zk: localhost:2181(CONNECTED) 11] create /groups/group1/vips ""Created /groups/group1[zk: localhost:2181(CONNECTED) 12] create /groups/group1/nodes ""Created /groups/group1/nodes[zk: localhost:2181(CONNECTED) 13] create /groups/group1/vips/vip-192-168-1-2 some-configCreated /groups/group1/vips/vip-192-168-1-2[zk: localhost:2181(CONNECTED) 14] create /groups/group1/vips/vip-192-168-1-3 some-configCreated /groups/group1/vips/vip-192-168-1-3[zk: localhost:2181(CONNECTED) 15] create /nodes/node-192-168-1-4/group1 some-configCreated /nodes/node-192-168-1-4/group1[zk: localhost:2181(CONNECTED) 16] create /nodes/node-192-168-1-5/group1 some-configCreated /nodes/node-192-168-1-5/group1[zk: localhost:2181(CONNECTED) 17] create /nodes/node-192-168-1-6/group1 some-configCreated /nodes/node-192-168-1-6/group1
node1因为之前监听了/nodes/node-192-168-1-4这个节点,所以会接受到zookeeper的通知,node1去读取/nodes/node-192-168-1-4下面的znode,更新自己的配置。然后在/groups/group1/nodes下去创建一个临时znode。# For node1WATCHER:: WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/nodes/node-192-168-1-4[zk: localhost:2181(CONNECTED) 18] create -e -s /groups/group1/nodes/node-192-168-1-4 ""Created /groups/group1/nodes/node-192-168-1-4[zk: localhost:2181(CONNECTED) 19] ls /groups/group1/vips[vip-192-168-1-2, vip-192-168-1-3][zk: localhost:2181(CONNECTED) 20] ls /groups/group1/vips/vip-192-168-1-2 true[][zk: localhost:2181(CONNECTED) 21] ls /groups/group1/vips/vip-192-168-1-3 true[]
当server为/groups/group1/vips下面的节点增加子节点时,agent会得到zookeeper的通知,通过获取节点的内容,可以知道自己是不是被server选中,从而选择是否去执行VIP的职责。# For server[zk: localhost:2181(CONNECTED) 5] create -s /tasks/node-192-168-1-4/task- "job definition"Created /tasks/node-192-168-1-4/task-0000000000[zk: localhost:2181(CONNECTED) 6] ls /tasks/node-192-168-1-4/task-0000000000 true[]
node1之前已经监听过了/tasks/node-192-168-1-4,所以会得到zookeeper的通知,这时node1会去读取/tasks/node-192-168-1-4下面的节点,拿到要执行的任务,在执行完成后,在/tasks//tasks/node-192-168-1-4/task-0000000000中添加一个状态znode# For agent[zk: localhost:2181(CONNECTED) 5] create /tasks/node-192-168-1-4/task-0000000000/status "done"Created /tasks/node-192-168-1-4/task-0000000000/status
server因为监听了/tasks/node-192-168-1-4/task-0000000000节点,所以会接到zookeeper的通知,知道任务已经完成。# For server example.shopee.com[zk: localhost:2181(CONNECTED) 11] create /servers/server-shopee-com:1212 ""Created /servers/server-shopee-com:1212
server每次执行关键词:系统,管理,虚拟