我想做个网站怎么做的,一个人看的免费直播大全,建筑培训网官网证件查询,中小企业网络营销方案官网#xff1a;https://zookeeper.apache.org/
zookeeper常用用途#xff1a;
集群管理#xff0c;zookeeper作为注册中心#xff0c;管理服务提供方的ip地址端口号url信息#xff0c;并在服务消费方请求需要时发送给服务消费方。配置中心#xff08;不过一般用阿波罗…官网https://zookeeper.apache.org/
zookeeper常用用途
集群管理zookeeper作为注册中心管理服务提供方的ip地址端口号url信息并在服务消费方请求需要时发送给服务消费方。配置中心不过一般用阿波罗apollo或者阿里的Nacos来做 多个app中的配置是从zookeeper中拉取配置而不是一个个去手动修改。消费端从服务端中关注某个ZNode一旦节点发生数据变更服务端会向消费端发送Watcher事件进行通知消费端接受事件后主动到服务端获取最新的配置数据。 分布式锁等待
安装
前提安装zookeeper需要的JDK版本这里装的是openjdk-8
apt install openjdk-8-jdk复制示例配置文件zoo_simple.conf到confg/zoo.cfg
cp confg/zoo_simle.conf confg/zoo.cf修改配置文件修改如下主要修改数据的保存目录其他看自己的需求修改
# 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/apps_data/zookeeper**
# 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.
#
# http://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通过自带的脚本启动zookeeper
# 查看帮助
rootswq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh --help
ZooKeeper JMX enabled by default
Using config: /apps/zookeeper-3.4.13/bin/../conf/zoo.cfg
Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}# 启动服务
rootswq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /apps/zookeeper-3.4.13/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED# 查看2181端口是否监听成功
rootswq-virtual-machine:/apps/zookeeper-3.4.13# ss -tanl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 127.0.0.1:631 0.0.0.0:*
LISTEN 0 4096 127.0.0.1:2379 0.0.0.0:*
LISTEN 0 4096 127.0.0.1:2380 0.0.0.0:*
LISTEN 0 50 *:46069 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 [::1]:631 [::]:*
LISTEN 0 50 *:2181 *:* 客户端
官方命令行客户端zkCli.sh
bash bin/zkCli.sh[zk: localhost:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd argsstat path [watch]set path data [version]ls path [watch]delquota [-n|-b] pathls2 path [watch]setAcl path aclsetquota -n|-b val pathhistory redo cmdnoprintwatches on|offdelete path [version]sync pathlistquota pathrmr pathget path [watch]create [-s] [-e] path data acladdauth scheme authquit getAcl pathclose connect host:port
[zk: localhost:2181(CONNECTED) 1] 图形化Ui客户端-ZooInspector
老古董不过实用没有啥界面之说…
图形化Ui客户端-ZKUI
界面也挺好看的…不过也挺久没有更新了
https://github.com/DeemOpen/zkui
图形化UI客户端-PrettyZoo
比较新界面好看
https://github.com/vran-dev/PrettyZoo
集群
集群理论
集群角色分类
leader领导者就是master主flowller追随者也就是slave从observer观察者不参与leader选举也不参与【过半写成功】策略。只用于读数据提高读性能。【一般不怎么用】 **过半写成功策略**当某个数据被写入时集群中一半以上的节点数据写成功就表示这个数据已经成功写入然后响应返回给客户端用于提升响应速度。 Zookeeper集群中的所有机器通过Leader选举来选定⼀台被称为Leader的机器Leader服务器为客户端提供读和写服务除Leader外其他机器包括Follower和Observer,Follower和Observer都能提供读服务唯⼀的区别在于Observer不参与Leader选举过程不参与写操作的过半写成功策略因此Observer可以在不影响写性能的情况下提升集群的性能。
集群读写的方式
读任意节点都可以 写只有leader节点可以如果往非leader节点写会自动转发给leader写入然后再同步给其他非leader节点
集群搭建
实验环境
# 由于我没啥硬件资源全部都放在同一台虚拟机上然后用不同的端口模拟实现集群。
# 生产环境肯定是放在不同的物理机上的。
zk1 - 192.168.6.130: 2181
zk2 - 192.168.6.130: 2182
zk3 - 192.168.6.130: 2183
修改配置文件中的端口和数据存储目录
# 由于是放同一个服务器上用不同的端口实现伪集群因此这里只需要添加2个额外的配置文件即可。# zk2 配置文件zoo2.cfg
# 这里需要修改指定存储数据的目录
dataDir/apps_data/zookeeper2
# the port at which the clients will connect
clientPort2182# zk3 服务zoo3.cfg
# 这里需要修改指定存储数据的目录
dataDir/apps_data/zookeeper3
# the port at which the clients will connect
clientPort2183
停止之前的zk1服务
bash zkServer.sh stop在每个zk服务器的【数据目录】下添加myid文件并且内容必须时每个服务器都时唯一的ID
# 我这里就用1、2、3来区分了
echo 1 /apps_data/zookeeper/myid
echo 2 /apps_data/zookeeper2/myid
echo 3 /apps_data/zookeeper3/myid
再次编辑每个zk服务的配置文件将需要组成集群的zk服务器ip端口等信息添加
# zk1、zk2、zk3的配置文件添加以下内容
# 格式 server.服务器唯一ID服务器IP:数据同步端口:leader选举端口
# 服务器唯一ID是上面步骤中向【数据目录】写入myid文件中内容
server.1192.168.6.130:2888:3888
server.2192.168.6.130:2888:3888
server.3192.168.6.130:2888:3888# zk2和zk3配置文件添加的内容相同。
# 由于我是同一个服务器上部署所以端口就不一致了生产环境可以直接用上面的配置
# 示例
rootswq-virtual-machine:/apps/zookeeper-3.4.13# cat EOF ./conf/zoo.cfg
# cluster config
server.1192.168.6.130:2888:3888
server.2192.168.6.130:2889:3889
server.3192.168.6.130:2887:3887
EOF
启动3台服务器
rootswq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh start conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo.cfg
Starting zookeeper ... ^[[A^[[DSTARTED
rootswq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh start conf/zoo2.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo2.cfg
Starting zookeeper ... STARTED
rootswq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh start conf/zoo3.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo3.cfg
Starting zookeeper ... STARTED用jps查看zookeeper是否启动用于查看当前系统上的java虚拟机
rootswq-virtual-machine:/apps/zookeeper-3.4.13# jps
29360 QuorumPeerMain
29443 Jps
29332 QuorumPeerMain
29402 QuorumPeerMain查看端口
rootswq-virtual-machine:/apps/zookeeper-3.4.13# ss -tanl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
...省略其他的
LISTEN 0 50 *:2181 *:*
LISTEN 0 50 *:2182 *:*
LISTEN 0 50 *:2183 *:*
LISTEN 0 50 *:37447 *:*
LISTEN 0 50 [::ffff:192.168.6.130]:2888 (被选为leader的服务才会监听【数据同步端口】) *:*
LISTEN 0 50 *:38731 *:*
LISTEN 0 50 [::ffff:192.168.6.130]:3887 *:*
LISTEN 0 50 *:40687 *:*
LISTEN 0 50 **[::ffff:192.168.6.130]:3888 ** *:*
LISTEN 0 50 [::ffff:192.168.6.130]:3889 *:*注意(被选为leader的服务才会监听【数据同步端口】因为其他follwer是通过该端口与leader同步数据的。) 查看zookeeper状态
rootswq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh status conf/zoo3.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo3.cfg
Mode: follower
rootswq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh status conf/zoo2.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo2.cfg
Mode: follower
rootswq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh status conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo.cfg
Mode: leader