Deploy a mall e-commerce project on Rainbond in 10 minutes

Many small partners will toss about deployment for a long time when they are learning mall e-commerce projects. Although many deployment methods have been provided, such as, , 在 Linux 上部署 mallbut 使用 Docker 或 DockerCompose 部署 mallfor us who are learning, it is more complicated and we need to understand and learn these container technologies. In this article, we will use Rainbond to deploy the mall e-commerce project. It is very convenient and simple to deploy the mall project through Rainbond. Let us focus on the code. Rainbond is a cloud-native application management platform, which is easy to use and does not need to understand containers, Kubernetes and underlying complex technologies , easily deploy applications on Kubernetes and experience the capabilities brought by Kubernetes.

This article introduces two ways to deploy mall e-commerce projects on Rainbond:

  1. Quickly deploy malls through the Rainbond open source application store
  2. Deploy all services of the mall project from 0

premise

Install the available Rainbond environment, which can be installed on Linux, Mac, and Win, see Rainbond Quick Installation

Quickly deploy the mall through the app store

The mall e-commerce project has been released to the Rainbond open source app store, which can be deployed with one click through the open source app store , search malland Platform Management -> App Market -> Open Source App Store.

At this point, Rainbond will automatically build and start all services in the mall, just wait. After the deployment is complete, the topology diagram is as follows:

Access the mall-admin-webfront-end project to verify the deployment, the default user password:admin / macro123

mall-portalAnd there is no front-end mall-searchfor the time being , you can visit the back-end swagger to verify the deployment http://xxx/swagger-ui/, as follows:

Deploy mall from scratch

middleware deployment

The middleware that mall needs to use are: Mysql Redis RabbitMQ MongoDB ElasticSearch, which can be deployed through the Rainbond open source application store.

Install Redis

Search for Redis in the open source application store and install version 5.x

Install MongoDB

Search for MongoDB in the open source application store and install the 4.x version

Install RabbitMQ

Search for RabbitMQ in the open source application store and install it

Install MySQL

Search for MySQL in the open source application store and install version 5.7

  1. Open the external port service in Mysql component -> port , connect through IP:PORT, default user passwordroot / root
  2. Connect and import mall sql data through tools.

Install ElasticSearch

Search for ElasticSearch in the open source app store and install version 7.15.2

  • The ElasticSearch application includes Kinbana, if not needed, the Kinbana component can be deleted
  • ElasticSearch enables password authentication by default. Edit the configuration file in Component -> Environment Configuration -> Configuration File Settings to xpack.security.enabledset to falseand update the component to take effect.

Install the Chinese word breaker IK Analyzer

  1. First search for and install the plugin in TeamES-IK-Analysis View -> Plugins -> Add Plugins -> Install Plugins via App Store
  2. Add storage for ElasticSearch components, component -> storage -> add storage
    • name: custom
    • Mount path:/usr/share/elasticsearch/plugins
    • Type: shared storage
  3. Go to Components -> Plugins -> Unactivated , activate ES-IK-Analysisthe plugin
  4. Update or restart ElasticSearch components to take effect.

Deploy mall backend service

Modify project code configuration

pom.xmlComment executionthe part in the main file. It is not necessary to configure the Docker packaging project in the project. The packaging work is handed over to Rainbond. pom.xmlThe configuration is as follows:

<!-- 
<execution>
  <id>build-image</id>
  <phase>package</phase>
  <goals>
    <goal>build</goal>
  </goals>
</execution>
-->

Modify application-dev.ymlthe file , the content is as follows:

spring:
  datasource:
    url: jdbc:mysql://${
    
    MYSQL_HOST}:${
    
    MYSQL_PORT}/${
    
    MYSQL_DATABASE}?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false #MySQL连接地址
    username: ${
    
    MYSQL_USERNAME} #MySQL用户
    password: ${
    
    MYSQL_PWD} #MySQL密码
  ......
  redis:
    host: ${
    
    REDIS_HOST} #Redis连接地址
  ......

Modify application-dev.ymlthe file , the content is as follows:

spring:
  datasource:
    url: jdbc:mysql://${
    
    MYSQL_HOST}:${
    
    MYSQL_PORT}/${
    
    MYSQL_DATABASE}?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false #MySQL连接地址
    username: ${
    
    MYSQL_USERNAME} #MySQL用户
    password: ${
    
    MYSQL_PWD} #MySQL密码
  ......
  data:
    mongodb:
      host: ${
    
    MONGODB_HOST} #MySQL连接地址为环境变量
      port: 27017
      database: mall-port
  redis:
    host: ${
    
    REDIS_HOST} #Redis服务器地址
  ......
  rabbitmq:
    host: ${
    
    AMQP_HOST} #RabbitMQ 连接地址
    virtual-host: ${
    
    RABBITMQ_DEFAULT_VHOST} #RabbitMQ virtual host
    username: ${
    
    RABBITMQ_DEFAULT_USER} #RabbitMQ 用户
    password: ${
    
    RABBITMQ_DEFAULT_PASS} #RabbitMQ 密码
  ......

Modify application-dev.ymlthe file , the content is as follows:

spring:
  datasource:
    url: jdbc:mysql://${
    
    MYSQL_HOST}:${
    
    MYSQL_PORT}/${
    
    MYSQL_DATABASE}?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false #MySQL连接地址
    username: ${
    
    MYSQL_USERNAME} #MySQL用户
    password: ${
    
    MYSQL_PWD} #MySQL密码
  ......
  elasticsearch:
    uris: ${
    
    ES_HOST}:${
    
    ES_PORT} #ElasticSearch连接地址
  ......

Why do we have to change to environment variables, because it is more flexible, just modify the simple variable configuration to make the mall project run in any environment. In Rainbond, after the dependencies are established between components, the environment variables of the dependent components will be automatically injected, so we don't even need to configure the environment variables, which is more convenient. For the principle, please refer to the environment variable injection between Rainbond components .

Deploy backend components

In the team view or application view , add a component from source code:

  • Component name: custom
  • Component English name: Custom
  • Warehouse Address:https://github.com/zzzhangqi/mall.git
  • Code version: master

The above warehouse has modified the above code configuration

At this time, Rainbond will detect that the project is a multi-module project, and enter the multi-module project construction: check mall-admin、mall-portal、mall-searchand build.

Enter each component -> port, delete the default port 5000, and add a new component corresponding port:

  • mall-admin:8080
  • mall-portal:8085
  • mall-search:8081

Create dependencies between components

Inside the app, switch to edit mode, follow the dependencies and make the connections:

Add dependencies between components

Deploy the mall front-end service

In many cases, our back-end services generally do not provide external access. If the current configuration is adopted, the addresses of the middle and back-end must be the same as the access addresses of the front-end during deployment. config/prod.env.jsIf they are different, cross-domain will occur, as follows:

module.exports = {
    
    
  NODE_ENV: '"production"',
  BASE_API: '"https://admin-api.xxx.com"'
}

How to solve the problem of cross-domain without exposing the back-end service, you can use Nginx reverse proxy back-end service.

config/prod.env.jsDefine an interface that does not exist, such as/api

module.exports = {
    
    
  NODE_ENV: '"production"',
  BASE_API: '"/api"'
}

For example, the URL of the front-end access login interface is /api/admin/loginobviously /apinot our interface /admin/login, then /apirewrite to access the back-end interface /admin/login. At this time, if the interface is correct, the data can be returned normally, and it can also solve cross-connection. Domain issues and back-end services do not need to be exposed to the outside world.

server {
    listen 80;

    location / {
      root /app/www;
      index index.html index.htm;
    }

    location  /api {
        rewrite ^/api/(.*)$ /$1 break;
        proxy_pass http://127.0.0.1:8080;
    }
}

Deploy front-end components

In the team view or application view , add a component from source code:

  • Component name: custom
  • Component English name: Custom
  • Warehouse Address:https://github.com/zzzhangqi/mall-admin-web.git
  • Code version: master

The above warehouse has added the above configuration

Add mall-admin-webdepends onmall-admin

Verify deployment

Access mall-admin-webthe front-end project to verify the deployment, the default user password: admin / macro123. mall-portalAnd there is no front-end mall-searchfor the time being , you can visit the back-end swagger to verify the deploymenthttp://xxx/swagger-ui/

at last

The next issue will be the practice of deploying mall-swarm microservice projects on Rainbond.

Guess you like

Origin blog.csdn.net/Mrex326428/article/details/128661398