hbase远程调试源码的方法和步骤
=============获取hbase-server源码=====================
hbase-regionserver源码调试的前提是有源码
有个比较简单的办法可以弄到hbase对应版本的源码
先随便弄个maven、sprinboot项目,引入下面的依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>regionserver1Dome</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>regionserver1Dome</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<hbase.version>2.0.2</hbase.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<artifactId>javax.el</artifactId>
<groupId>org.glassfish</groupId>
<version>3.0.1-b12</version>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>5.0.0-HBase-2.0</version>
<!--wjh尝试解决冲突-->
<exclusions>
<exclusion>
<artifactId>javax.el</artifactId>
<groupId>org.glassfish</groupId>
</exclusion>
<exclusion>
<artifactId>hadoop-hdfs</artifactId>
<groupId>org.apache.hadoop</groupId>
</exclusion>
<exclusion>
<artifactId>hadoop-hdfs-client</artifactId>
<groupId>org.apache.hadoop</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--以下为源码jar包可删除-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>${hbase.version}</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>${hbase.version}</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 指定jdk -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<skip>true</skip>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果你的hbase版本不是2.0.2,只需要对应改下pom中的版本号就行了。
然后idea中把jar包源码下载下来
接着你就能点进jar包看源码了
=============idea配置====================
host填入你要远程调试的服务器的ip
部分内容我复制出来
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8765
其它内容参考图片
=============linux环境配置====================
远程调试需要打开端口,如果端口都打不开就没办法网络通讯了,需要保证本地和远程是通网的
退出容器查看端口
iptables -n -t nat -L
容器外添加打开的端口
如命令:iptables -t nat -A DOCKER -p tcp --dport ${port1} -j DNAT --to-destination ${ip}:${port1}
比如iptables -t nat -A DOCKER -p tcp --dport 8765 -j DNAT --to-destination 172.17.157.14:8765
=============hbase-server配置====================
在regionserver的配置文件里加上这个jvm参数(小心空格),如果suspend=y,那么idea没启动起来的时候,regionserver也无法启动起来,我一般使用n
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8765,server=y,suspend=n
重启regionserver生效
hbase-daemon.sh stop regionserver
hbase-daemon.sh start regionserver
先启动regionserver,然后再启动idea的调试,不然有时候idea的调试启动不起来
有的时候也会出现regionserver启动后卡住,需要idea启动后才能继续运行的情况
在合适的地方加上断点,比如JvmPauseMonitor的run方法,这个方法在hbaseregionserver运行的时候几乎每秒运行一遍,如果你的idea成功在这个断点停下来了,说明你已经成功连接了
其他大佬的文档
https://blog.csdn.net/lo085213/article/details/102922720