zookeeper的安装与部署
一,简介
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
二,环境
jdk: 1.8.0_271
系统:Centos 7
zookeeper
三,安装
*** 注意:本文的安装是第一次安装zookeeper,安装没有很大的问题。但是选错了安装包。建议大家在下载安装包的时候选择带bin的安装包下载,里面带了需要的zookeeperjar包。如果选择的是不带bin的还需要自行安装maven来下载相应的jar***
本文是基于阿里云Centos 7,并且需要自行安装好jdk
- 把zookeeper安装包,在/usr/local/java/下执行
tar -zxvf apache-zookeeper-3.7.0.tar.gz
- 安装目录下创建data文件夹,用于存放数据并且记录该目录/usr/local/java/apache-zookeeper-3.7.0/data/
mkdir data
- 进入conf文件夹执行,复制一份zoo_sample.cfg 并命名为zoo.cfg.
cp zoo_sample.cfg zoo.cfg
- 修改zoo.cfg文件
#编辑zoo.cfg文件 vim zoo.cfg
修改dataDir
dataDir=/usr/local/java/apache-zookeeper-3.7.0/data/
四,使用
- 启动:
进入bin目录下启动服务zkServer.sh
./zkServer.sh start
注意 :zookeeper最近的版本中有个内嵌的管理控制台是通过jetty启动,也会占用8080 端口。 ,而我们的Tomcat的默认端口也是8080.这就导致了端口冲突。可以修改Tomcat的默认端口或者关闭Tomcat服务器。
关闭Tomcat服务器后启动服务依然启动失败。执行一下命令查看启动状态
./zkServer.sh start-foreground
得到:
[root@qijian bin]# ./zkServer.sh start-foreground /usr/local/java/jdk1.8.0_271/bin/java ZooKeeper JMX enabled by default Using config: /usr/local/java/apache-zookeeper-3.7.0/bin/../conf/zoo.cfg Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
查看README.md文件
[root@qijian apache-zookeeper-3.7.0]# cat README.md # Apache ZooKeeper [![GitHub Actions CI][ciBadge]][ciLink] [![Travis CI][trBadge]][trLink] [![Maven Central][mcBadge]][mcLink] [![License][liBadge]][liLink] [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KOXgiAah-1617959168445)(https://zookeeper.apache.org/images/zookeeper_small.gif "ZooKeeper")] For the latest information about Apache ZooKeeper, please visit our website at: https://zookeeper.apache.org and our wiki, at: https://cwiki.apache.org/confluence/display/ZOOKEEPER ## Packaging/release artifacts Either downloaded from https://zookeeper.apache.org/releases.html or found in zookeeper-assembly/target directory after building the project with maven. apache-zookeeper-[version].tar.gz Contains all the source files which can be built by running: mvn clean install To generate an aggregated apidocs for zookeeper-server and zookeeper-jute: mvn javadoc:aggregate (generated files will be at target/site/apidocs) apache-zookeeper-[version]-bin.tar.gz Contains all the jar files required to run ZooKeeper Full documentation can also be found in the docs folder As of version 3.5.5, the parent, zookeeper and zookeeper-jute artifacts are deployed to the central repository after the release is voted on and approved by the Apache ZooKeeper PMC: https://repo1.maven.org/maven2/org/apache/zookeeper/zookeeper ## Java 8 If you are going to compile with Java 1.8, you should use a recent release at u211 or above. # Contributing We always welcome new contributors to the project! See [How to Contribute](https://cwiki.apache.org/confluence/display/ZOOKEEPER/HowToContribute) for details on how to submit patch through pull request and our contribution workflow. [ciBadge]: https://github.com/apache/zookeeper/workflows/CI/badge.svg [ciLink]: https://github.com/apache/zookeeper/actions [liBadge]: https://img.shields.io/github/license/apache/zookeeper?color=282661 [liLink]: https://github.com/apache/zookeeper/blob/master/LICENSE.txt [mcBadge]: https://img.shields.io/maven-central/v/org.apache.zookeeper/zookeeper [mcLink]: https://zookeeper.apache.org/releases [trBadge]: https://travis-ci.org/apache/zookeeper.svg?branch=master [trLink]: https://travis-ci.org/apache/zookeeper
通过阅读我们发现还需要我们安装maven。
仔细看会发现上面我解压的是apache-zookeeper-3.5.5.tar.gz 。注意是没有带bin的。网上一查发现apache-zookeeper-3.5.5-bin.tar.gz 自带所需要的各种jar包
真的是坑!!!!此处生气5秒钟。生气归生气学习我们还要继续。卸载重新安装吧
- 查看状态,是否成功启动
./zkServer.sh status
- 停止服务命令
./zkServer.sh stop
生气归生气学习我们还要继续。卸载重新安装吧
- 查看状态,是否成功启动
./zkServer.sh status • 1
- 停止服务命令
./zkServer.sh stop