前言
Linux版本:CentOS-6.7-x86_64-bin-DVD1.iso (链接:点击打开链接 密码:h51u)
JDK版本:1.8(JDK安装过程参考:点击打开链接)
Zookeeper版本:3.4.6
注:本文安装的是单机模式,适合初学者进行
安装
step1 下载Zookeeper并解压
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
tar -zxvf zookeeper-3.4.6.tar.gz
mv zookeeper-3.4.6 zookeeper (修改根目录名字)
step2 添加文件夹和文件
在Zookeeper根目录下添加两个文件夹data、logs
mkdir data
mkdir logs
进入到data文件夹下,添加一个文件myid,里面的内容先填写1,后面会讲怎么填写!
step3 修改配置文件
在conf文件夹下面新建一个文件,命名为zoo.cfg,内容如下(注意修改dataDir和dataLogDir路径):
# 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= /usr/local/zookeeper/data dataLogDir= /usr/local/zookeeper/logs # 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 #2888,3888 are election port server.1=zookeeper:2888:38888
参照zoo.cfg里面最后一行server.1,在data/myid里面加入一个数字:1;
里面就一个数字,用来唯一标识这个服务!!!
server.A=B:C:D;其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。
step4 添加环境变量
在/etc/profile文件中设置PATH,注意修改路径
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH
export PATH
step5 测试
执行
zkServer.sh start
出现下列信息表示启动成功:
扩展
Zookeeper启动关闭相关命令
zkServer.sh status ---查询状态
zkServer.sh stop ---关闭
zkServer.sh restart ---重启