Zookeeper安装

1 下载zookeeper

[root@host home]# mkdir zookeeper

[root@host zookeeper]# mkdir server1 server2 server3

[root@host zookeeper]# curl -O http://apache.fayea.com/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz

2 解压

[root@host zookeeper]# tar -zxvf zookeeper-3.4.9.tar.gz

拷贝到server1 server2 server3里面

3 配置

每个server下面创建几个文件夹  data datalog logs

[root@host zookeeper]# cd server1
[root@host server1]# mkdir data datalog logs

首先进入data目录,创建一个myid的文件,里面写入一个数字,比如我这个是server1,那么就写一个1,server2对应myid文件就写入2,server3对应myid文件就写个3

进入zookeeper-3.4.3/conf目录,那么如果是刚下过来,会有3个文件,configuration.xml, log4j.properties,zoo_sample.cfg,这3个文件我们首先要做的就是在这个目录创建一个zoo.cfg的配置文件,当然你可以把zoo_sample.cfg文件改成zoo.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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/zookeeper/server1/data
dataLogDir=/home/zookeeper/server1/datalog
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

在文件末尾添加如下内容:

server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890

clientPort这个端口如果你是在1台机器上部署多个server,那么每台机器都要不同的clientPort。最后几行唯一需要注意的地方就是 server.X 这个数字就是对应 data/myid中的数字。你在3个server的myid文件中分别写入了1,2,3,那么每个server中的zoo.cfg都配server.1,server.2,server.3就OK了。因为在同一台机器上,后面连着的2个端口3个server都不要一样,否则端口冲突,其中第一个端口用来集群成员的信息交换,第二个端口是在leader挂掉时专门用来进行选举leader所用。

4 启动

启动ZooKeeper伪机群的所有服务器
分别进入三个服务器的zookeeper-3.4.3/bin目录下,启动服务
./zkServer.sh start
启动完成后,查看服务器状态,
./zkServer.sh status

接入客户端
进入任意一个服务器的zookeeper/bin目录下,启动一个客户端,接入服务。

./zkCli.sh –server localhost:3181

原文地址:https://www.cnblogs.com/sysnap/p/7388675.html