3、安装ZooKeeper集群
- 下载
http://apache.fayea.com/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
- 将ZooKeeper安装到/usr/local/zookeeper
tar -xvzf zookeeper-3.4.10.tar.gz -C /usr/local
mv /usr/local/zookeeper-3.4.10 /usr/local/zookeeper
- 修改/etc/profile,末尾添加以下内容:
# ZooKeeper
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
- 拷贝配置文件{ZOOKEEPER_HOME}/conf/zoo.cfg
$cp {ZOOKEEPER_HOME}/conf/zoo_sample.cfg {ZOOKEEPER_HOME}/conf/zoo.cfg
- 修改zoo.cfg
# 配置数据目录,使用默认即可,不过要记住该目录,下一步要用
dataDir=/tmp/zookeeper
# 配置集群主机,记住server.1中这个数字,下一步要用
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
- 创建数据目录
$mkdir /tmp/zookeeper
- 在/tmp/zookeeper下创建myid文件,并输入id,id值与zoo.cfg中对应
$touch myid
$echo "1" > /tmp/zookeeper/myid
- 拷贝到其他节点
scp -r /usr/local/zookeeper/ root@node2:/usr/local/
scp -r /usr/local/zookeeper/ root@node3:/usr/local/
scp -r /tmp/zookeeper/ root@node2:/tmp/
scp -r /tmp/zookeeper/ root@node3:/tmp/
在其他节点上创建/tmp/zookeeper目录和myid文件,并输入相应ID(略)
启动,注意:这个需要分别在每台zookeeper主机上执行
zkServer.sh start #启动
zkServer.sh status #查看
zkServer.sh stop #停止