下载zk

wget https://archive.apache.org/dist/zookeeper/stable/apache-zookeeper-3.5.5-bin.tar.gz

安装jdk

tar xf jdk-12.0.2_linux-x64_bin.tar.gz -C /usr/local/
vim /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
ln -s /usr/local/jdk-12.0.2 /usr/local/jdk

部署zk

mkdir /data/zk -pv
tar xf apache-zookeeper-3.5.5-bin.tar.gz -C /data/zk/
cp /data/zk/apache-zookeeper-3.5.5-bin/bin/../conf/zoo_sample.cfg /data/zk/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg
创建数据目录 mkdir /data/zk/data
[root@master conf]# vim zoo.cfg # The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/data/zk/data 数据目录
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

  配置zk的环境变量

[root@master conf]# vim /etc/profile.d/zk.sh 

export ZOOKEEPER_HOME=/data/zk/apache-zookeeper-3.5.5-bin
export ZOOBINDIR=/data/zk/apache-zookeeper-3.5.5-bin/bin
export PATH=$ZOOKEEPER_HOME/bin:$PATH [root@master conf]# exec bash

  启动

[root@master conf]# zkServer.sh start

  客户端登录

[root@master conf]# zkCli.sh
[zk: localhost:2181(CONNECTED) 0] help 帮助
ZooKeeper -server host:port cmd args
addauth scheme auth
close
config [-c] [-w] [-s]
connect host:port
create [-s] [-e] [-c] [-t ttl] path [data] [acl]
delete [-v version] path
deleteall path
delquota [-n|-b] path
get [-s] [-w] path
getAcl [-s] path
history
listquota path
ls [-s] [-w] [-R] path
ls2 path [watch]
printwatches on|off
quit
reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
redo cmdno
removewatches path [-c|-d|-a] [-l]
rmr path
set [-s] [-v version] path data
setAcl [-s] [-v version] [-R] path acl
setquota -n|-b val path
stat [-w] path
sync path
Command not found: Command not found help
[zk: localhost:2181(CONNECTED) 1] create /app4 创建node
Created /app4
[zk: localhost:2181(CONNECTED) 2] create /app4/p-1
Created /app4/p-1
[zk: localhost:2181(CONNECTED) 3] create /app4/p-2
Created /app4/p-2
[zk: localhost:2181(CONNECTED) 4] create /app4/p-3
Created /app4/p-3
[zk: localhost:2181(CONNECTED) 5] ls -R / 查看node
/
/app1
/app2
/app4
/zookeeper
/app1/p_1
/app1/p_2
/app1/p_3
/app4/p-1
/app4/p-2
/app4/p-3
/zookeeper/config
/zookeeper/quota

  客户端创建分布式锁

[zk: localhost:2181(CONNECTED) 6] create -e /log
Created /log
[root@master data]# zkCli.sh
[zk: localhost:2181(CONNECTED) 2] create -e /log
Node already exists: /log
[zk: localhost:2181(CONNECTED) 3] stat -w /log 监控这个锁
cZxid = 0x14
ctime = Wed Sep 11 16:31:46 CST 2019
mZxid = 0x14
mtime = Wed Sep 11 16:31:46 CST 2019
pZxid = 0x14
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x100014034170002
dataLength = 0
numChildren = 0
退出第一个客户端;释放锁
[zk: localhost:2181(CONNECTED) 7] quit WATCHER:: WatchedEvent state:Closed type:None path:null
2019-09-11 16:35:02,053 [myid:] - INFO [main:ZooKeeper@1422] - Session: 0x100014034170002 closed
2019-09-11 16:35:02,053 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@524] - EventThread shut down for session: 0x100014034170002
释放锁后
[zk: localhost:2181(CONNECTED) 4]
WATCHER:: WatchedEvent state:SyncConnected type:NodeDeleted path:/log [zk: localhost:2181(CONNECTED) 4] create -e /log 第二的
Created /log

  

zk的单机部署,与客户端的使用的更多相关文章

  1. Kafka记录-Kafka简介与单机部署测试

    1.Kafka简介 kafka-分布式发布-订阅消息系统,开发语言-Scala,协议-仿AMQP,不支持事务,支持集群,支持负载均衡,支持zk动态扩容 2.Kafka的架构组件 1.话题(Topic) ...

  2. ETL作业调度软件TASKCTL4.1单机部署

    单机部署,实际上就是将EM节点和一个Server节点安装到同一个地方.EM节点是TASKCTL服务端的最顶层,主要负责客户端与服务端之间的通信.Server节点是TASKCTL的调度服务控制层,也有A ...

  3. Hadoop生态圈-CentOs7.5单机部署ClickHouse

    Hadoop生态圈-CentOs7.5单机部署ClickHouse 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 到了新的公司,认识了新的同事,生产环境也得你去适应新的集群环境,我 ...

  4. Zookeeper(一)-- 简介以及单机部署和集群部署

    一.分布式系统 由多个计算机组成解决同一个问题的系统,提高业务的并发,解决高并发问题. 二.分布式环境下常见问题 1.节点失效 2.配置信息的创建及更新 3.分布式锁 三.Zookeeper 1.定义 ...

  5. RocketMQ 消息队列单机部署及使用

    转载请注明来源:http://blog.csdn.net/loongshawn/article/details/51086876 相关文章: <RocketMQ 消息队列单机部署及使用> ...

  6. Minikube之Win10单机部署Kubernetes(k8s)自动化容器操作的开源平台

    Minikube之Win10单机部署 Kubernetes(k8s)是自动化容器操作的开源平台,基于这个平台,你可以进行容器部署,资源调度和集群扩容等操作.如果你曾经用过Docker部署容器,那么可以 ...

  7. redission-tomcat:快速实现从单机部署到多机部署

    原文地址: http://blog.jboost.cn/2019/06/29/session-redis.html 一些项目初期出于简单快速,都是做单机开发与部署,但是随着业务的扩展或对可用性要求的提 ...

  8. Clickhouse单机部署以及从mysql增量同步数据

    背景: 随着数据量的上升,OLAP一直是被讨论的话题,虽然druid,kylin能够解决OLAP问题,但是druid,kylin也是需要和hadoop全家桶一起用的,异常的笨重,再说我也搞不定,那只能 ...

  9. linux单机部署kafka(filebeat+elk组合)

    filebeat+elk组合之kafka单机部署 准备: kafka下载链接地址:http://kafka.apache.org/downloads.html 在这里下载kafka_2.12-2.10 ...

随机推荐

  1. rancher2中文文档地址

    rancher2中文文档地址 待办 https://docs.rancher.cn/

  2. AC3 IMDCT

    AC3 encoder 在进行MDCT时,使用两种长度的block. 512 samples的block用于输入信号频谱是stationary,或者在时间上变化缓慢.在fs 为48k时,使用512 s ...

  3. ACM的探索之Everything is Generated In Equal Probability! 后序补充丫!

    Problem Desciption: 百度翻译后的汉化: 参见博客:https://www.cnblogs.com/zxcoder/p/11253099.html https://blog.csdn ...

  4. docker互联机制实现便捷互访

    何为容器互联 & 为何需要容器互联 容器的互联是一种让多个容器中应用进行快速交互的方式,它会在源和接收容器之间创建连接关系,接收容器可以通过容器名快速访问到源容器,而不用指定具体的 ip 地址 ...

  5. MyBatis(8)——联表多对一的处理

    xml说明: <!--column不做限制,可以为任意表的字段,而property须为type 定义的pojo属性--> <resultMap id="唯一的标识" ...

  6. 深度学习之tensorflow框架(中)

    会话 开启会话 tf.Session用于完整的程序中 tf.InteractiveSession用于交互式上下文中的tensorflow 查看张量的值 都必须在会话里面 c_new_value=new ...

  7. python中的数学类型及操作

    一.概述 整数类型 浮点数类型 复数类型 round()函数 数值运算符 数值运算函数 字符串类型 1.整数类型 整型:用来描述什么:比如身高,体重,年龄等 eg: age=20 height=168 ...

  8. A task in a suit and a tie:paraphrase generation with semantic augmentation解读

    1.该算法核心:在seq2seq模型的编码器中增加语义的frame 和 roles 2.上图为算法整个流程: 1).首先输入一句话s,SLING会使用frame和role label注释输入语句s,然 ...

  9. ALSA driver--PCM Interrupt handle

    PCM 中断处理函数的主要作用是用来更新buffer position. 在PCM的interrupt handle里面通过snd_pcm_period_elapsed来通知alsa-core buf ...

  10. 修改链接服务器 Rpc &Rpc Out

    USE [master] GO EXEC master.dbo.sp_serveroption @server=N'LinkName', @optname=N'rpc', @optvalue=N'tr ...