提供做网站公司有哪些,房山企业网站建设公司,如何做好网站管理工作,用wp做网站备案文章目录 概述安装LinuxWindows 配置参数集群参考配置文件配置步骤流程启动 概述 Zookeeper#xff1a; 为分布式框架组件提供协调服务的中间件 【类似#xff1a;文件系统通知机制】 负责存储上下层应用关系的数据以及接收观察者注册监听#xff0c;一旦观察查关心的数据发… 文章目录 概述安装LinuxWindows 配置参数集群参考配置文件配置步骤流程启动 概述 Zookeeper 为分布式框架组件提供协调服务的中间件 【类似文件系统通知机制】 负责存储上下层应用关系的数据以及接收观察者注册监听一旦观察查关心的数据发生变化则Zookeeper会将数据变化推送给观察者 官网 https://zookeeper.apache.org/ 组成 Zookeeper由一个领导者(Leader),多个跟随者(Follower)组成的集群 半数以上的节点存活集群才能正常工作并且建议安装奇数台服务器集群 全局数据一致 每个Server保存一份相同的数据副本Client无论连接到哪个Server,数据都是一致的。 实时性 客户端A更新信息到服务端A则客户端B能在一定很快的时间范围内也同步回最新服务端A数据 Zookeeper内部数据结构 树结构每个节点最多存储1MB并且每个数据节点有节点唯一标识进行识别区分 Zookeeper集群同步逻辑 客户端向ZooKeeper集群发送写请求时请求 首先会发送给Leader节点 Leader节点会将该请求广播给所有Follower节点只有当大多数节点包括Leader节点都写入成功后写操作才会被确认为成功并通知客户端客户端收到写入成功响应无需等待集群中所有机器都写入成功只需过半机器写入成功即可后续慢慢会执行同步最终达到zxid一致 从而保证数据的一致性 #mermaid-svg-0yeXyDhcg9ByUvKL {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-0yeXyDhcg9ByUvKL .error-icon{fill:#552222;}#mermaid-svg-0yeXyDhcg9ByUvKL .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-0yeXyDhcg9ByUvKL .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-0yeXyDhcg9ByUvKL .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-0yeXyDhcg9ByUvKL .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-0yeXyDhcg9ByUvKL .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-0yeXyDhcg9ByUvKL .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-0yeXyDhcg9ByUvKL .marker{fill:#333333;stroke:#333333;}#mermaid-svg-0yeXyDhcg9ByUvKL .marker.cross{stroke:#333333;}#mermaid-svg-0yeXyDhcg9ByUvKL svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-0yeXyDhcg9ByUvKL .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-0yeXyDhcg9ByUvKL .cluster-label text{fill:#333;}#mermaid-svg-0yeXyDhcg9ByUvKL .cluster-label span{color:#333;}#mermaid-svg-0yeXyDhcg9ByUvKL .label text,#mermaid-svg-0yeXyDhcg9ByUvKL span{fill:#333;color:#333;}#mermaid-svg-0yeXyDhcg9ByUvKL .node rect,#mermaid-svg-0yeXyDhcg9ByUvKL .node circle,#mermaid-svg-0yeXyDhcg9ByUvKL .node ellipse,#mermaid-svg-0yeXyDhcg9ByUvKL .node polygon,#mermaid-svg-0yeXyDhcg9ByUvKL .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-0yeXyDhcg9ByUvKL .node .label{text-align:center;}#mermaid-svg-0yeXyDhcg9ByUvKL .node.clickable{cursor:pointer;}#mermaid-svg-0yeXyDhcg9ByUvKL .arrowheadPath{fill:#333333;}#mermaid-svg-0yeXyDhcg9ByUvKL .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-0yeXyDhcg9ByUvKL .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-0yeXyDhcg9ByUvKL .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-0yeXyDhcg9ByUvKL .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-0yeXyDhcg9ByUvKL .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-0yeXyDhcg9ByUvKL .cluster text{fill:#333;}#mermaid-svg-0yeXyDhcg9ByUvKL .cluster span{color:#333;}#mermaid-svg-0yeXyDhcg9ByUvKL div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-0yeXyDhcg9ByUvKL :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 身份证 修改数据的次数 投票的轮数 专有名词 SID每个zookeeper的唯一标识则dataDir下面的myid里面的值 ZXID事务ID、标识依次服务器状态的变更 最终Zookeeper集群中ZXID会保持一致 Epoch每个Leader的任期代号 Zookeeper机器每完成一次投票则1 //奇数台解释以及半数以上人同意才可进行一致性读写操作
举个通俗易懂的例子就好比开会需要做决定
如果有5个人参与讨论只要有3个人同意就可以做出决定。
但如果只有4个人参与讨论那么如果有2个人持不同意见就无法做出决定
因此为了确保能够做出决定最好让参与讨论的人数为奇数。这样就能够确保在发生分歧时仍然能够做出决定。架构图
Zookeeper内部数据结构 #mermaid-svg-HRNAJ4GchwiL45Xj {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-HRNAJ4GchwiL45Xj .error-icon{fill:#552222;}#mermaid-svg-HRNAJ4GchwiL45Xj .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-HRNAJ4GchwiL45Xj .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-HRNAJ4GchwiL45Xj .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-HRNAJ4GchwiL45Xj .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-HRNAJ4GchwiL45Xj .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-HRNAJ4GchwiL45Xj .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-HRNAJ4GchwiL45Xj .marker{fill:#333333;stroke:#333333;}#mermaid-svg-HRNAJ4GchwiL45Xj .marker.cross{stroke:#333333;}#mermaid-svg-HRNAJ4GchwiL45Xj svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-HRNAJ4GchwiL45Xj .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-HRNAJ4GchwiL45Xj .cluster-label text{fill:#333;}#mermaid-svg-HRNAJ4GchwiL45Xj .cluster-label span{color:#333;}#mermaid-svg-HRNAJ4GchwiL45Xj .label text,#mermaid-svg-HRNAJ4GchwiL45Xj span{fill:#333;color:#333;}#mermaid-svg-HRNAJ4GchwiL45Xj .node rect,#mermaid-svg-HRNAJ4GchwiL45Xj .node circle,#mermaid-svg-HRNAJ4GchwiL45Xj .node ellipse,#mermaid-svg-HRNAJ4GchwiL45Xj .node polygon,#mermaid-svg-HRNAJ4GchwiL45Xj .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-HRNAJ4GchwiL45Xj .node .label{text-align:center;}#mermaid-svg-HRNAJ4GchwiL45Xj .node.clickable{cursor:pointer;}#mermaid-svg-HRNAJ4GchwiL45Xj .arrowheadPath{fill:#333333;}#mermaid-svg-HRNAJ4GchwiL45Xj .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-HRNAJ4GchwiL45Xj .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-HRNAJ4GchwiL45Xj .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-HRNAJ4GchwiL45Xj .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-HRNAJ4GchwiL45Xj .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-HRNAJ4GchwiL45Xj .cluster text{fill:#333;}#mermaid-svg-HRNAJ4GchwiL45Xj .cluster span{color:#333;}#mermaid-svg-HRNAJ4GchwiL45Xj div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-HRNAJ4GchwiL45Xj :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 1个 多个 Zookeeper集群 领导者 跟随者 #mermaid-svg-ioiVdWlcY7u7CqLo {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-ioiVdWlcY7u7CqLo .error-icon{fill:#552222;}#mermaid-svg-ioiVdWlcY7u7CqLo .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-ioiVdWlcY7u7CqLo .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-ioiVdWlcY7u7CqLo .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-ioiVdWlcY7u7CqLo .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-ioiVdWlcY7u7CqLo .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-ioiVdWlcY7u7CqLo .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-ioiVdWlcY7u7CqLo .marker{fill:#333333;stroke:#333333;}#mermaid-svg-ioiVdWlcY7u7CqLo .marker.cross{stroke:#333333;}#mermaid-svg-ioiVdWlcY7u7CqLo svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-ioiVdWlcY7u7CqLo .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-ioiVdWlcY7u7CqLo .cluster-label text{fill:#333;}#mermaid-svg-ioiVdWlcY7u7CqLo .cluster-label span{color:#333;}#mermaid-svg-ioiVdWlcY7u7CqLo .label text,#mermaid-svg-ioiVdWlcY7u7CqLo span{fill:#333;color:#333;}#mermaid-svg-ioiVdWlcY7u7CqLo .node rect,#mermaid-svg-ioiVdWlcY7u7CqLo .node circle,#mermaid-svg-ioiVdWlcY7u7CqLo .node ellipse,#mermaid-svg-ioiVdWlcY7u7CqLo .node polygon,#mermaid-svg-ioiVdWlcY7u7CqLo .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-ioiVdWlcY7u7CqLo .node .label{text-align:center;}#mermaid-svg-ioiVdWlcY7u7CqLo .node.clickable{cursor:pointer;}#mermaid-svg-ioiVdWlcY7u7CqLo .arrowheadPath{fill:#333333;}#mermaid-svg-ioiVdWlcY7u7CqLo .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-ioiVdWlcY7u7CqLo .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-ioiVdWlcY7u7CqLo .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-ioiVdWlcY7u7CqLo .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-ioiVdWlcY7u7CqLo .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-ioiVdWlcY7u7CqLo .cluster text{fill:#333;}#mermaid-svg-ioiVdWlcY7u7CqLo .cluster span{color:#333;}#mermaid-svg-ioiVdWlcY7u7CqLo div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-ioiVdWlcY7u7CqLo :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Zookeeper应用场景 统一命名服务 统一配置管理 统一集群管理 服务器节点动态上下线 软负载均衡 安装
Linux 下载地址 https://archive.apache.org/dist/zookeeper/ //解压
mkdir /opt/module/ tar -zxvf apache-zookeeper-3.9.1-bin.tar.gz -C /opt/module cd /opt/module///修改目录名
mv apache-zookeeper-3.9.1-bin zookeeper-3.9.1//创建zookeeper数据目录
cd zookeeper-3.9.1 mkdir zkData//修改配置文件 数据目录改为zkData
cp conf/zoo_sample.cfg conf/zoo.cfg
sed -i /^dataDir/c\dataDir/opt/module/zookeeper-3.9.1/zkData conf/zoo.cfg//查看配置文件
more conf/zoo.cfg//服务端
//启动zookeeper服务端 注意确保2181、39306、8080 这三个端口不会被占用否则启动失败
// zookeeper服务端启动
cd /opt/module/zookeeper-3.9.1/bin sh zkServer.sh start
// zookeeper服务端状态查看
cd /opt/module/zookeeper-3.9.1 sh bin/zkServer.sh status
// zookeeper服务端状态停止
cd /opt/module/zookeeper-3.9.1 sh bin/zkServer.sh stop//查看zookeeper服务端是否启动成功 出现QuorumPeerMain说明启动成功
jps -l//查看zookeeper服务端占用的端口号
netstat -anlp |grep $(jps -l | grep QuorumPeerMain | awk {print $1}) | grep tcp//客户端
cd /opt/module/zookeeper-3.9.1 sh bin/zkCli.sh //查看zookeeper客户端占用的端口号
netstat -anlp |grep $(jps -l | grep ZooKeeperMain | awk {print $1}) | grep tcp
服务端相关
客户端相关
Windows
配置参数 配置文件路径 /opt/module/zookeeper-3.9.1/conf/zoo.cfg //tickTime
默认2000
通信心跳时间Zookeeper服务器与客户端心跳时间单位毫秒//initLimit
默认10
【建立连接】
Leader和Follower初始连接时能容忍的最多心跳数(tickTime的数量)
LF初始通信时限tickTime * initLimit时间范围内未通信成功则认为失败、zookeeper集群Leader与Follower的通信时限//syncLimit
默认5
【建立连接之后的通信】
Leader和Follower.之间通信时间如果超过syncLimit*tickTime,Leader认为Follwer死掉从服务器列表中删除Follwer。//dataDir
保存Zookeeper中的数据//clientPort
客户端连接端口通常不做修改。集群
参考配置文件
# The number of milliseconds of each tick
tickTime2000
# The number of ticks that the initial
# synchronization phase can take
initLimit10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir/opt/module/zookeeper-3.9.1/zkData
# the port at which the clients will connect
clientPort2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount3
# Purge task interval in hours
# Set to 0 to disable auto purge feature
#autopurge.purgeInterval1## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.classNameorg.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost0.0.0.0
#metricsProvider.httpPort7000
#metricsProvider.exportJvmInfotrue# 集群配置
server.107192.168.19.107:2888:3888
server.108192.168.19.108:2888:3888
server.109192.168.19.109:2888:3888配置步骤流程 测试 准备三台虚拟机107、108、109 //
// 在107里面运行下面的命令//集群必须中每台zookeeper必须设置一个唯一的身份证号echo 107 /opt/module/zookeeper-3.9.1/zkData/myid //将107里面的zookeeper同步到另外两台服务器上rsync -avz /opt/module/ root192.168.19.108:/opt/modulersync -avz /opt/module/ root192.168.19.109:/opt/module// 在108里面运行下面的命令
echo 108 /opt/module/zookeeper-3.9.1/zkData/myid// 在109里面运行下面的命令
echo 109 /opt/module/zookeeper-3.9.1/zkData/myid//
//
////配置文件添加集群信息 opt/module/zookeeper-3.9.1/conf/zoo.cfg
server.zookeeper的身份证号zookeeper的ip:集群间的通信端口号:集群leader挂了重新选举新Leader的端口号
//配置文件添加的信息
# 集群配置
server.107192.168.19.107:2888:3888
server.108192.168.19.108:2888:3888
server.109192.168.19.109:2888:3888//同步文件过去
rsync -avz /opt/module/zookeeper-3.9.1/conf/zoo.cfg root192.168.19.108:/opt/module/zookeeper-3.9.1/conf
rsync -avz /opt/module/zookeeper-3.9.1/conf/zoo.cfg root192.168.19.109:/opt/module/zookeeper-3.9.1/conf启动 107服务器 108服务器 107服务器 109服务器