Jenkins+Docker+SpringCloud部署方案優(yōu)化
基于 Jenkins+Docker+SpringCloud微服務(wù)持續(xù)集成 作優(yōu)化
上面部署方案存在的問題:
- 一次只能選擇一個(gè)微服務(wù)部署
- 只有一臺(tái)生產(chǎn)者部署服務(wù)器
- 每個(gè)微服務(wù)只有一個(gè)實(shí)例,容錯(cuò)率低
Jenkins+Docker+SpringCloud集群部署流程說明
優(yōu)化方案:
- 在一個(gè)Jenkins工程中可以選擇多個(gè)微服務(wù)同時(shí)發(fā)布
- 在一個(gè)Jenkins工程中可以選擇多臺(tái)生產(chǎn)服務(wù)器同時(shí)部署
- 每個(gè)微服務(wù)都是以集群高可用形式部署
服務(wù)器列表
服務(wù)器名稱 | IP地址 | 安裝軟件 | 硬件配置 | 系統(tǒng) |
---|---|---|---|---|
代碼托管服務(wù)器 | 192.168.100.240 | Gitlab-12.9.9 | 2核4G | CentOS Linux release 7.5.1804 |
持續(xù)集成服務(wù)器 | 192.168.100.241 | Jenkins 2.401.2,JDK 11,JDK 1.8,Maven 3.8.8,Git 1.8.3.1,Docker 20.10.24-ce | 2核4G | CentOS Linux release 7.5.1804 |
代碼審查服務(wù)器 | 192.168.100.242 | mysql 5.7.43,sonarqube 6.7.7 | 1核2G | CentOS Linux release 7.5.1804 |
Harbor倉(cāng)庫服務(wù)器 | 192.168.100.251 | Docker 20.10.24-ce,Harbor 1.9.2 | 1核2G | CentOS Linux release 7.5.1804 |
生產(chǎn)部署服務(wù)器 | 192.168.100.252 | Docker 20.10.24-ce | 1核2G | CentOS Linux release 7.5.1804 |
生產(chǎn)部署服務(wù)器 | 192.168.100.253 | Docker 20.10.24-ce | 1核2G | CentOS Linux release 7.5.1804 |
修改所有微服務(wù)配置
eureka配置
讓eureka集群實(shí)現(xiàn)一個(gè)互相注冊(cè)的功能!
# 集群版
spring:
application:
name: EUREKA-HA
---
server:
port: 10086
spring:
# 指定profile=eureka-server1
profiles: eureka-server1
eureka:
instance:
# 指定當(dāng)profile=eureka-server1時(shí),主機(jī)名是eureka-server1
hostname: 192.168.100.252
client:
service-url:
# 將自己注冊(cè)到eureka-server1、eureka-server2這個(gè)Eureka上面去
defaultZone: http://192.168.100.252:10086/eureka,http://192.168.100.253:10086/eureka
---
server:
port: 10086
spring:
profiles: eureka-server2
eureka:
instance:
hostname: 192.168.100.253
client:
service-url:
defaultZone: http://192.168.100.252:10086/eureka,http://192.168.100.253:10086/eureka
在啟動(dòng)微服務(wù)的時(shí)候,加入?yún)?shù):spring.profiles.active
來讀取對(duì)應(yīng)的配置
其他微服務(wù)配置
除了Eureka注冊(cè)中心以外,其他微服務(wù)配置都需要加入所有Eureka服務(wù)
# Eureka配置
eureka:
client:
service-url:
defaultZone: http://192.168.100.252:10086/eureka,http://192.168.100.253:10086/eureka # Eureka訪問地址
instance:
prefer-ip-address: true
tensquare_zuul
配置tensquare_admin_service
配置tensquare_gathering
配置
把代碼提交到Gitlab中
設(shè)計(jì)Jenkins集群項(xiàng)目的構(gòu)建參數(shù)
因?yàn)橐M(jìn)行多項(xiàng)選擇,安裝Extended Choice Parameter
插件
創(chuàng)建流水線項(xiàng)目(集群版)
添加參數(shù)化構(gòu)建
選擇字符串參數(shù)
添加多選項(xiàng)目參數(shù)
使用jdk1.8
構(gòu)建項(xiàng)目
點(diǎn)擊構(gòu)建查看效果
編寫多選項(xiàng)遍歷腳本
多項(xiàng)目提交進(jìn)行代碼審查
// 定義變量以及引用變量,這樣維護(hù)性好一點(diǎn)
// 引用憑證ID最好使用雙引號(hào) ""
// git憑證ID
def git_auth = "a4d0066f-6c58-4ab0-b714-6a24b3f5bc90"
// git的URL地址
def git_url = "git@192.168.100.240:tensquare_group/tensquare_back.git"
// 鏡像的版本號(hào)
def tag = "latest"
// Harbor的url地址
def harbor_url = "192.168.100.251:85"
// 鏡像庫項(xiàng)目名稱
def harbor_project = "tensquare"
// Harbor的登錄憑證ID
def harbor_auth = "5785fbf3-a0f0-4234-8961-c866ca1e7046"
node {
// 獲取當(dāng)前選擇的項(xiàng)目名稱 ,調(diào)用split方法 以逗號(hào)切割項(xiàng)目名稱 返回的變量是一個(gè)數(shù)組
def selectedProjectNames = "${project_name}".split(",")
stage('拉取代碼') {
checkout scmGit(branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]])
}
stage('代碼審查') {
//
for(int i=0;i<selectedProjectNames.length;i++){
// 遍歷selectedProjectNames后取出每個(gè)元素里的內(nèi)容,就是project_name 項(xiàng)目信息
def projectInfo = selectedProjectNames[i];
// 取出項(xiàng)目名字 , 以@符號(hào)切割 [0] 為第一個(gè)參數(shù) tensquare_eureka
def currentProjectName = "${projectInfo}".split("@")[0]
// 當(dāng)前遍歷的項(xiàng)目端口,取出項(xiàng)目端口
def currentProjectPort = "${projectInfo}".split("@")[1]
// 定義當(dāng)前Jenkins的SonarQubeScanner工具的環(huán)境,位于全局工具配置的SonarQube Scanner 的name定義為'sonar-scanner'
def scannerHome = tool 'sonar-scanner'
// 引用當(dāng)前JenkinsSonarQube的環(huán)境,系統(tǒng)配置的SonarQube servers定義的name以及代碼審查服務(wù)器位置
withSonarQubeEnv('sonarqube') {
sh """
cd ${currentProjectName}
${scannerHome}/bin/sonar-scanner
"""
}
}
}
stage('編譯安裝公共子工程') {
sh "mvn -f tensquare_common clean install"
}
stage('編譯打包微服務(wù)工程,上傳鏡像') {
// 項(xiàng)目參數(shù)傳入的project_name 修改為變量
sh "mvn -f ${project_name} clean package dockerfile:build"
// 定義鏡像名稱
def imageName = "${project_name}:${tag}"
// 對(duì)鏡像打標(biāo)簽
sh "docker tag ${imageName} ${harbor_url}/${harbor_project}/${imageName}"
// 把鏡像推送到Harbor,項(xiàng)目為私有級(jí)別,登錄時(shí)涉及一個(gè)問題,登錄harbor需要輸入賬號(hào)和密碼,Jenkinsfile需要配置項(xiàng)目目錄下,會(huì)暴露給所有開發(fā)人員,為了安全使用憑證方式
withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
// 登錄到Harbor,引用如上定義的username和password,就是用戶haibo的信息
sh "docker login -u ${username} -p ${password} ${harbor_url}"
// 鏡像上傳
sh "docker push ${harbor_url}/${harbor_project}/${imageName}"
sh "echo 鏡像上傳成功"
}
// 部署應(yīng)用
sshPublisher(publishers: [sshPublisherDesc(configName: 'master_server', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/opt/jenkins_shell/deploy.sh $harbor_url $harbor_project $project_name $tag $port", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
嘗試多選項(xiàng)目進(jìn)行構(gòu)建
控制臺(tái)輸出能夠看到進(jìn)行了兩次代碼審查,證明Jenkinsfile能夠?qū)?xiàng)目進(jìn)行遍歷審查
但構(gòu)建結(jié)果是失敗的,在編譯打包的時(shí)候無法進(jìn)行遍歷與project_name
切割
多個(gè)項(xiàng)目打包及構(gòu)建上傳鏡像
修改Jenkinsfile
,注釋掉遠(yuǎn)程發(fā)布,查看編譯構(gòu)建和打包效果
// git憑證ID
def git_auth = "a4d0066f-6c58-4ab0-b714-6a24b3f5bc90"
// git的URL地址
def git_url = "git@192.168.100.240:tensquare_group/tensquare_back.git"
// 鏡像的版本號(hào)
def tag = "latest"
// Harbor的url地址
def harbor_url = "192.168.100.251:85"
// 鏡像庫項(xiàng)目名稱
def harbor_project = "tensquare"
// Harbor的登錄憑證ID
def harbor_auth = "5785fbf3-a0f0-4234-8961-c866ca1e7046"
node {
// 獲取當(dāng)前選擇的項(xiàng)目名稱 ,調(diào)用split方法 以逗號(hào)切割項(xiàng)目名稱 返回的變量是一個(gè)數(shù)組
def selectedProjectNames = "${project_name}".split(",")
stage('拉取代碼') {
checkout scmGit(branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]])
}
stage('代碼審查') {
//
for(int i=0;i<selectedProjectNames.length;i++){
// 遍歷selectedProjectNames后取出每個(gè)元素里的內(nèi)容,就是project_name 項(xiàng)目信息
def projectInfo = selectedProjectNames[i];
// 取出項(xiàng)目名字 , 以@符號(hào)切割 [0] 為第一個(gè)參數(shù) tensquare_eureka
def currentProjectName = "${projectInfo}".split("@")[0]
// 當(dāng)前遍歷的項(xiàng)目端口,取出項(xiàng)目端口
def currentProjectPort = "${projectInfo}".split("@")[1]
// 定義當(dāng)前Jenkins的SonarQubeScanner工具的環(huán)境,位于全局工具配置的SonarQube Scanner 的name定義為'sonar-scanner'
def scannerHome = tool 'sonar-scanner'
// 引用當(dāng)前JenkinsSonarQube的環(huán)境,系統(tǒng)配置的SonarQube servers定義的name以及代碼審查服務(wù)器位置
withSonarQubeEnv('sonarqube') {
sh """
cd ${currentProjectName}
${scannerHome}/bin/sonar-scanner
"""
}
}
}
stage('編譯安裝公共子工程') {
sh "mvn -f tensquare_common clean install"
}
stage('編譯打包微服務(wù)工程,上傳鏡像') {
for(int i=0;i<selectedProjectNames.length;i++){
// 遍歷selectedProjectNames后取出每個(gè)元素里的內(nèi)容,就是project_name 項(xiàng)目信息
def projectInfo = selectedProjectNames[i];
// 取出項(xiàng)目名字 , 以@符號(hào)切割 [0] 為第一個(gè)參數(shù) tensquare_eureka
def currentProjectName = "${projectInfo}".split("@")[0]
// 當(dāng)前遍歷的項(xiàng)目端口,取出項(xiàng)目端口
def currentProjectPort = "${projectInfo}".split("@")[1]
// 項(xiàng)目參數(shù)傳入的project_name 修改為變量
sh "mvn -f ${currentProjectName} clean package dockerfile:build"
// 定義鏡像名稱
def imageName = "${currentProjectName}:${tag}"
// 對(duì)鏡像打標(biāo)簽
sh "docker tag ${imageName} ${harbor_url}/${harbor_project}/${imageName}"
// 把鏡像推送到Harbor,項(xiàng)目為私有級(jí)別,登錄時(shí)涉及一個(gè)問題,登錄harbor需要輸入賬號(hào)和密碼,Jenkinsfile需要配置項(xiàng)目目錄下,會(huì)暴露給所有開發(fā)人員,為了安全使用憑證方式
withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
// 登錄到Harbor,引用如上定義的username和password,就是用戶haibo的信息
sh "docker login -u ${username} -p ${password} ${harbor_url}"
// 鏡像上傳
sh "docker push ${harbor_url}/${harbor_project}/${imageName}"
sh "echo 鏡像上傳成功"
}
// 部署應(yīng)用
//sshPublisher(publishers: [sshPublisherDesc(configName: 'master_server', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/opt/jenkins_shell/deploy.sh $harbor_url $harbor_project $project_name $tag $port", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
此時(shí)可以發(fā)現(xiàn)兩個(gè)服務(wù)都可以進(jìn)行代碼掃描以及進(jìn)行構(gòu)建打包和上傳至鏡像倉(cāng)庫!
把Eureka注冊(cè)中心集群部署到多臺(tái)服務(wù)器
配置第二臺(tái)生產(chǎn)服務(wù)器 192.168.100.253
# 卸載舊版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 刪除docker的所有鏡像和容器
rm -rf /var/lib/docker
# 安裝基本的依賴包
sudo yum install yum-utils device-mapper-persistent-data lvm2 -y
# 設(shè)置鏡像倉(cāng)庫 Docker yum源
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 更新yum軟件包索引
sudo yum makecache fast
# 列出需要安裝的版本列表
yum list docker-ce --showduplicates | sort -r
# 安裝docker-ce-20.10
yum install docker-ce-20.10.* docker-ce-cli-20.10.* containerd -y
# 配置Docker鏡像倉(cāng)庫加速以及配置Harbor鏡像倉(cāng)庫信任
mkdir /etc/docker -p
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://k68iw3ol.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.100.251:85"]
}
EOF
# 開啟內(nèi)核轉(zhuǎn)發(fā),后續(xù)報(bào)錯(cuò)排查后回來整理的筆記,重要!!!
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
# 重裝使配置生效
sysctl -p /etc/sysctl.conf
systemctl daemon-reload && systemctl enable --now docker
配置遠(yuǎn)程部署服務(wù)器
Jenkins服務(wù)器拷貝公鑰到遠(yuǎn)程生產(chǎn)服務(wù)器02
ssh-copy-id 192.168.100.253
系統(tǒng)配置->添加遠(yuǎn)程服務(wù)器
Publish over SSH–> 新增一臺(tái)機(jī)器
項(xiàng)目配置添加參數(shù)
配置能夠選擇多個(gè)服務(wù)器
返回項(xiàng)目構(gòu)建查看效果
更改Jenkinsfile
添加遍歷服務(wù)器啟動(dòng)容器配置
// git憑證ID
def git_auth = "a4d0066f-6c58-4ab0-b714-6a24b3f5bc90"
// git的URL地址
def git_url = "git@192.168.100.240:tensquare_group/tensquare_back.git"
// 鏡像的版本號(hào)
def tag = "latest"
// Harbor的url地址
def harbor_url = "192.168.100.251:85"
// 鏡像庫項(xiàng)目名稱
def harbor_project = "tensquare"
// Harbor的登錄憑證ID
def harbor_auth = "5785fbf3-a0f0-4234-8961-c866ca1e7046"
node {
// 獲取當(dāng)前選擇的項(xiàng)目名稱,調(diào)用split方法切割逗號(hào),意為切開項(xiàng)目名稱
def selectedProjectNames = "${project_name}".split(",")
// 獲取當(dāng)前選擇的服務(wù)器名稱
def selectedServers = "${publish_server}".split(",")
stage('拉取代碼') {
checkout scmGit(branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]])
}
stage('代碼審查') {
// 對(duì)項(xiàng)目遍歷進(jìn)行代碼審查,定義變量i=0 遍歷數(shù)組selectedProjectNames 數(shù)組長(zhǎng)度為length
for(int i=0;i<selectedProjectNames.length;i++){
// 取出每個(gè)元素里的內(nèi)容 定義變量為projectInfo 就是項(xiàng)目信息,即包含項(xiàng)目名字也包含項(xiàng)目端口
def projectInfo = selectedProjectNames[i];
// 對(duì) projectInfo 進(jìn)行切割 引用projectInfo 變量,使用@符號(hào)切,當(dāng)前遍歷的項(xiàng)目名字 [0] 為獲取的第一個(gè)元素 就是項(xiàng)目名字
def currentProjectName = "${projectInfo}".split("@")[0]
// 當(dāng)前遍歷的項(xiàng)目端口 [1] 就是獲取的第二個(gè)元素
def currentProjectPort = "${projectInfo}".split("@")[1]
// 定義當(dāng)前Jenkins的SonarQubeScanner工具的環(huán)境,位于全局工具配置的SonarQube Scanner 的name定義為'sonar-scanner'
def scannerHome = tool 'sonar-scanner'
// 引用當(dāng)前JenkinsSonarQube的環(huán)境,系統(tǒng)配置的SonarQube servers定義的name以及代碼審查服務(wù)器位置
withSonarQubeEnv('sonarqube') {
sh """
cd ${currentProjectName}
${scannerHome}/bin/sonar-scanner
"""
}
}
}
stage('編譯安裝公共子工程') {
sh "mvn -f tensquare_common clean install"
}
stage('編譯打包微服務(wù)工程,上傳鏡像') {
for(int i=0;i<selectedProjectNames.length;i++){
// 取出每個(gè)元素里的內(nèi)容 定義變量為projectInfo 就是項(xiàng)目信息,即包含項(xiàng)目名字也包含項(xiàng)目端口
def projectInfo = selectedProjectNames[i];
// 對(duì) projectInfo 進(jìn)行切割 引用projectInfo 變量,使用@符號(hào)切,當(dāng)前遍歷的項(xiàng)目名字 [0] 為獲取的第一個(gè)元素 就是項(xiàng)目名字
def currentProjectName = "${projectInfo}".split("@")[0]
// 當(dāng)前遍歷的項(xiàng)目端口 [1] 就是獲取的第二個(gè)元素
def currentProjectPort = "${projectInfo}".split("@")[1]
// 項(xiàng)目參數(shù)傳入的project_name 修改為變量
sh "mvn -f ${currentProjectName} clean package dockerfile:build"
// 定義鏡像名稱
def imageName = "${currentProjectName}:${tag}"
// 對(duì)鏡像打標(biāo)簽
sh "docker tag ${imageName} ${harbor_url}/${harbor_project}/${imageName}"
// 把鏡像推送到Harbor,項(xiàng)目為私有級(jí)別,登錄時(shí)涉及一個(gè)問題,登錄harbor需要輸入賬號(hào)和密碼,Jenkinsfile需要配置項(xiàng)目目錄下,會(huì)暴露給所有開發(fā)人員,為了安全使用憑證方式
withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
// 登錄到Harbor,引用如上定義的username和password,就是用戶haibo的信息
sh "docker login -u ${username} -p ${password} ${harbor_url}"
// 鏡像上傳
sh "docker push ${harbor_url}/${harbor_project}/${imageName}"
sh "echo 鏡像上傳成功"
}
// 遍歷所有的服務(wù)器,分別部署
for(int j=0;j<selectedServers.length;j++){
// 獲取當(dāng)前遍歷的服務(wù)器名稱
def currentServerName = selectedServers[j]
// 加上的參數(shù)格式:--spring.profiles.active=eureka-server1/eureka-server2
def activeProfile = "--spring.profiles.active="
// 根據(jù)不同的服務(wù)器名字來讀取不同的eureka配置信息
if(currentServerName=="master_server"){
activeProfile = activeProfile+"eureka-server1"
}else if (currentServerName=="slave_server"){
activeProfile = activeProfile+"eureka-server2"
}
// 部署應(yīng)用
sshPublisher(publishers: [sshPublisherDesc(configName: "${currentServerName}", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/opt/jenkins_shell/deployCluster.sh $harbor_url $harbor_project $currentProjectName $tag $currentProjectPort $activeProfile", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
echo "${currentProjectName}完成編譯,構(gòu)建鏡像"
}
}
}
更改服務(wù)器端部署腳本
在deploy.sh
的基礎(chǔ)上再編寫一個(gè)deployCluster.sh
腳本
增加一個(gè)變量profile,用來存儲(chǔ)新增的位置變量activeProfile,也是傳參的$6
vim /opt/jenkins_shell/deployCluster.sh
#!/bin/sh
# 接收外部參數(shù)
harbor_url=$1
harbor_project_name=$2
project_name=$3
tag=$4
port=$5
Profile=$6
imageName=$harbor_url/$harbor_project_name/$project_name:$tag
echo "$imageName"
# 查詢?nèi)萜魇欠翊嬖?,存在則刪除
containerId=`docker ps -a | grep -w ${project_name}:${tag} | awk '{print $1}'`
if [ "$containerId" != "" ] ; then
# 停掉容器
docker stop $containerId
# 刪除容器
docker rm $containerId
echo "成功刪除容器"
fi
# 查詢鏡像是否存在,存在則刪除
imageId=`docker images | grep -w $project_name | awk '{print $3}'`
if [ "$imageId" != "" ] ; then
# 刪除鏡像
docker rmi -f $imageId
echo "成功刪除鏡像"
fi
# 登錄Harbor
docker login -u haibo -p LIUhaibo123 $harbor_url
# 下載鏡像
docker pull $imageName
# 啟動(dòng)容器
docker run -di -p $port:$port $imageName $profile
echo "容器啟動(dòng)成功"
# 添加執(zhí)行權(quán)限
chmod +x /opt/jenkins_shell/deployCluster.sh
嘗試構(gòu)建項(xiàng)目,部署eureka服務(wù)器至兩臺(tái)服務(wù)器上
eureka集群?jiǎn)?dòng)并且使用10086端口
部署剩下的微服務(wù)集群
四個(gè)微服務(wù)都部署完成后通過瀏覽器查看,并且所有微服務(wù)都已經(jīng)成功注冊(cè)到eureka服務(wù)器也已經(jīng)形成集群形式
報(bào)錯(cuò)問題排查
第一個(gè)報(bào)錯(cuò):eureka服務(wù)器容器啟動(dòng)后端口為8080
容器啟動(dòng)后查看容器日志,發(fā)現(xiàn)eureka服務(wù)器監(jiān)聽端口為8080,心想我的配置文件設(shè)置為10086端口為什么啟動(dòng)后是監(jiān)聽8080端口?
重構(gòu)Jenkinsfile文件的docker容器啟動(dòng)傳參部分
// 加上的參數(shù)格式:--spring.profiles.active=eureka-server1/eureka-server2
def activeProfile = "--spring.profiles.active=" //添加等號(hào) =
// 根據(jù)不同的服務(wù)器名字來讀取不同的eureka配置信息
if(currentServerName=="master_server"){
activeProfile = activeProfile+"eureka-server1"
}else if (currentServerName=="slave_server"){
activeProfile = activeProfile+"eureka-server2"
}
于是手動(dòng)啟動(dòng)容器傳參后報(bào)錯(cuò)
docker run -di -p 10086:10086 2c37266049d5 --spring.profiles.activeeureka-server2
WARNING: IPv4 forwarding is disabled. Networking will not work.
# 警告:IPv4轉(zhuǎn)發(fā)已禁用。網(wǎng)絡(luò)將不起作用。
添加docker ipv4轉(zhuǎn)發(fā)
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
# 重裝使配置生效
sysctl -p /etc/sysctl.conf
# 重啟docker
systemctl restart docker
啟動(dòng)后還是監(jiān)聽8080端口,嘗試使用--spring.profiles.active=eureka-server2
進(jìn)行傳參后啟動(dòng)成功
docker run -di -p 10086:10086 2c37266049d5 --spring.profiles.active=eureka-server2
第二個(gè)報(bào)錯(cuò):【已解決】com.mysql.jdbc.exceptions.jdbc4.CommunicationsExcepti:Communications link failure ----mysql連接報(bào)錯(cuò)
Nginx+Zuul集群實(shí)現(xiàn)高可用網(wǎng)關(guān)
配置nginx
配置負(fù)載均衡池,里面地址就是zuul網(wǎng)關(guān)地址proxy_pass
選擇不同的zuulServer
# 位于pro02生產(chǎn)服務(wù)器進(jìn)行配置
# 安裝Nginx
# 修改Nginx配置
vim /etc/nginx/nginx.conf
# http模塊添加
upstream zuulServer {
server 192.168.100.252:10020 weight=1;
server 192.168.100.253:10020 weight=1;
}
vim /etc/nginx/conf.d/default.conf
server {
listen 85;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html;
location / {
# root /usr/share/nginx/html;
# index index.html index.htm;
# 指定服務(wù)器負(fù)載均衡服務(wù)器
proxy_pass http://zuulServer/;
}
# 重啟Nginx
systemctl restart nginx
修改前端代碼對(duì)于Nginx的訪問地址
更改完成后代碼上傳至Gitlab代碼倉(cāng)庫
構(gòu)建前端web項(xiàng)目流水線并訪問文章來源:http://www.zghlxwxcb.cn/news/detail-639347.html
瀏覽器訪問
同時(shí)也可以新增數(shù)據(jù),前后端能互相調(diào)用組件工作,實(shí)驗(yàn)完成!文章來源地址http://www.zghlxwxcb.cn/news/detail-639347.html
到了這里,關(guān)于Jenkins+Docker+SpringCloud微服務(wù)持續(xù)集成項(xiàng)目?jī)?yōu)化和微服務(wù)集群的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!