由于项目需要,需要在集群中安装好Zookeeper,这里我选择最新版本的Zookeeper3.4.5。
ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护、名字服务、分布式同步、组服务等。ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。它也是Google的Chubby一个开源的实现,是高有效和可靠的协同工作系统,Zookeeper能够用来leader选举,配置信息维护等,在一个分布式的环境中,需要一个Master实例或存储一些配置信息,确保文件写入的一致性等。
当然你运行一个zookeeper也是可以的,但是在生产环境中,你最好部署3,5,7个节点。部署的越多,可靠性就越高,zookeeper集群是以宕机个数过半才会让整个集群宕机的,所以奇数个集群更佳。这里我选择三台机器,hostname分别为master、node1、node2。其中master机器作为Zookeeper集群的Master。下面一步一步说明如何安装分布式zookeeper。
1、下载最新版的zookeeper,然后解压到相应的目录里面(本文解压的目录为/home/wyp/Downloads):
[wyp@master Downloads]$ wget http://mirrors.cnnic.cn/ apache/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz [wyp@master Downloads]$ tar -zxvf zookeeper-3.4.5.tar.gz
解压的文件夹名为zookeeper-3.4.5,下文将用ZOOKEEPER_HOME作为Zookeeper的安装目录。
2、修改Zookeeper的默认配置文件,如下:
[wyp@master zookeeper-3.4.5]$ cd conf/ [wyp@master conf]$ ls -l 总用量 12 -rw-r--r--. 1 wyp wyp 535 Oct 1 2012 configuration.xsl -rw-r--r--. 1 wyp wyp 2161 Oct 1 2012 log4j.properties -rw-r--r--. 1 wyp wyp 808 Oct 1 2012 zoo_sample.cfg [wyp@master conf]$ cp zoo_sample.cfg zoo.cfg [wyp@master conf]$ vim zoo.cfg 将里面的默认配置修改为如下(当然,具体配置可以根据你机器来定): 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. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/home/wyp/zookeeper # the port at which the clients will connect clientPort=2181 server.1=master:2888:3888 server.2=node1:2888:3888 server.3=node2:2888:3888
3、在刚刚zoo.cfg文件中dataDir属性指定的目录(本文中为/home/wyp/zookeeper)下创建一个myid,在里面添加你指定的server编号,因为这台机器是master,而zoo.cfg中master编号为1(server.1=master:2888:3888),所以myid内容只需要为1即可。
[wyp@master conf]$ mkdir /home/wyp/zookeeper [wyp@master conf]$ vim /home/wyp/zookeeper/myid 1 [wyp@master conf]$
这样就在master机器上配置好Zookeeper,接下来只需要将master配置好的Zookeeper整个目录打包分发到node1、node2机器中:
4、打包、分发到node1、node2:
[wyp@master Downloads]$ tar -zcvf zookeeper.tar.gz zookeeper-3.4.5 [wyp@master Downloads]$ scp zookeeper.tar.gz node1:/home/wyp/Downloads [wyp@master Downloads]$ scp zookeeper.tar.gz node2:/home/wyp/Downloads
5、分别登陆node1、node2,并将刚刚发送的zookeeper.tar.gz文件解压:
[wyp@master Downloads]$ ssh node1 Last login: Sat Jan 18 16:46:50 2014 from master [wyp@node1 ~]$ cd /home/wyp/Downloads/ [wyp@node1 Downloads]$ tar -zxf zookeeper.tar.gz [wyp@node1 Downloads]$
并在node1的/home/wyp/zookeeper/myid文件中添加2。同理,node2的操作和上面一样,这里就不说了。
6、分别在master、node1、node2机器上启动Zookeeper相关服务:
[wyp@master Downloads]$ $ZOOKEEPER_HOME/bin/zkServer.sh start JMX enabled by default Using config: /home/wyp/Downloads/zookeeper-3.4.5/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
这样就安装并启动了Zookeeper分布式集群。
7、测试Zookeeper是否安装成功:
[wyp@master Downloads]$ $ZOOKEEPER_HOME/bin/zkCli.sh -server master:2181 Connecting to master:2181 ##########################################、 这里输出一大推信息,就不列出 ########################################## [zk: master:2181(CONNECTED) 0] ls / [zookeeper] [zk: master:2181(CONNECTED) 1] ls / [zookeeper] [zk: master:2181(CONNECTED) 2] create /wyp hello(/wyp为创建的文件名,内容为hello) Created /wyp [zk: master:2181(CONNECTED) 3] ls / [wyp, zookeeper] [zk: master:2181(CONNECTED) 4] get /wyp hello cZxid = 0x100000004 ctime = Sun Jan 19 15:08:58 CST 2014 mZxid = 0x100000004 mtime = Sun Jan 19 15:08:58 CST 2014 pZxid = 0x100000004 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 5 numChildren = 0 [zk: master:2181(CONNECTED) 5] set /wyp zookeeper cZxid = 0x100000004 ctime = Sun Jan 19 15:08:58 CST 2014 mZxid = 0x100000005 mtime = Sun Jan 19 15:09:31 CST 2014 pZxid = 0x100000004 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 9 numChildren = 0 [zk: master:2181(CONNECTED) 6] get /wyp zookeeper cZxid = 0x100000004 ctime = Sun Jan 19 15:08:58 CST 2014 mZxid = 0x100000005 mtime = Sun Jan 19 15:09:31 CST 2014 pZxid = 0x100000004 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 9 numChildren = 0 [zk: master:2181(CONNECTED) 7] delete /wyp [zk: master:2181(CONNECTED) 8] ls / [zookeeper] [zk: master:2181(CONNECTED) 9] quit Quitting... 2014-01-19 15:10:07,064 [myid:] - INFO [main-EventThread: ClientCnxn$EventThread@509] - EventThread shut down 2014-01-19 15:10:07,064 [myid:] - INFO [main:ZooKeeper@684] - Session: 0x143a94f84230001 closed [wyp@master Downloads]$
好了,至此整个Zookeeper已经安装完成。
本博客文章除特别声明,全部都是原创!原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载。
本文链接: 【Zookeeper 3.4.5分布式安装手册】(https://www.iteblog.com/archives/904.html)
http://www.iteblog.com/archives/date/2014/01
TIPS 文章摘要显示有错位
刚刚我在调试博客,可能中间出现了数据问题,现在好了。谢谢支持 🙄
是啊,今天刚刚换的风格挺好的。WordPress果然很强大。 😳
嗯,之前的主题用了好久。所以换了一个。里面有bug,所以线上调。