标签:操作 lock 并发 参数 说明 提高 character 模式 efault
目录
zookeeper是一个为分布式应用所设计的分布式的、开源的协调服务。它提供了一项基本服务:分布式锁服务,同时也提供了分布式应用数据的维护和管理机制,包括统一命名服务、状态同步服务、集群管理、分布式消息队列、分布式应用配置项的管理等。zookeeper支持独立安装以及集群部署。
zookeeper官方网站:http://zookeeper.apache.org/
zookeeper下载地址:https://www.apache.org/dyn/closer.cgi/zookeeper/
Zookeeper集群主要角色有Server和Client,其中Server分为Leader、Follower和Observer三个角色:
zk集群中每个server在内存中存储一份数据。在zk启动时,将从实例中选举一个server作为leader,leader负责处理数据更新等操作,当且仅当大多数server在内存中成功修改数据,才认为数据修改成功。
zk写的流程:
tar xf zookeeper-3.4.14.tar.gz -C /usr/local/
cd /usr/local/
ln -s zookeeper-3.4.14 zookeeper
# 创建数据目录和日志目录
mkdir /usr/local/zookeeper/{data,logs}
注: zk的安装依赖java,所以需要先安装jdk
cd /usr/local/zookeeper/conf
cp zoo_sample.conf zoo.conf
#vim zoo.conf
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
clientPort=2181
配置项说明:
/usr/local/zookeeper/zkServer.sh start
[root@app conf]# telnet 127.0.0.1 2181
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stat
Zookeeper version: 3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
Clients:
/127.0.0.1:42638[0](queued=0,recved=1,sent=0)
Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x0
Mode: standalone
Node count: 4
[root@app conf]# /usr/local/zookeeper/bin/zkCli.sh -server localhost:2181
Connecting to localhost:2181
...
[zk: localhost:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port
[zk: localhost:2181(CONNECTED) 1]
#vim /etc/hosts
zk1 192.168.0.101
zk2 192.168.0.102
zk3 192.168.0.103
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
clientPort=2181
server.1=192.168.0.101:2888:3888
server.2=192.168.0.102:2888:3888
server.3=192.168.0.103:2888:3888
配置项说明:
server.id=host:port:port
,其中id即server id,用于标识服务器在集群中的序号。每台zk服务器上,都需要在数据目录下创建一个myid文件,该文件中只有一行内容,即对应于每台服务器的server id。# 每个服务器上的myid内容都不同,且需要保证和自己的zoo.cfg配置文件中"server.id=host:port:port"的id值一致
# id的范围是1~255
echo "1" > /usr/local/zookeeper/data/myid
/usr/local/zookeeper/zkServer.sh start
[root@app conf]# telnet 127.0.0.1 2181
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stat
Zookeeper version: 3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
Clients:
/127.0.0.1:41142[0](queued=0,recved=1,sent=0)
Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x100000000
Mode: leader
Node count: 4
Proposal sizes last/min/max: -1/-1/-1
Connection closed by foreign host.
[root@app conf]# ../bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
标签:操作 lock 并发 参数 说明 提高 character 模式 efault
原文地址:https://www.cnblogs.com/breezey/p/10849306.html