zookeeper环境搭建

Standalone

create it in conf/zoo.cfg:

1
2
3
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181

start ZooKeeper

1
2
3
4
5
bin/zkServer.sh start


#window下,不能加start命令
zkServer.cmd

Connecting to ZooKeeper

1
bin/zkCli.sh -server 127.0.0.1:2181

Running Replicated ZooKeeper

For replicated mode, a minimum of three servers are required, and it is strongly recommended that you have an odd number of servers

create it in conf/zoo.cfg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#结点1
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.85.134:2888:3888
server.2=192.168.85.135:2888:3888
server.3=0.0.0.0:2888:3888

# echo 1 > /var/lib/zookeeper/myid


#结点2
tickTime=200
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.85.134:2888:3888
server.2=0.0.0.0:2888:3888
server.3=192.168.85.136:2888:3888

#echo 2 > /var/lib/zookeeper/myid


#结点3
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.85.134:2888:3888
server.2=192.168.85.135:2888:3888
server.3=0.0.0.0:2888:3888

# echo 3 > /var/lib/zookeeper/myid

注意服务器防火墙是否开启

Cannot open channel to 2 at election address /192.168.85.135:3888

initLimit=5
syncLimit=2
server.1=192.168.85.144:2888:3888
server.2=192.168.85.145:2888:3888
server.3=192.168.85.146:2888:3888

解决: must specify 0.0.0.0 for the current node

修改占用8080端口

zookeeper最近的版本中有个内嵌的管理控制台是通过jetty启动,也会占用8080 端口。
通过查看zookeeper的官方文档,发现有3种解决途径:

  • 删除jetty。
  • 修改端口。

    修改方法的方法有两种,一种是在启动脚本中增加 -Dzookeeper.admin.serverPort=你的端口号.
    一种是在zoo.cfg中增加admin.serverPort=没有被占用的端口号

  • 停用这个服务,在启动脚本中增加”-Dzookeeper.admin.enableServer=false”

zookeeper内置一个管理控制台,通过下面的配置禁用
admin.enableServer=false