温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Zookeeper环境的搭建过程

发布时间:2021-07-09 16:53:36 来源:亿速云 阅读:141 作者:chen 栏目:大数据

本篇内容介绍了“Zookeeper环境的搭建过程”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

一、背景

个人习惯看源码的时候先编译成功并运行再开始看,现在大多数源码都是maven管理的,直接导入就行了,zookeeper由于年代比较久远,依赖管理还是用的Apache Ant,所以这里专门记录一下。

本文环境基于Windows10 1903 + Ant 1.10.6 + IDEA 2019.2

截止到本文写完,zookeeper的3.5.5和3.4.14版本已经有了pom.xml,但是编译的时候总是报org.apache.zookeeper.data不存在,使用ant编译之后发现这个包是在zookeeper-jute/target目录下,暂时不知道是啥情况,有懂的朋友可以留言一下:metal:

二、环境搭建

2.1 下载源码

从 https://github.com/apache/zookeeper/releases 下载你想要的版本源码并解压,这里下载的是3.4.14

2.2 安装Apache Ant

  1. 从 https://ant.apache.org/bindownload.cgi 下载ant发布包并解压,假设解压后的目录为D:\apache-ant-1.10.6

  2. 添加一个新的环境变量ANT_HOME=D:\apache-ant-1.10.6;在环境变量PATH中添加一条%ANT_HOME%\bin

  3. 打开cmd,运行ant -v查看是否配置成功
    Zookeeper环境的搭建过程

2.3 编译源码

打开cmd,进入解压后的zookeeper目录,运行ant eclipse将项目编译并转成eclipse的项目结构(因为IDEA不能识别ant项目,但是可以识别eclipse项目),然后等一段时间,我这边花了大概10分钟

2.4 导入源码

打开IDEA,选择导入eclipse项目,然后一路next即可

Zookeeper环境的搭建过程

Zookeeper环境的搭建过程

2.5 运行zookeeper

  1. 搜索QuorumPeerMain这个类,点击左侧的绿色三角运行一次

    Zookeeper环境的搭建过程

    默认运行前会build一下,这里编译会报错

    Zookeeper环境的搭建过程

    进入org.apache.zookeeper.Version这个类,看到一片红

    Zookeeper环境的搭建过程

    查了一下,这应该是zookeeper用来发布的时候生成版本用的,我们又不发布版本所以直接写死就行了

    修改完的代码如下

    public class Version  {
    
        /*
         * Since the SVN to Git port this field doesn't return the revision anymore
         * TODO: remove this method and associated field declaration in VerGen
         * @see {@link #getHashRevision()}
         * @return the default value -1
         */
        @Deprecated
        public static int getRevision() {
            return -1;
        }
    
        public static String getRevisionHash() {
            return "1";
        }
    
        public static String getBuildDate() {
            return "2019-08-11";
        }
    
        public static String getVersion() {
            return "3.4.14";
        }
    
        public static String getVersionRevision() {
            return getVersion() + "-" + getRevisionHash();
        }
    
        public static String getFullVersion() {
            return getVersionRevision() + ", built on " + getBuildDate();
        }
    
        public static void printUsage() {
            System.out
                    .print("Usage:\tjava -cp ... org.apache.zookeeper.Version "
                            + "[--full | --short | --revision],\n\tPrints --full version "
                            + "info if no arg specified.");
            System.exit(1);
        }
    
        /**
         * Prints the current version, revision and build date to the standard out.
         * 
         * @param args
         *            <ul>
         *            <li> --short - prints a short version string "1.2.3"
         *            <li> --revision - prints a short version string with the SVN
         *            repository revision "1.2.3-94"
         *            <li> --full - prints the revision and the build date
         *            </ul>
         */
        public static void main(String[] args) {
            if (args.length > 1) {
                printUsage();
            }
            if (args.length == 0 || (args.length == 1 && args[0].equals("--full"))) {
                System.out.println(getFullVersion());
                System.exit(0);
            }
            if (args[0].equals("--short"))
                System.out.println(getVersion());
            else if (args[0].equals("--revision"))
                System.out.println(getVersionRevision());
            else
                printUsage();
            System.exit(0);
        }
    }


    然后如果你再次运行,还是会报错,但是不重要,运行完之后上边会出现对应的配置项,进入修改

    Zookeeper环境的搭建过程

  2. 在命令行参数里指定配置文件的位置

    Zookeeper环境的搭建过程

  3. 进入conf目录,复制zoo_sample.cfg,重命名为zoo.cfg,根据自己需要进行修改,也可以不改

    Zookeeper环境的搭建过程

  4. 复制log4j.properties到zookeeper-server目录下

    Zookeeper环境的搭建过程

  5. 然后再次运行,就能看到熟悉的控制台启动界面了

    Zookeeper环境的搭建过程

“Zookeeper环境的搭建过程”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI