本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:xttblog2,之前的微信号好友位已满,备注:返现
受密码保护的文章请关注“业余草”公众号,回复关键字“0”获得密码
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
腾讯云】1核2G5M轻量应用服务器50元首年,高性价比,助您轻松上云
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。
ZooKeeper包含一个简单的原语集,提供Java和C的接口。
ZooKeeper代码版本中,提供了分布式独享锁、选举、队列的接口,代码在zookeeper-3.4.3\src\recipes。其中分布锁和队列有Java和C两个版本,选举只有Java版本。
今天为大家分享一下,如何安装单机的Zookeeper和如何搭建Zookeeper集群?
准备安装软件
- Ubuntu 14.04.4 64位
- Oracle JDK 1.8.0_112
- Zookeeper 3.4.9
单机安装教程
Step 1:环境准备,准备一台ubuntu系统的服务器,ip地址为:192.168.10.100,并且已经安装并配置好Oracle JDK 1.8.0_112。
Step 2:去Zookeeper官网下载最新的稳定版本,当前最新的稳定版本是Release 3.4.9。
Step 3:解压缩zookeeper-3.4.9.tar.gz到/opt/下(可以安装到其他目录,我这里安装到/opt/下),进入/conf/目录,创建zoo.cfg:cp zoo_sample.cfg zoo.cfg。
Step 4:修改zoo.cfg配置文件:vim zoo.cfg,内容如下:
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=5 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=2 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/opt/zookeeper_data # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1
上面配置修改了默认的dataDir到/opt/zookeeper_data。
Step 5:进入/bin/目录下,启动zookeeper:./zkServer.sh start。
Step 6:连接zookeeper: ./zkCli.sh -server 127.0.0.1:2181,如果成功连接,则zookeeper单机配置并启动成功。
集群安装教程
准备3台机器,IP分别为:192.168.10.100、192.168.10.101、192.168.10.102,系统均为Ubuntu 14.04.4 64位,并安装配置好Oracle JDK 1.8.0_112。
Step 1:参考前文的单机安装步骤,分别下载Zookeeper3.4.9并解压缩到/opt/下,并创建好/conf/zoo.cfg文件。
Step 2:三台机器的/conf/zoo.cfg都修改为如下内容:
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=5 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=2 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/opt/zookeeper_data # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.1=192.168.10.100:2888:3888 server.2=192.168.10.101:2888:3888 server.3=192.168.10.102:2888:3888
Step 3:分别在/opt/zookeeper_data(根据自己的dataDir确定)下创建myid:
192.168.10.100:echo 1 > myid
192.168.10.101:echo 2 > myid
192.168.10.102:echo 3 > myid
Step 4:分别启动各个机器下的Zookeeper:./bin/zkServer.sh start
Step 5:查看状态:./zkServer.sh status
最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号:xttblog2。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!
本文原文出处:业余草: » Zookeeper单机、集群安装教程