Best practices for deploying Java webapps with minimal downtime?

前端 未结 18 1825
我在风中等你
我在风中等你 2021-01-29 18:28

When deploying a large Java webapp (>100 MB .war) I\'m currently use the following deployment process:

  • The application .war file is expanded locally on the develop
相关标签:
18条回答
  • 2021-01-29 18:39

    Your approach to rsync the extracted war is pretty good, also the restart since I believe that a production server should not have hot-deployment enabled. So, the only downside is the downtime when you need to restart the server, right?

    I assume all state of your application is hold in the database, so you have no problem with some users working on one app server instance while other users are on another app server instance. If so,

    Run two app servers: Start up the second app server (which listens on other TCP ports) and deploy your application there. After deployment, update the Apache httpd's configuration (mod_jk or mod_proxy) to point to the second app server. Gracefully restarting the Apache httpd process. This way you will have no downtime and new users and requests are automatically redirected to the new app server.

    If you can make use of the app server's clustering and session replication support, it will be even smooth for users which are currently logged in, as the second app server will resync as soon as it starts. Then, when there are no accesses to the first server, shut it down.

    0 讨论(0)
  • 2021-01-29 18:39

    Just use 2 or more tomcat servers with a proxy over it. That proxy can be of apache/nignix/haproxy.

    Now in each of the proxy server there is "in" and "out" url with ports are configured.

    First copy your war in the tomcat without stoping the service. Once war is deployed it is automatically opened by the tomcat engine.

    Note cross check unpackWARs="true" and autoDeploy="true" in node "Host" inside server.xml

    It look likes this

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
    

    Now see the logs of tomcat. If no error is there it means it is up successfully.

    Now hit all APIs for testing

    Now come to your proxy server .

    Simply change the background url mapping with the new war's name. Since registering with the proxy servers like apache/nignix/haProxy took very less time, you will feel minimum downtime

    Refer -- https://developers.google.com/speed/pagespeed/module/domains for mapping urls

    0 讨论(0)
  • 2021-01-29 18:45

    It has been noted that rsync does not work well when pushing changes to a WAR file. The reason for this is that WAR files are essentially ZIP files, and by default are created with compressed member files. Small changes to the member files (before compression) result in large scale differences in the ZIP file, rendering rsync's delta-transfer algorithm ineffective.

    One possible solution is to use jar -0 ... to create the original WAR file. The -0 option tells the jar command to not compress the member files when creating the WAR file. Then, when rsync compares the old and new versions of the WAR file, the delta-transfer algorithm should be able to create small diffs. Then arrange that rsync sends the diffs (or original files) in compressed form; e.g. use rsync -z ... or a compressed data stream / transport underneath.

    EDIT: Depending on how the WAR file is structured, it may also be necessary to use jar -0 ... to create component JAR files. This would apply to JAR files that are frequently subject to change (or that are simply rebuilt), rather than to stable 3rd party JAR files.

    In theory, this procedure should give a significant improvement over sending regular WAR files. In practice I have not tried this, so I cannot promise that it will work.

    The downside is that the deployed WAR file will be significantly bigger. This may result in longer webapp startup times, though I suspect that the effect would be marginal.


    A different approach entirely would be to look at your WAR file to see if you can identify library JARs that are likely to (almost) never change. Take these JARs out of the WAR file, and deploy them separately into the Tomcat server's common/lib directory; e.g. using rsync.

    0 讨论(0)
  • 2021-01-29 18:45

    Not a "best practice" but something I just thought of.

    How about deploying the webapp through a DVCS such as git?

    This way you can let git figure out which files to transfer to the server. You also have a nice way to back out of it if it turns out to be busted, just do a revert!

    0 讨论(0)
  • 2021-01-29 18:49

    Can't you make a local copy of the current web application on the web server, rsync to that directory and then perhaps even using symbolic links, in one "go", point Tomcat to a new deployment without much downtime?

    0 讨论(0)
  • 2021-01-29 18:50

    Hot Deploy a Java EAR to Minimize or Eliminate Downtime of an Application on a Server or How to “hot” deploy war dependency in Jboss using Jboss Tools Eclipse plugin might have some options for you.

    Deploying to a cluster with no downtime is interesting too.

    JavaRebel has hot-code deployement too.

    0 讨论(0)
提交回复
热议问题