ZooKeeper

ZooKeeper
分布式模式(Replicated mode)


第一步:主机名称到IP地址映射配置

vim /etc/hosts

10.10.100.85        zookper_01
10.10.100.86        zookper_02
10.10.100.87        zookper_03

第二步:安装JDK.

tar -zxvf jdk1.6.0_45.tar.gz -C /apps/product/

ln -s /apps/product/jdk1.6.0_45 java

vim /etc/profile

JAVA_HOME=/apps/product/java
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH 

查看jdk版本:java -version

第三步:安装Zookeeper

tar -zxvf zookeeper-3.3.6.tar.gz -C /apps/product/

cd /apps/product/zookeeper-3.3.6/conf
修改配置文件conf/zoo.cfg #将zoo_sample.cfg拷贝为zoo.cfg

ickTime=2000       

dataDir=/var/lib/zookeeper/

initLimit=5

syncLimit=2

clientPort=2181

server.1=zookper_01:2888:3888

server.2=zookper_02:2888:3888

server.3=zookper_03:2888:3888

远程复制分发安装文件

上面已经在一台机器slave-01上配置完成ZooKeeper,现在可以将该配置好的安装文件远程拷贝到集群中的各个结点对应的目录下:

cd /apps/product/
scp -r zookeeper-3.3.6/ [email protected]:/apps/product/
scp -r zookeeper-3.3.6/ [email protected]:/apps/product/


设置myid文件
要在每台机器的dataDir下,新建一个myid文件,里面存放一个数字,用来标识当前主机。

mkdir /var/lib/zookeeper/

[root@zookper_01 ~]# echo "1" >> /var/lib/zookeeper/myid
[root@zookper_02 ~]# echo "2" >> /var/lib/zookeeper/myid
[root@zookper_03 ~]# echo "3" >> /var/lib/zookeeper/myid


JAVA_HOME=/apps/product/java
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
PATH=$JAVA_HOME/bin:$PATH
ZOOKEEPER_HOME=/apps/product/zookeeper-3.3.6
export JAVA_HOME CLASSPATH PATH ZOOKEEPER_HOME

第四步:启动ZooKeeper集群

[root@zookper_01 ~]# ./bin/zkServer.sh start  
[root@zookper_02 ~]# ./bin/zkServer.sh start  
[root@zookper_03 ~]# ./bin/zkServer.sh start  


可以通过ZooKeeper的脚本来查看启动状态,包括集群中各个结点的角色(或是Leader,或是Follower)

./bin/zkServer.sh status

JMX enabled by default
Using config: /apps/product/zookeeper-3.3.6/bin/../conf/zoo.cfg
Mode: follower

jps 
 4468 Jps
4361 QuorumPeerMain


./bin/zkCli.sh -server zookper_01:2181

create -e /t tdata 


tail -100f zookeeper.out 

 

你可能感兴趣的:(ZooKeeper)