Link: https://pan.baidu.com/s/1HR3Q-cojnCidRy1xrdlOxg
Extraction code: 7m56
--Sharing from Baidu online disk super member V3
Deploy other microservices
The registry eureka service configuration specifies the production server address
The service gateway configuration specifies the production server address
For the configuration of the certification center, the database uses the database in Jenkins
Active microservice configuration
Submit after modification
Import database script into MySQL in Jenkins server
Click to view the codemysql> create database tensquare_user; mysql> use tensquare_user; mysql> source /opt/tensquare_user.sql; mysql> create database tensquare_gathering; mysql> use tensquare_gathering; mysql> source /opt/tensquare_gathering.sql; ------------------------Authorize remote login------------------------------------- grant all privileges on *.* to 'root'@'%' identified by 'abc123' with grant option; mysql> flush privileges;
After preparation, all microservices can be deployed directly
List of containers in production server
Test the background data connection with postman
Continuous integration of microservices (7) - deploy front-end static web sites
Install Nginx server
yum install epel-release
yum -y install nginx
Modify the port of nginx. The default value is 80. Change it to 9090:
vi /etc/nginx/nginx.conf
Close selinux, SELINUX=disabled
Setenforce0 is temporarily closed first
vi /etc/selinux/con "g edit the file and close it permanently
SELINUX=disabled
Start Nginx
systemctl enable nginx set startup
systemctl start nginx start
systemctl stop nginx stop
systemctl restart nginx restart
Install NodeJS plug-in
Jenkins configuring the Nginx server
Manage Jenkins->Global Tool Configuration
Create front-end pipeline project
//Certificate of harbor def git_auth="1be38991-873b-4a68-8eb6-312347fdc0a4" node { stage('pull code') { //Switch to variable and use double quotation marks for string symbols checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: 'git@192.168.195.180:kgc_group/tensquare_front.git']]]) } stage('make package,deploy') { //npm packaging using nodejs nodejs('nodejs12'){ sh ''' npm install npm run build ''' } //Remote deployment sshPublisher(publishers: [sshPublisherDesc(configName: 'master_server', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/usr/share/nginx/html', remoteDirectorySDF: false, removePrefix: 'dist', sourceFiles: 'dist/**')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)]) } }
Start building
Production server validation view / usr/share/nginx/html root directory
Jenkins + docker + spring cloud deployment scheme optimization
Problems in the above deployment scheme:
1) Only one microservice deployment can be selected at a time
2) Only one producer deployment server
3) There is only one instance of each microservice, and the fault tolerance rate is low
Optimization scheme:
1) In a Jenkins project, you can select multiple microservices to publish at the same time
2) In a Jenkins project, multiple production servers can be selected and deployed at the same time
3) Each microservice is deployed in the form of cluster high availability
Jenkins+Docker+SpringCloud cluster deployment process description
Modify all micro service configurations
Registry configuration (*)
Start a docker2 server (install and deploy docker environment)
Click to view the code# Cluster version spring: application: name: EUREKA-HA --- server: port: 10086 spring: # Specify profile = Eureka Server1 profiles: eureka-server1 eureka: instance: # Specifies that when profile = Eureka Server1, the host name is Eureka Server1 hostname: 192.168.195.184 client: service-url: # Register yourself on eureka-server1 and eureka-server2 defaultZone: http://192.168.195.184:10086/eureka/,http://192.168.195.182:10086/eureka/ --- server: port: 10086 spring: profiles: eureka-server2 eureka: instance: hostname: 192.168.195.182 client: service-url: defaultZone: http://192.168.195.184:10086/eureka/,http://192.168.195.182:10086/eureka/
When starting the micro service, add the parameter: spring profiles.active to read the corresponding configuration
Other micro service configurations
In addition to Eureka registry, all Eureka services need to be added to other micro service configurations
# Eureka configuration eureka: client: service-url: defaultZone: http://192.168.195.182:10086/eureka, http://192.168.195.184:10086/eureka #Eureka access address instance: prefer-ip-address: true
Submit the code to Gitlab
Design the construction parameters of Jenkins cluster project
1) Installing the Extended Choice Parameter plug-in supports multiple selection boxes
2) Create pipeline project
3) Add parameter
String parameter: branch name
Multi box: item name
Final effect (please use English comma):
Circular packaging compilation and image making
Click to view the code//git's credentials def git_auth="1be38991-873b-4a68-8eb6-312347fdc0a4" //URL of git def git_url="git@192.168.195.180:kgc_group/tensquare_back.git" //Mirror label def tag="latest" //url address of harbor def harbor_url="192.168.195.183:85" //Image warehouse name def harbor_name="tensquare" //Certificate of harbor def harbor_auth="e8b4bf42-2a87-4611-90f7-4b4a75479b5c" node { //Gets the name of the currently selected item def selectedProjectNames="${project_name}".split(",") stage('pull code') { //Switch to variable and use double quotation marks for string symbols checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]]) } stage('check code') { for(int i=0;i<selectedProjectNames.length;i++){ //Project information tensquare_eureka_server@10086 def projectInfo=selectedProjectNames[i] //Current project name def currentProjectName="${projectInfo}".split("@")[0] //Current project port def currentProjectPort="${projectInfo}".split("@")[1] //Define the SonarQubeScanner tool def scannerHome = tool 'sonar-scanner' //Reference SonarQube system environment withSonarQubeEnv('sonarqube') { sh """ cd ${currentProjectName} ${scannerHome}/bin/sonar-scanner """ } } } //Add public subproject stage('make install public sub project') { sh "mvn -f tensquare_common clean install" } //Package micro services, create images and upload images stage('make package images,push images') { for(int i=0;i<selectedProjectNames.length;i++){ //Project information tensquare_eureka_server@10086 def projectInfo=selectedProjectNames[i] //Current project name def currentProjectName="${projectInfo}".split("@")[0] //Current project port def currentProjectPort="${projectInfo}".split("@")[1] sh "mvn -f ${currentProjectName} clean package dockerfile:build" //Define image name def imageName="${currentProjectName}:${tag}" //Label images sh "docker tag ${imageName} ${harbor_url}/${harbor_name}/${imageName}" //Push image to harbor withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) { //Log in to harbor sh "docker login -u ${username} -p ${password} ${harbor_url}" //Image upload sh "docker push ${harbor_url}/${harbor_name}/${imageName}" sh "echo Image upload succeeded" } } //Deploy application sshPublisher(publishers: [sshPublisherDesc(configName: 'master_server', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/opt/jenkins_shell/deploy.sh ${harbor_url} ${harbor_name} ${project_name} ${tag} ${port}", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)]) } }