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 上部署 mall
but 使用 Docker 或 DockerCompose 部署 mall
for 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:
- Quickly deploy malls through the Rainbond open source application store
- 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 mall
and 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-web
front-end project to verify the deployment, the default user password:admin / macro123
mall-portal
And there is no front-end mall-search
for 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
- Open the external port service in Mysql component -> port , connect through IP:PORT, default user password
root / root
- 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.enabled
set tofalse
and update the component to take effect.
Install the Chinese word breaker IK Analyzer
- First search for and install the plugin in Team
ES-IK-Analysis
View -> Plugins -> Add Plugins -> Install Plugins via App Store - Add storage for ElasticSearch components, component -> storage -> add storage
- name: custom
- Mount path:
/usr/share/elasticsearch/plugins
- Type: shared storage
- Go to Components -> Plugins -> Unactivated , activate
ES-IK-Analysis
the plugin - Update or restart ElasticSearch components to take effect.
Deploy mall backend service
Modify project code configuration
pom.xml
Comment execution
the 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.xml
The configuration is as follows:
<!--
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
-->
Modify application-dev.yml
the 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.yml
the 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.yml
the 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-search
and 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.js
If 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.js
Define 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/login
obviously /api
not our interface /admin/login
, then /api
rewrite 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-web
depends onmall-admin
Verify deployment
Access mall-admin-web
the front-end project to verify the deployment, the default user password: admin / macro123. mall-portal
And there is no front-end mall-search
for 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.