一. 目标
在Linux集群搭建Zookeeper集群,并配置管理Web管理系统。
二. 先决条件
本文档中基于VirtualBox Ubuntu Server 13.04 虚机(启动SSH服务器)构建。
三. 安装 Zookeeper环境
l 下载jdk-7u51-linux-x64.gz (预先下载到局域网环境)
l cpsing@Zookeeper-Cluster1:~# wget ftp://192.168.1.104/jdk-7u51-linux-x64.gz
l cpsing@Zookeeper-Cluster1:~# sudo cp jdk-7u51-linux-x64.gz /usr/local/
l cpsing@Zookeeper-Cluster1:sudo /usr/local# tar zxvf jdk-7u51-linux-x64.gz
l cpsing@Zookeeper-Cluster1:/usr/local/jdk1.7.0_51$ sudo vi /etc/profile
l 增加如下
export JAVA_HOME=/usr/local/jdk1.7.0_51
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
l cpsing@Zookeeper-Cluster1:/usr/local/jdk1.7.0_51$ source /etc/profile
l cpsing@Zookeeper-Cluster1:/usr/local/jdk1.7.0_51$ java -version
l cpsing@Zookeeper-Cluster1:/usr/local$ sudo wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
l cpsing@Zookeeper-Cluster1:/usr/local$ sudo tar zxvf zookeeper-3.4.6.tar.gz
l cpsing@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6$ sudo vi /etc/environment
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.6
export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf
l cpsing@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6/conf$ cp zoo_sample.cfg zoo.cfg
dataDir=/root/zookeeper
l cpsing@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6/conf$ sudo mkdir /root/zookeeper
l root@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6/bin# ./zkServer.sh start
l root@Zookeeper-Cluster1:/etc/init.d# ps -ef | grep 'zookeeper'
四.执行VM Clone
Clone两台VM,如果出现网卡不能使用的情况,则按如下操作:
l 删除 /etc/udev/rules.d/70-persistent-net.rules
l 重启机器
l 修改/etc/hosts:sudo vi /etc/hosts,然后修改 /etc/hostname
五.配置集群
l 修改三台服务器的 /etc/hosts
192.168.9.208 Zookeeper-Cluster1
192.168.9.178 Zookeeper-Cluster2
192.168.9.117 Zookeeper-Cluster3
l 修改三台服务器的zookeeper配置文件 增加如下;
server.1=Zookeeper-Cluster1:2888:3888
server.2=Zookeeper-Cluster2:2888:3888
server.3=Zookeeper-Cluster3:2888:3888
l 在我们配置的dataDir指定的目录下面,创建一个myid文件,里面内容为一个数字,用来标识当前主机,conf/zoo.cfg文件中配置的server.X中X为什么数字,则myid文件中就输入这个数字,例如:
root@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6/bin# echo "1" > /root/zookeeper/myid
root@Zookeeper-Cluster2:/usr/local/zookeeper-3.4.6/bin# echo "2" > /root/zookeeper/myid
root@Zookeeper-Cluster3:/usr/local/zookeeper-3.4.6/bin# echo "3" > /root/zookeeper/myid
l 检查集群状态
root@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6/bin# n./zkServer.sh status
root@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6/bin# n./zkServer.sh status
root@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6/bin# n./zkServer.sh status
如果显示如下:
root@Zookeeper-Cluster3:/usr/local/zookeeper-3.4.6/bin# n./zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
执行
root@Zookeeper-Cluster1:/usr/local/zookeeper-3.4.6/bin# tail -f zookeeper.out 查看日志
解决办法:
Sudo vi /etc/hosts
注释掉:127.0.0.1 开始的行,重启zookeeper 搞定!