标签: zookeeper集群安装配置
2015-08-18 10:05
470人阅读
举报
Zookeeper的目的是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。Zookeeper有两种运行模式,单机模式(Standalone)和集群模式(Distributed),但是Zookeeper的长处在于可以搭建分布式的Zookeeper集群(一个Leader,多个Follower),从而可以保证集群的高可用性、高稳定性、高可靠性。
下面说明一下Zookeeper两种模式的配置:
在配置Zookeeper之前,下载Zookeeper的安装包:http://zookeeper.apache.org/releases.html#download,我使用的是zookeeper-3.3.6版本的。
Zookeeper的单机模式(standalone)
下载安装包之后,使用Winscp放到Linux的环境中,然后解压安装包:
- tar zxvf zookeeper-3.3.6.tar.gz
解压后开始配置Zookeeper,进入到配置文件的目录:
将目录下面的 zoo_sample.cfg修改为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.
- dataDir=/tmp/zookeeper
- # the port at which the clients will connect
- clientPort=2181
上面各个配置参数的含义:
tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
dataLogDir: log目录, 同样可以是任意目录. 如果没有设置该参数, 将使用和dataDir相同的设置,这个参数我没有设置。
配置好后,启动Zookeeper服务器进程:
- cd zookeeper-3.3.6/
- bin/zkServer.sh start
启动成功后,用jps -m的命令查询,Zookeeper的进程为QuorumPeerMain
用客户端进程连接服务器,执行如下命令:
- bin/zkCli.sh -server logsrv03:2181
上面的logsrv是我的主机名,后面的2181是连接的端口号
连接成功后,出现以下的连接信息:
- [root@logsrv03 zookeeper-3.3.6]# bin/zkCli.sh -server logsrv03:2181
- Connecting to logsrv03:2181
- 2015-08-18 10:23:48,966 - INFO [main:Environment@97] - Client environment:zookeeper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT
- 2015-08-18 10:23:48,969 - INFO [main:Environment@97] - Client environment:host.name=logsrv03
- 2015-08-18 10:23:48,970 - INFO [main:Environment@97] - Client environment:java.version=1.7.0_71
- 2015-08-18 10:23:48,970 - INFO [main:Environment@97] - Client environment:java.vendor=Oracle Corporation
- 2015-08-18 10:23:48,971 - INFO [main:Environment@97] - Client environment:java.home=/usr/local/jdk1.7.0_71/jre
- 2015-08-18 10:23:48,971 - INFO [main:Environment@97] - Client environment:java.class.path=/usr/local/jiang/zookeeper-3.3.6/bin/../build/classes:/usr/local/jiang/zookeeper-3.3.6/bin/../build/lib/*.jar:/usr/local/jiang/zookeeper-3.3.6/bin/../zookeeper-3.3.6.jar:/usr/local/jiang/zookeeper-3.3.6/bin/../lib/log4j-1.2.15.jar:/usr/local/jiang/zookeeper-3.3.6/bin/../lib/jline-0.9.94.jar:/usr/local/jiang/zookeeper-3.3.6/bin/../src/java/lib/*.jar:/usr/local/jiang/zookeeper-3.3.6/bin/../conf:.:/usr/local/jdk1.7.0_71/lib:/usr/local/jdk1.7.0_71/lib/dt.jar:/usr/local/jdk1.7.0_71/lib/tools.jar
- 2015-08-18 10:23:48,972 - INFO [main:Environment@97] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
- 2015-08-18 10:23:48,972 - INFO [main:Environment@97] - Client environment:java.io.tmpdir=/tmp
- 2015-08-18 10:23:48,973 - INFO [main:Environment@97] - Client environment:java.compiler=
- 2015-08-18 10:23:48,973 - INFO [main:Environment@97] - Client environment:os.name=Linux
- 2015-08-18 10:23:48,974 - INFO [main:Environment@97] - Client environment:os.arch=amd64
- 2015-08-18 10:23:48,974 - INFO [main:Environment@97] - Client environment:os.version=2.6.32-431.el6.x86_64
- 2015-08-18 10:23:48,975 - INFO [main:Environment@97] - Client environment:user.name=root
-