2、Zookeeper Server环境的搭建和配置文件参数设置
配置要求Zookeeper主要包括客户端(client)、服务端(server)、原生客户端(native client)和其他可选组件(Contrib)四类。其中:客户端是java实现的api library,通过在应用中引用jar的方式使用。服务端是运行在java 1.7之上版本的java应用。原生客户端和客户端功能一样,只不过是C语言实现的。环境搭建之前,参考官网的系...
配置要求
Zookeeper主要包括客户端(client)、服务端(server)、原生客户端(native client)和其他可选组件(Contrib)四类。
其中:
客户端是java实现的api library,通过在应用中引用jar的方式使用。
服务端是运行在java 1.7之上版本的java应用。
原生客户端和客户端功能一样,只不过是C语言实现的。
环境搭建之前,参考官网的系统配置要求:
Operating System | Client | Server | Native Client | Contrib |
---|---|---|---|---|
GNU/Linux | Development and Production | Development and Production | Development and Production | Development and Production |
Solaris | Development and Production | Development and Production | Not Supported | Not Supported |
FreeBSD | Development and Production | Development and Production | Not Supported | Not Supported |
Windows | Development and Production | Development and Production | Not Supported | Not Supported |
Mac OS X | Development Only | Development Only | Not Supported | Not Supported |
Zookeeper Server分为单节点模式(Standalone)、伪集群和集群(Clustered )模式。
开发人员可以采用单节点模式,只部署一个Server。
伪集群是在一台机器上部署多个Server,可作为集群测试。
生产环境应采用集群模式,建议至少部署三个Server的集群模式。
【Yahoo公司每个Server采用REHL系统,双核CPU,2G RAM和80G硬盘。】
环境搭建采用linux(CentOS 7) + openJDK8u40。
操作步骤
1、下载稳定版的apache-zookeeper-3.5.5-bin(2019.4.20),tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz解压。
2、创建配置文件conf/zoo.cfg,复制apache-zookeeper-3.5.5-bin/conf/目录下的配置模板zoo_sample.cfg,重命名为zoo.cfg。
- tickTime:基本时间单元,以毫秒为单位,这个时间作为 Zookeeper 服务器之间或客户端之间维持心跳的时间间隔,默认值2000。
- dataDir:存储内存中数据库快照的位置,顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存到这个目录里,默认/tmp/zookeeper,linux 可改为/data/zookeeper,windows下可改为D:/zookeeper。
- clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
- initLimit:这个配置项是用来配置 Zookeeper 接受客户端初始化连接时最长能忍受多少个心跳时间间隔,默认值10。
- 当已经超过 10 个心跳的时间也就是(ticktime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败,总的时间长度就是:10*2000 = 20s
- syncLimit:这个配置项表示 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,默认值5,总的时间长度就是:5*2000 = 10s
- server.A = B:C:D
- A:表示这是第几号服务器
- B:服务器的 IP 地址
- C:服务器与集群中的 Leader 服务器交换信息的端口
- D:一旦集群中的 Leader 服务器挂了,需要一个端口重新进行选举,选出一个新的 Leader
- 2181:对外提供服务端口
- 2888:内部数据同步端口
- 3888:节点挂了,选举端口
单节点模式: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=/home/manager/zookeeper/data
dataLogDir=/home/manager/zookeeper/logs
# the port at which the clients will connect
clientPort=2181
伪集群模式:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/manager/zookeeper/zk1/data
dataLogDir=/home/manager/zookeeper/zk1/logs
clientPort=2181
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/manager/zookeeper/zk2/data
dataLogDir=/home/manager/zookeeper/zk2/logs
clientPort=2182
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/manager/zookeeper/zk3/data
dataLogDir=/home/manager/zookeeper/zk3/logs
clientPort=2183
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
需要在各自dataDir路径下创建myid文件,填写server.1后的数字标示这是第几号服务器。
例如,vi /home/manager/zookeeper/zk1/data/myid
键入1,然后esc :wq 保存,否则:
集群模式:修改zoo.cfg,zoo1(或IP),zoo2,zoo3三台机器分别放置到config目录下
tickTime=2000
dataDir=/home/manager/zookeeper
dataLogDir=/home/manager/zookeeper/logs
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
3、启动,windows系统双击apache-zookeeper-3.5.5-bin/bin目录下的zkServer.cmd,linux可采用
./apache-zookeeper-3.5.5-bin/bin/zkServer.sh start
启动成功,可见
或
4、client执行命令,客户端连接成功。
./apache-zookeeper-3.5.5-bin/bin/zkCli.sh -server 127.0.0.1:2181
或
D:\apache-zookeeper-3.5.5-bin\bin>zkCli.cmd -server 127.0.0.1:2181
更多推荐
所有评论(0)