Zookeeper 伪分布配置

系统:CentOS 7 64位

软件准备:zookeeper-3.4.6.tar.gz、JDK(自行安装,这里不进行描述)

配置环境:一台虚拟机,配置三个节点

三个节点分配目录:

/home/hadoop/zookeeper/zookeeper0

/home/hadoop/zookeeper/zookeeper1

/home/hadoop/zookeeper/zookeeper2


以下为配置过程

一、第一个节点 /home/hadoop/zookeeper/zookeeper0

1. 解压zookeeper-3.4.6.tar.gz

tar -zxvf zookeeper-3.4.6.tar.gz

2.重命名/home/hadoop/zookeeper/zookeeper0/conf下的zoo_sample.cgf
cp /home/hadoop/zookeeper/zookeeper0/conf/zoo_sample.cfg  /home/hadoop/zookeeper/zookeeper0/conf/zoo.cfg

3.修改zoo.cfg里的配置内容为
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/hadoop/zookeeper/zookeeper0/data
dataLogDir=/home/hadoop/zookeeper/zookeeper0/logs
clientPort=2181
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772

4.复制/home/hadoop/zookeeper/zookeeper0 为/home/hadoop/zookeeper/zookeeper1、/home/hadoop/zookeeper/zookeeper2
cp -r /home/hadoop/zookeeper/zookeeper0  /home/hadoop/zookeeper/zookeeper1
cp -r /home/hadoop/zookeeper/zookeeper0  
/home/hadoop/zookeeper/zookeeper2

5.修改zookeeper1、zookeeper2的zoo.cfg配置
zookeeper1为
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/hadoop/zookeeper/zookeeper0/data
dataLogDir=/home/hadoop/zookeeper/zookeeper0/logs
clientPort=2182
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
zookeeper2为
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/hadoop/zookeeper/zookeeper0/data
dataLogDir=/home/hadoop/zookeeper/zookeeper0/logs
clientPort=2183
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
6.分别在zookeeper0、zookeeper1、zookeeper2的data文件夹中添加myid文件,里面的内容为配置文件zoo.cfg中server-XXX 的XXX内容,可自定义分配到每个节点中myid的内容,但是不能重复
以zookeeper1为例
zookeeper1配置文件zoo.cfg配置文件内容为:
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/hadoop/zookeeper/zookeeper0/data
dataLogDir=/home/hadoop/zookeeper/zookeeper0/logs
clientPort=2182
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
则myid文件中的内容为1
其余两个节点myid 内容可以为0、2

7.分别启动zookeeper0、zookeeper1、zookeeper2
以启动zookeeper0为例
cd /home/hadoop/zookeeper/zookeeper0/bin
./zkServer.sh start
查看启动状态(zoo.cfg为第3步配置的文件)
./zkServer.sh status zoo.cfg
停止服务
./zkServer.sh stop
8.通过jps查看运行状态
jps
结果:
6998 QuorumPeerMain
7836 Jps
6956 QuorumPeerMain
7159 QuorumPeerMain
9.进行zookeeper客户端(2182为配置文件中的 clientPort属性配置)
./zkCli.sh -server 127.0.0.1:2182
结果:
Connecting to 127.0.0.1:2182
2015-09-21 14:20:00,152 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2015-09-21 14:20:00,154 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=hadoop
2015-09-21 14:20:00,154 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_75
2015-09-21 14:20:00,156 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2015-09-21 14:20:00,156 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/home/hadoop/java/jdk1.7.0_75/jre
2015-09-21 14:20:00,156 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/hadoop/zookeeper/zookeeper0/bin/../build/classes:/home/hadoop/zookeeper/zookeeper0/bin/../build/lib/*.jar:/home/hadoop/zookeeper/zookeeper0/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/hadoop/zookeeper/zookeeper0/bin/../lib/slf4j-api-1.6.1.jar:/home/hadoop/zookeeper/zookeeper0/bin/../lib/netty-3.7.0.Final.jar:/home/hadoop/zookeeper/zookeeper0/bin/../lib/log4j-1.2.16.jar:/home/hadoop/zookeeper/zookeeper0/bin/../lib/jline-0.9.94.jar:/home/hadoop/zookeeper/zookeeper0/bin/../zookeeper-3.4.6.jar:/home/hadoop/zookeeper/zookeeper0/bin/../src/java/lib/*.jar:/home/hadoop/zookeeper/zookeeper0/bin/../conf:.:/home/hadoop/java/jdk1.7.0_75/lib:/home/hadoop/java/jdk1.7.0_75/jre/lib
2015-09-21 14:20:00,156 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2015-09-21 14:20:00,156 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2015-09-21 14:20:00,156 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=
2015-09-21 14:20:00,157 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2015-09-21 14:20:00,157 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2015-09-21 14:20:00,157 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-229.el7.x86_64
2015-09-21 14:20:00,157 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=hadoop
2015-09-21 14:20:00,157 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/hadoop
2015-09-21 14:20:00,157 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/hadoop/zookeeper/zookeeper0/bin
2015-09-21 14:20:00,167 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2182 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@149ee0f1
2015-09-21 14:20:00,192 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
2015-09-21 14:20:00,196 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:2182, initiating session
Welcome to ZooKeeper!
JLine support is enabled
2015-09-21 14:20:00,294 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1235] - Session establishment complete on server 127.0.0.1/127.0.0.1:2182, sessionid = 0x14fee884cc30000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

以上为配置Zookeeper伪分布的配置过程。










你可能感兴趣的:(Zookeeper)