安装zookeeper也很简单,下载zookeeper-3.1.1.tar.gz,解压到/home/hezhiming/zookeeper-3.1.1。zookeeper要部署到各台机器的相同目录下,且具有相同的配置文件。
配置:
clientPort
监听客户端连接的端口;
dataDir
存储内存中数据库快照的位置;
注意 应该谨慎地选择日志存放的位置,使用专用的日志存储设备能够大大地提高系统的性能,如果将日志存储在比较繁忙的存储设备上,那么将会在很大程度上影响系统的性能。
tickTime
基本事件单元,以毫秒为单位。它用来控制心跳和超时,默认情况下最小的会话超时时间为两倍的 tickTime 。
server.1=10.15.107.142:2888:3888
#server.2=hadoop.cluster.second_master:2888:3888
#server.3=hadoop.cluster.slave1:2888:3888
增加server.x选项,配置运行zookeeper的机器主机名或是IP地址,2888表示zookeeper程序监听端口,3888表示zookeeper选举通信端口。
注意:如果zookeeper启动不了,把系统默认防火墙关闭后再试:sudo service iptables stop。
我的虚拟机linux上的zookeeper配置:
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.
dataDir=/hadoop/zookeeper-3.3.6/zookeeper_data
# the port at which the clients will connect
clientPort=3355
server.1=10.15.82.166:2555:3555
启动和关闭zookeeper服务:
hfx@ubuntu:/hadoop/zookeeper-3.3.6/bin$ ./zkServer.sh start
JMX enabled by default
Using config: /hadoop/zookeeper-3.3.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
hfx@ubuntu:/hadoop/zookeeper-3.3.6/bin$ ./zkServer.sh stop
JMX enabled by default
Using config: /hadoop/zookeeper-3.3.6/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
监听:
hfx@ubuntu:/hadoop/zookeeper-3.3.6/bin$ echo ruok | nc 127.0.0.1 3355
imok
这样就代表了zookeeper服务启动成功啦。
集群的zookeeper配置其实也是如此:
比如我想配3台机器的伪分布,copy3份配置文件
-rwxrw-r-- 1 hfx hfx 502 Mar 3 17:19 zoo1.cfg*
-rwxrw-r-- 1 hfx hfx 502 Mar 3 17:19 zoo2.cfg*
-rwxrw-r-- 1 hfx hfx 502 Mar 3 17:20 zoo3.cfg*
内容大同小异:
# 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.
dataDir=/hadoop/zookeeper-3.3.6/zookeeper_data1
# the port at which the clients will connect
clientPort=3351
server.1=10.15.91.115:8881:7771
server.2=10.15.91.115:8882:7772
server.3=10.15.91.115:8883:7773
再建3个文件夹存放数据
drwxrwxr-x 3 hfx hfx 4096 Mar 11 00:29 zookeeper_data1/
drwxrwxr-x 3 hfx hfx 4096 Mar 11 00:29 zookeeper_data2/
drwxrwxr-x 3 hfx hfx 4096 Mar 11 00:29 zookeeper_data3/
记得每个文件夹下建一个myid的文件,里面写1或者2或者3。
启动
./zkServer.sh start zoo1.cfg
./zkServer.sh start zoo2.cfg
./zkServer.sh start zoo3.cfg
如此而已!