Rainbond: Production-level Serverless PaaS Rainbond is the first open source production-level serverless PaaS in China, which deeply integrates kubernetes-based container management, multi-type CI/CD application construction and delivery, multi-data center resource management and other technologies, providing cloud native application lifecycle solutions. Build an ecosystem of connectivity between applications and infrastructure, between applications and between infrastructures. Click on the install

In order for your application to withstand more concurrency and improve application stability, you need to expand the capacity when appropriate. Tomcat under each node only stores sessions generated when it accesses its own requests. In order to solve the problem of session persistence after capacity expansion, we provide a Java War package project that uses Tomcat to configure Redis to realize the session sharing solution. Store your session in Redis to keep your application stable. As shown in the figure:

If Load Balancing sends requests to Tomcat A in Container 1 and generates A session, the session will be persisted in Redis. When the Web Server sends A request to Tomcat A of Container 2, the Existing session is found in Redis.

Through the source code construction, you can configure redis to implement session sharing in the following two ways:

Use Webapp-runner or Jetty-runner

Cloud Bang uses Tomcat embedded in Webapp-Runner or Jetty embedded in Jetty-Runner to implement server functions. You can easily deploy your application to a cloud gang without creating additional servers. You can perform the following steps to configure redis to achieve session sharing.

  1. Configure Procfile: Add the following command to your Procfile and add Procfile in the source directory.

    web: java -jar ./webapp-runner.jar --port 5000 --session-store redis ./*.war
    Copy the code
    • Application port 8080. The platform enables application port 5000 by default. To ensure normal port mapping:
      • Specify the port in Procfile--port 5000
      • Set port 8080 in application Console – Port
    • Specifying session storage--session-store redis
  2. Configure webServer: add the webserver file in the source root directory, write the current platform support webapp-runner version:

    Webapp - runner - 7.0.57.2. JarCopy the code
    Webapp - runner - 8.0.18.0 - M1. JarCopy the code
    Webapp - runner - 8.5.5.2. JarCopy the code
  3. Cloud help through the source code to create applications, in the create application – application Settings to select the created Redis for dependency association.

  4. Application configuration Redis: Add REDIS_URL to the application environment variable with the value 127.0.0.1:6379.

  5. Restart the application to fit

To facilitate application creation, you are advised to create Redis applications in the application market in advance. If you do not rely on the Redis application during creation, you can also associate the Redis application on the Application Console – Dependencies after the application is created. Remember to restart the application after association.

Use docker images

Cloud Help provides a way to start applications using custom Tomcat containers. You can perform the following steps to configure redis to achieve session sharing.

  1. Create a Dockerfile and write the following:

    • Use the source code
    Copy the code

Dockerfile FROM goodrainapps/tomcat: 7.0.82 jre7 – alpine RUN rm/usr/local/tomcat/webapps/ROOT COPY < dir_name > / usr/local/tomcat/webapps/ROOT # < dir_name > to EXPOSE 8080 source directory name

- use the war package ` ` ` dockerfile FROM goodrainapps/tomcat: 7.0.82 jre7 - alpine RUN rm/usr /local/tomcat/webapps/ROOT
COPY <filename>.war /usr/local/tomcat/webapps/ROOT.war
EXPOSE 8080
Copy the code
  1. Verify that

    or

    . War of the source code exists and is in the same directory as the Dockerfile file. Use this directory as the root directory to create the application.

  2. Under Create Application – Application Settings select the created Redis for dependency association.

  3. Application configuration REDis: Add the variable REDIS_URL to the application environment variable. The value is 127.0.0.1:6379. Configure the variable REDIS_SESSION to the application environment variable with the value true.

  4. Restart the application to fit