Liubsyy / HotSecondsIDEA

HotSeconds是一款Java远程热部署的插件,可实现秒级一键化热更新。插件分为HotSecondsClient(IDEA热部署插件)和HotSecondsServer(服务端javaagent热更新插件),可以热更新java和常用配置文件,也支持常用框架(Spring,MyBatis)的热更新,相对传统部署可节省大量时间提高开发效率。
GNU General Public License v2.0
382 stars 50 forks source link

服务端启动了但是,客户端连不上 #7

Closed nanxing7 closed 1 year ago

nanxing7 commented 1 year ago
[root@vm12345-1214332 HotSecondsServer]# java -XXaltjvm=dcevm -javaagent:HotSecondsServer.jar=hotconf=hot-seconds-remote.xml
HOTSECONDS: 18:40:17.886 INFO findAllDependencyClasses[]
HOTSECONDS: 18:40:17.886 INFO findAllDependencyClasses[/root/HotSecondsServer/HotSecondsServer.jar]
HOTSECONDS: 18:40:17.889 INFO findNeedClassLoaderDonesun.misc.Launcher$AppClassLoader@18b4aac2
HOTSECONDS: 18:40:17.890 INFO Loading Hotswap agent {1.4.1} - unlimited runtime class redefinition.
HOTSECONDS: 18:40:17.890 WARNING Invalid javaagent option 'hotconf'. Argument 'hotconf=hot-seconds-remote.xml' is ignored.
HOTSECONDS: 18:40:18.423 INFO Discovered plugins: [Hotswapper, JdkPlugin, AnonymousClassPatch, ClassInitPlugin, WatchResources, Hibernate, Hibernate3JPA, Hibernate3, Spring, Jersey1, Jersey2, Jetty, Tomcat, ZK, Logback, Log4j2, MyFaces, Mojarra, Omnifaces, ELResolver, WildFlyELResolver, OsgiEquinox, Owb, Proxy, WebObjects, Weld, JBossModules, ResteasyRegistry, Deltaspike, GlassFish, Vaadin, Wicket, CxfJAXRS, FreeMarker, Undertow, MyBatis]
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -server       to select the "server" VM
                  The default VM is server,
                  because you are running on a server-class machine.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
HOTSECONDS: 18:40:21.481 INFO HotDeployService热部署服务启动成功

启动后 hotseconds_err.log

100
101
102
200
201
202
100
200
201
202
100
200
201
202
100
200
201
202
100
200
201
202
100
200
201
202
100
200
201
202
100
100
100
100
100
200
201
202
100
200
201
202
100
200
201
202
100
[root@vm12345-1214332 ~]# lsof -i:12023
COMMAND   PID USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
java    23552 root   18u  IPv6 924706608      0t0  TCP *:12023 (LISTEN)

配置文件 hot-seconds-remote.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- 一键秒级远程热部署配置文件 -->
<!-- 此配置文件一共两套,为hot-seconds.xml和hot-seconds-remote.xml -->
<liubs>
    <!-- 这个是本地和远程连接的唯一id,务必保证hot-seconds.xml和hot-seconds-remote.xml相等 -->
    <secret>aaaaaaaabbbbbbbbbccccccccc</secret>

    <!-- 远程端口 -->
    <remote_port>12023</remote_port>

    <init_delay>3000</init_delay>

    <!-- 
        普通java项目填 AppClassLoader,
        Tomcat项目填 WebappClassLoader/ParallelWebappClassLoader(Tomcat8及以后的版本填ParallelWebappClassLoader), 
        SpringBoot项目填 LaunchedURLClassLoader 
    -->
    <classloader>AppClassLoader</classloader>

    <!-- 这里的扩展classname是热加载某个文件的前置和后置操作,需要实现IHotExtHandler接口,复制IHotExtHandler.java到工程即可 -->
    <dev-ext>
        <!--<classname>com.liubs.ext.XXHandler</classname>-->
    </dev-ext>

</liubs>

配置文件 hot-seconds.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- 一键秒级远程热部署配置文件 -->
<!-- 此配置文件一共两套,为hot-seconds.xml和hot-seconds-remote.xml -->
<!-- 此配置文件本地改完重新打开插件开关生效 -->
<liubs>
    <author>liubsyy</author>

    <!-- 这个是本地和远程连接的唯一id,务必保证本地和远程相等 -->
    <secret>aaaaaaaabbbbbbbbbccccccccc</secret>

    <!-- 远程ip -->
    <remote_ip>xxx.xxx.xxx.xxx</remote_ip>

    <iplist>xxx.xxx.xxx.xxx</iplist>

    <!-- 远程端口 -->
    <remote_port>12023</remote_port>

    <!-- timeout : ms-->
    <timeout>3000</timeout>

    <!-- 是否自动部署,如果为true则监听文件变化自动部署到远程 -->
    <auto_hotdeploy>false</auto_hotdeploy>

    <!-- 本地路径和远程路径mapping关系 -->
    <!-- ****** 填写路径path和remote-path须知 ******
    1.file_type为上传文件的后缀,如果有多个用英文逗号隔开
    2.path为本地路径, remote-path为远程路径
    3.$rootPath$为本地工程根目录,remote-path需要填绝对路径
    4.上传到远程路径的规则: ${path}/dir1/dir2/a.html ==> ${remote-path}/dir1/dir2/a.html
    5.如果file_type是.java或.class,可不填mapping,直接热到内存生效
    -->
    <mappings>

        <mapping>
            <file_type>.class</file_type>
            <path>$rootPath$/next-server/next-user-webapp/target/classes</path>
            <remote-path>/opt/web/xx/webapps/WEB-INF/classes</remote-path>
        </mapping>

        <!-- 下面是两个例子,仅供参考
         1.将src/main/webapp下的资源文件上传到远程的/opt/web/xx/webapps目录下
         2.将target/classes目录下的.class文件上传到远程的/opt/web/xx/webapps/WEB-INF/classes目录下
         <mapping>
             <file_type>.html,css,js</file_type>
             <path>$rootPath$/src/main/webapp</path>
             <remote-path>/opt/web/xx/webapps</remote-path>
         </mapping>
         <mapping>
             <file_type>.class</file_type>
             <path>$rootPath$/target/classes</path>
             <remote-path>/opt/web/xx/webapps/WEB-INF/classes</remote-path>
         </mapping>
         -->
    </mappings>

</liubs>
Liubsyy commented 1 year ago

远程是本地开的虚拟机吧,看着远程ip被映射成了127.0.0.1,你用的是哪种虚拟机网络连接模式?

Liubsyy commented 1 year ago

试试在远程服务器加上jvm参数:-Djava.rmi.server.hostname=$YourIp

nanxing7 commented 1 year ago

现在提示 java.net.ConnectException: Operation timed out

nanxing7 commented 1 year ago

远程是本地开的虚拟机吧,看着远程ip被映射成了127.0.0.1,你用的是哪种虚拟机网络连接模式?

直接部署在机器上的

nanxing7 commented 1 year ago

我看 server 代码里面

Liubsyy commented 1 year ago

我看 server 代码里面

这个只是个告警,最新版就没有告警:WARNING Invalid javaagent option 'hotconf'. Argument 'hotconf=hot-seconds-remote.xml' is ignored.

Liubsyy commented 1 year ago

连接不上本质上还是网络不通,你能确认下正常的socket连接到远程的服务端是通的吗?