目录
一、Jenkins + Docker + SpringCloud 部署方案优化
优化方案:
- 在一个 Jenkins 工程中可以选择多个微服务同时发布
- 在一个 Jenkins 工程中可以选择多台生产服务器同时部署
- 每个微服务都是以集群高可用形式部署
二、Jenkins + Docker + SpringCloud 集群部署流程说明
服务器名称 | IP 地址 | 安装的软件 |
---|---|---|
代码托管服务器 | 192.168.10.20 | Gitlab |
持续集成服务器 | 192.168.10.30 | Jenkins,Maven,Git,JDK,Sonarqube,Docker20.10.12-ce |
Docker 仓库服务器 | 192.168.10.40 | JDK,Tomcat,Docker20.10.12-ce,Harbor1.9.2 |
生产部署服务器一 | 192.168.10.50 | Docker20.10.12-ce |
生产部署服务器二 | 192.168.10.115 | Docker20.10.12-ce |
三、新增一台 Docker 服务器
参考:
安装 Docker
指向 harbor 地址
[root@c7-5 ~]#vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://4iv7219l.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.10.40:85"]
}
[root@c7-5 ~]#systemctl restart docker
四、修改所有微服务配置
修改各个模块的 application.yml 的 eureka 生产服务器地址为集群模式,我们新增了一个地址。
1. eureka
# 集群版
spring:
application:
name: EUREKA-HA
---
server:
port: 10086
spring:
# 指定profile=eureka-server1
profiles: eureka-server1
eureka:
instance:
# 指定当profile=eureka-server1时,主机名是eureka-server1
hostname: 192.168.10.50
client:
service-url:
# 将自己注册到eureka-server1、eureka-server2这个Eureka上面去
defaultZone: http://192.168.10.50:10086/eureka/,http://192.168.10.115:10086/eureka/
---
server:
port: 10086
spring:
profiles: eureka-server2
eureka:
instance:
hostname: 192.168.10.115
client:
service-url:
defaultZone: http://192.168.10.50:10086/eureka/,http://192.168.10.115:10086/eureka/
2. zuul
server:
port: 10020 # 端口
# 基本服务信息
spring:
application:
name: tensquare-zuul # 服务ID
# Eureka配置
eureka:
client:
service-url:
defaultZone: http://192.168.10.50:10086/eureka,http://192.168.10.115:10086/eureka # Eureka访问地址
instance:
prefer-ip-address: true
# 修改ribbon的超时时间
ribbon:
ConnectTimeout: 1500 # 连接超时时间,默认500ms
ReadTimeout: 3000 # 请求超时时间,默认1000ms
# 修改hystrix的熔断超时时间
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMillisecond: 2000 # 熔断超时时长,默认1000ms
# 网关路由配置
zuul:
routes:
admin:
path: /admin/**
serviceId: tensquare-admin-service
gathering:
path: /gathering/**
serviceId: tensquare-gathering
# jwt参数
jwt:
config:
key: itcast
ttl: 1800000
3. admin
server:
port: 9001
spring:
application:
name: tensquare-admin-service #指定服务名
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.10.30:3306/tensquare_user?characterEncoding=UTF8
username: root
password: 123456
jpa:
database: mysql
show-sql: true
#Eureka配置
eureka:
client:
service-url:
defaultZone: http://192.168.10.50:10086/eureka,http://192.168.10.115:10086/eureka
instance:
lease-renewal-interval-in-seconds: 5 # 每隔5秒发送一次心跳
lease-expiration-duration-in-seconds: 10 # 10秒不发送就过期
prefer-ip-address: true
# jwt参数
jwt:
config:
key: itcast
ttl: 1800000
4. gathering
server:
port: 9002
spring:
application:
name: tensquare-gathering #指定服务名
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.10.30:3306/tensquare_gathering?characterEncoding=UTF8
username: root
password: 123456
jpa:
database: mysql
show-sql: true
#Eureka客户端配置
eureka:
client:
service-url:
defaultZone: http://192.168.10.50:10086/eureka,http://192.168.10.115:10086/eureka
instance:
lease-renewal-interval-in-seconds: 5 # 每隔5秒发送一次心跳
lease-expiration-duration-in-seconds: 10 # 10秒不发送就过期
prefer-ip-address: true