• 1、Zookeeper熟悉和用途综述


    集群 配置:
    
    192.168.32.80  192.168.32.81  192.168.32.82
    
    server 1:
    zjtest7-redis:/opt/zookeeper/conf# cat zoo.cfg  | grep -v "^#"
    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/server1/data
    dataLogDir=/opt/zookeeper/server1/logs
    clientPort=2181
    server.1=192.168.32.80:2888:3888
    server.2=192.168.32.81:2888:3888
    server.3=192.168.32.82:2888:3888
    
    
    server 2:
    
    zjtest7-redis2:/opt/zookeeper/conf# cat zoo.cfg  | grep -v "^#"
    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/server2/data
    dataLogDir=/opt/zookeeper/server2/logs
    clientPort=2181
    server.1=192.168.32.80:2888:3888
    server.2=192.168.32.81:2888:3888
    server.3=192.168.32.82:2888:3888
    
    
    server 3:
    
    zjtest7-haproxy:/opt/zookeeper/conf# cat zoo.cfg  | grep -v "^#"
    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/server3/data
    dataLogDir=/opt/zookeeper/server3/logs
    clientPort=2181
    server.1=192.168.32.80:2888:3888
    server.2=192.168.32.81:2888:3888
    server.3=192.168.32.82:2888:3888
    
    
    
    
    一个zookeeper 集群 只有一个leader: 类似master/slave模式
    
    
    
    
    
    
    /**192.168.32.80 follower
    zjtest7-redis:/opt/zookeeper/conf# telnet 192.168.32.80 2181
    Trying 192.168.32.80...
    Connected to 192.168.32.80.
    Escape character is '^]'.
    stat
    Zookeeper version: 3.4.8--1, built on 02/06/2016 03:18 GMT
    Clients:
     /192.168.32.80:54168[0](queued=0,recved=1,sent=0)
     /127.0.0.1:59950[1](queued=0,recved=23550,sent=23550)
    
    Latency min/avg/max: 0/0/111
    Received: 25815
    Sent: 25814
    Connections: 2
    Outstanding: 0
    Zxid: 0x10000000b
    Mode: follower
    Node count: 4
    Connection closed by foreign host.
    
    
    
    /***192.168.32.81 leader
    
    zjtest7-redis:/opt/zookeeper/conf# telnet 192.168.32.81 2181
    Trying 192.168.32.81...
    Connected to 192.168.32.81.
    Escape character is '^]'.
    stat
    Zookeeper version: 3.4.8--1, built on 02/06/2016 03:18 GMT
    Clients:
     /192.168.32.80:40376[0](queued=0,recved=1,sent=0)
    
    Latency min/avg/max: 0/0/0
    Received: 2
    Sent: 1
    Connections: 1
    Outstanding: 0
    Zxid: 0x10000000b
    Mode: leader
    Node count: 4
    Connection closed by foreign host.
    
    
    
    /*******192.168.32.82
    zjtest7-redis:/opt/zookeeper/conf# telnet 192.168.32.82 2181
    Trying 192.168.32.82...
    Connected to 192.168.32.82.
    Escape character is '^]'.
    stat
    Zookeeper version: 3.4.8--1, built on 02/06/2016 03:18 GMT
    Clients:
     /192.168.32.80:56173[0](queued=0,recved=1,sent=0)
    
    Latency min/avg/max: 0/0/0
    Received: 2
    Sent: 1
    Connections: 1
    Outstanding: 0
    Zxid: 0x10000000b
    Mode: follower
    Node count: 4
    Connection closed by foreign host.
    zjtest7-redis:/opt/zookeeper/conf# 
    
    
    客户端提交请求之后,先发送到leader,leader作为接收者,广播到每个server
    
    
    
    znode :
    节点/NameService/Server1 唯一路径(Node),且携带数据
    
    即是目录又是文件
    
    临时节点,不能有子节点
    
    znode节点变化的时候,可以出发事件
    
    
    
    
    zookeeper 节点:znode
    
    
    每个watcher 就是服务器集群中的一台机器
    
    
    zookeeper 应用场景:
    
    zk 保存Storm集群的所有数据
    
    Storm集群:Zookeeper作为nimbus(master)和supervisor(slave)的中间枢纽,
    保存Storm集群和作业的所有信息,并负责nimbus和supervisor的全部通信,
    Fast faill 。
    
    
    Zookeeper 作为master和slave之间唯一的通道,
    
    消息提交到master上,master会把消息发送给zookeeper,zk在分发到每个slave
    
    
    
    
    发布与订阅即所谓的配置管理,顾名思义就是将数据发布到zk节点上,供订阅者动态获取数据,
    实现配置信息的集中式管理和动态更新。例如全局的配置信息,地址列表等就非常适合使用。
    
    
    每天节点自动从zk获取
    
    
    
    一个节点是全局唯一的path
    
    
    
    zk 创建节点:
    
    客户端访问:
    
    redis01:/root# cd /zookeeper/server1
    redis01:/zookeeper/server1# cd bin/
    redis01:/zookeeper/server1/bin# ./zkCli.sh -server localhost:2181
    
    
    2 )创建一个新的 znode ,使用 create /zk myData 。这个命令创建了一个新的 znode 节点“ zk ”以及与它关联的字符串:
    
    
    
    
    在leader 上创建: create /zk myData
    
    会自动同步到所有服务器
    
    
    
    在folloer上创建:也会同步到leader
    
    
    
    一个节点上的数据发生变化后,通知其他节点
    
    
    watch 监听节点变化
    
    
    zk集群上相同的znode数据一定是相同的
    
    

  • 相关阅读:
    ubuntu
    ubuntu
    ubuntu14.04,安装Gnome 15.10 (桌面)
    ubuntu14.04,安装Gnome 15.10 (桌面)
    Ubuntu 14.04.3 LTS如何安装谷歌输入法
    Ubuntu 14.04.3 LTS如何安装谷歌输入法
    ubuntu 安装 删除 卸载 Deb 包文件
    失去爆破音规律
    单词发音规律
    英式音标和美式音标的差异
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199571.html
Copyright © 2020-2023  润新知