flume 源码编译 和 inteallij IDEA远程调试

1.本地环境:

apache-flume-1.8.0-src (官网下载源码,或者git下载)

java1.8

2.编译

    (1)用Inteallij IDEA 导入已下载的flume工程

    (2)修改flume-parent下的 pom.xml 添加 aliyun的仓库(加快下载,有些包直接从maven repository上下               载很慢 )

  <repositories><!-- 代码库 -->
        <repository>
            <id>maven-ali</id>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </snapshots>
        </repository>
    </repositories>

   

    (3)开始漫长的编译过程

    如果是第一次的话,可能下载包要花2个多小时

    中间可能会报错(报错主要是某些包没下载成功,此时可以手动从仓库中手动下载到本地,然后放在本地      的maven 包路径下,默认的本地的包路径是 C:\Users\你的用户名\.m2\repository 下面)

mvn clean
mvn install -DskipTests -U -Dtar

    (4)如果你只想编译某些模块,只需要在对应模块下执行

mvn install -DskipTests -U -Dtar

    (5)由于整个项目是用pom管理包和模块,十分方便,如果在整个编译过程中,某些模块你需要编译,        或者编译耗时,或者编译失败,并且你暂时用不到整个模块,可以从pom中注释掉这个模块,不做编译,      具体做法如下图所示(具体的根据你的需求操作即可):


 

3.远程调试:

(1)修改服务器上的 bin/flume-ng 中的JAVA_OPTS变量,支持远程调试

JAVA_OPTS="-Xmx20m -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y"

具体如下:

 

(2)Inteallij IDEA配置 ,远程调试


 

 

 
(3)在任意代码出打上断点


 

(4)启动flume-ng(按实际情况修改下面命令)

bin/flume-ng agent --conf conf --conf-file ./conf/flume-custom.properties --name hd1 -Dflume.root.logger=INFO,console

启动后日志如下:


  

(5)Inteallij IDEA 开始debug,可以发现在断点处停止,debug流程成功了


 

4.思考:

  • 源码编译耗时费力,需要耐心,熬过去了,会有很大收获,同样也是更好理解源码的开始,万事开头难
  • remote debug可以更方便的了解执行流程,学习源码的捷径

猜你喜欢

转载自coderlxl201209164551.iteye.com/blog/2418657