Mall-swarm (5.1K +star) address: github.com/macrozheng/…
Abstract
The mall Swarm project was upgraded to use Nacos for the registry and configuration center, but Jenkins’ automatic deployment documentation has not been updated. Some friends refer to the original document deployment a little problem, this time to the mall swarm automatic deployment document to make an upgrade, I hope to help you!
Basic use of Jenkins
To use this deployment solution, you need to know something about Jenkins. For basic information, see “Deploying SpringBoot Applications with Jenkins in one Click, That’s it 6!”.
preparedness
Before deployment, you need to install the dependent services required by mall-swarm and pack the Docker images of all applications. For details, please refer to “Mall-swarm deployment in Linux (Based on Docker container)”. The document address is www.macrozheng.com/#/deploy/ma… .
- You need to install the dependencies required by the project and use them directly
Docker Compose
Install it. The specific service and version information are as follows.
component | The version number |
---|---|
Mysql | 5.7 |
Redis | 5.0 |
MongoDb | 4.3.5 |
RabbitMq | 3.7.15 |
Nginx | 1.10 |
Elasticsearch | 7.6.2 |
Logstash | 7.6.2 |
Kibana | 7.6.2 |
Nacos | 1.3.0 |
- Package the Docker images of all SpringBoot applications. The specific application service information is as follows:
application | instructions |
---|---|
mall-monitor | The monitoring center |
mall-gateway | Microservice Gateway |
mall-auth | Certification center |
mall-admin | Mall Background Service |
mall-portal | Mall Front Desk Service |
mall-search | Mall Search service |
- Add all the application configurations to the Nacos registry as shown in the following configuration file.
Preparing for executing scripts
Jenkins automatic deployment relies on Linux to execute scripts, so we first prepare the scripts to execute.
- Script files are stored
mall-swarm
The project/document/sh
Directory:
- Change the newline format of all script files in IDEA to
LF
Otherwise, the script cannot be executed.
- Upload all script files to the specified directory, as we did here
/mydata/sh
Directory;
- Change all script files to executable files:
chmod +x ./mall-*
Copy the code
Create a task in Jenkins
Next we will automate deployment by creating tasks in Jenkins. Because our mall-Swarm is a multi-module project, the deployment above is different from the previous single-module project.
mall-admin
Since the creation of tasks performed by each module is pretty much the same, the creation of tasks for the mall-admin module will be explained in detail below, and the other modules will be covered briefly.
- First we choose
Build a free-style software project
And then enter the task name asmall-admin
Git repository address: Gitee Git repository address:
- And then we create a build, build
mall-swarm
Dependency modules in the project that would otherwise fail when building working service modules because they cannot be found;
Install ml-common, ml-mbg, ml-mbg
clean install -pl mall-common,mall-mbg -am
Copy the code
- Schematic diagram of dependency module construction:
- Create another build, build it separately and package it
mall-admin
Module:
- Create another build and execute it over SSH
sh
The script, which is executed heremall-admin
To run the script:
- Click Save to complete the creation of the mall-admin task.
mall-gateway
The creation of the mall gateway and other modules is basically the same as that of the mall admin. You only need to change the location of the POM. XML file and the location of the script when building the module.
- We can go straight from
mall-admin
Create a copy of the module’s task:
- Modify the second build
pom.xml
File location, changed to:${WORKSPACE}/mall-gateway/pom.xml
- Change the SSH execution script file location in the third build to:
/mydata/sh/mall-gateway.sh
- Click Save to complete the creation of the mall-gateway execution task.
Other modules
For details about how to create tasks for other modules, see creating mall-admin and mall-gateway.
Task creation complete
Docker network problem
If Docker Compose is used to start all dependent services, a network will be created by default. All dependent services will be in this network, and services in different networks cannot access each other. The network I created here is deploy_default, so you need to specify the network where the service in the SH script runs, otherwise the started application service will not be able to connect to the dependent service.
- You can use
docker inspect mysql
Command to check the network where the mysql server resides;
- Also through
docker network ls
To see all the networks;
[root@local-linux ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
59b309a5c12f bridge bridge local
3a6f76a8920d deploy_default bridge local
ef34fe69992b host host local
a65be030c632 none
Copy the code
- Modify all
sh
Script to modify the network on which the service runs, add a line--network deploy_default \
Can.
The module startup sequence is incorrect
Since Nacos, the registry and configuration center, is already started, there is almost no limit to the order in which the other modules start, but it is best to start in the following order.
Recommended boot sequence:
- mall-auth
- mall-gateway
- mall-monitor
- mall-admin
- mall-portal
- mall-search
Run to complete the effect display
- See the API documentation information, access to the address: http://192.168.3.101:8201/doc.html
- Check the registry service information, access to the address: http://192.168.3.101:8848/nacos/
- The monitoring center application information, access to the address: http://192.168.3.101:8101
- Log information collection system, access to the address: http://192.168.3.101:5601
conclusion
We completed the automatic deployment of the mall swarm project by creating tasks in Jenkins, so that when we modified the code every time, we could just click the start task to achieve one-click package deployment, saving the trouble of frequent package deployment.
The project address
Github.com/macrozheng/…