Mac 中 Zookeeper 安装与配置 二

  |   1 评论   |   1,247 浏览

配置

单机模式

集群模式

实现方式
1. 多台机器,每台运行一个Zookeeper Server
2. 单台机器,运行多个Zookeeper Server
测试环境使用第二种形式

参数配置
1. data目录 用于存放进程运行数据。
2. data目录下的myid文件 用于存储一个数值,用来作为该ZooKeeper Server进程的标识。
3. 监听Client端请求的端口号
4. 监听同ZooKeeper集群内其他Server进程通信请求的端口号
5. 监听ZooKeeper集群内“leader”选举请求的端口号 该端口号用来监听ZooKeeper集群内“leader”选举的请求。注意这个是ZooKeeper集群内“leader”的选举,跟分布式应用程序无关。

参数配置注意事项
* 同一个ZooKeeper集群内,不同ZooKeeper Server进程的标识需要不一样,即myid文件内的值需要不一样
* 采用单机多实例形式构建ZooKeeper集群,需要注意“目录,端口号”等资源的不可共享性,如果共享会导致ZooKeeper Server进程不能正常运行,比如“data目录,几个监听端口号”都不能被共享
各实例分配如下

myid Data目录 Client Server Leader 配置文件名
1 /data/zoo1/ 2181 2222 2001 zoo1.cfg
2 /data/zoo2/ 2182 3333 3002 zoo2.cfg
3 /data/zoo3/ 2183 4444 4003 zoo3.cfg

配置文件
zoo1.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=//Users/chenlei/syssoft/soft/zookeeper-3.4.12/data/zoo1
clientPort=2181
#server.x中的“x”表示ZooKeeper Server进程的标识
server.1=127.0.0.1:2222:2001
server.2=127.0.0.1:3333:3002
server.3=127.0.0.1:4444:4003

在/Users/chenlei/syssoft/soft/zookeeper-3.4.12/data/zoo2目录中创建myid文件,文件中设置数字为1

zoo2.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/Users/chenlei/syssoft/soft/zookeeper-3.4.12/data/zoo2
clientPort=2182
#server.x中的“x”表示ZooKeeper Server进程的标识
server.1=127.0.0.1:2222:2001
server.2=127.0.0.1:3333:3002
server.3=127.0.0.1:4444:4003

在/Users/chenlei/syssoft/soft/zookeeper-3.4.12/data/zoo2目录中创建myid文件,文件中设置数字为2

zoo3.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/Users/chenlei/syssoft/soft/zookeeper-3.4.12/data/zoo3
clientPort=2183
#server.x中的“x”表示ZooKeeper Server进程的标识
server.1=127.0.0.1:2222:2001
server.2=127.0.0.1:3333:3002
server.3=127.0.0.1:4444:4003

在/Users/chenlei/syssoft/soft/zookeeper-3.4.12/data/zoo2目录中创建myid文件,文件中设置数字为3

运行ZooKeeper Server

./bin/zkServer.sh start conf/zoo1.cfg
./bin/zkServer.sh start conf/zoo2.cfg
./bin/zkServer.sh start conf/zoo3.cfg
 chenlei@chenleideMacBook-Pro # ~/syssoft/soft/zookeeper-3.4.12  ./bin/zkServer.sh start conf/zoo1.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo1.cfg
Starting zookeeper ... STARTED
 chenlei@chenleideMacBook-Pro # ~/syssoft/soft/zookeeper-3.4.12  ./bin/zkServer.sh start conf/zoo2.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo2.cfg
Starting zookeeper ... STARTED
 chenlei@chenleideMacBook-Pro # ~/syssoft/soft/zookeeper-3.4.12  ./bin/zkServer.sh start conf/zoo3.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo3.cfg
Starting zookeeper ... STARTED

运行ZooKeeper命令客户端连接到Server集群

 ~/syssoft/soft/zookeeper-3.4.12 # ./bin/zkCli.sh -server 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
Connecting to 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
2018-06-26 18:08:47,164 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.12-e5259e437540f349646870ea94dc2658c4e44b3b, built on 03/27/2018 03:55 GMT
2018-06-26 18:08:47,167 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=192.168.2.1
2018-06-26 18:08:47,167 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_131
2018-06-26 18:08:47,169 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-06-26 18:08:47,170 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre
2018-06-26 18:08:47,170 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../build/classes:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../build/lib/*.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../lib/slf4j-log4j12-1.7.25.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../lib/slf4j-api-1.7.25.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../lib/netty-3.10.6.Final.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../lib/log4j-1.2.17.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../lib/jline-0.9.94.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../lib/audience-annotations-0.5.0.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../zookeeper-3.4.12.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../src/java/lib/*.jar:/Users/chenlei/syssoft/soft/zookeeper-3.4.12/bin/../conf:
2018-06-26 18:08:47,170 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/Users/chenlei/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
2018-06-26 18:08:47,170 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/var/folders/p6/c7x0g7sj603dt_1brhj2x1nr0000gn/T/
2018-06-26 18:08:47,171 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2018-06-26 18:08:47,171 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Mac OS X
2018-06-26 18:08:47,171 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=x86_64
2018-06-26 18:08:47,171 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=10.13.5
2018-06-26 18:08:47,171 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=chenlei
2018-06-26 18:08:47,172 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/Users/chenlei
2018-06-26 18:08:47,172 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/Users/chenlei/syssoft/soft/zookeeper-3.4.12
2018-06-26 18:08:47,173 [myid:] - INFO  [main:ZooKeeper@441] - Initiating client connection, connectString=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7aec35a
Welcome to ZooKeeper!
2018-06-26 18:08:47,203 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1028] - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2018-06-26 18:08:47,290 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1165] - Socket error occurred: 127.0.0.1/127.0.0.1:2182: Connection refused
[zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTING) 0] 2018-06-26 18:08:47,395 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1028] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2018-06-26 18:08:47,397 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@878] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
2018-06-26 18:08:47,431 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1302] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x1000dd94c820000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

评论

发表评论