├── .gitignore ├── README.md ├── auth-service ├── Dockerfile ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── zhangxd │ │ └── auth │ │ ├── AuthApplication.java │ │ ├── config │ │ ├── OAuthConfiguration.java │ │ └── ResourceServerConfiguration.java │ │ └── controller │ │ └── UserController.java │ └── resources │ ├── bootstrap.yml │ ├── logback-spring.xml │ └── schema.sql ├── bill-biz-task ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── cn │ │ │ └── zhangxd │ │ │ └── billbiztask │ │ │ ├── BillBizTaskApplication.java │ │ │ └── runner │ │ │ └── MyBillBizTaskRunner.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── cn │ └── zhangxd │ └── billbiztask │ ├── HttpClientUtil.java │ └── HttpTest.java ├── cluster-role-binding.yml ├── config-repo ├── application-dev.yml ├── application-prod.yml ├── application.yml ├── auth-service.yml ├── gateway.yml ├── svca-service-dev.yml ├── svca-service-prod.yml ├── svca-service.yml ├── svcb-service-dev.yml ├── svcb-service-prod.yml ├── svcb-service.yml └── user-biz-task-dev.yml ├── config ├── Dockerfile ├── config.yaml ├── pom.xml └── src │ └── main │ ├── fabric8 │ └── service.yml │ ├── java │ └── cn │ │ └── zhangxd │ │ └── config │ │ └── ConfigApplication.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── devops └── jenkins │ └── jenkinsfile ├── docker-compose.yml ├── gateway ├── Dockerfile ├── gateway.yaml ├── pom.xml └── src │ └── main │ ├── fabric8 │ └── service.yml │ ├── java │ └── cn │ │ └── zhangxd │ │ └── gateway │ │ ├── GatewayApplication.java │ │ └── config │ │ └── SpringDocConfig.java │ └── resources │ ├── application.yml │ ├── bootstrap.yml │ └── logback-spring.xml ├── helms ├── common-modle-springbootcloud │ ├── .helmignore │ ├── Chart.yaml │ ├── templates │ │ ├── NOTES.txt │ │ ├── _helpers.tpl │ │ ├── deployment.yaml │ │ ├── hpa.yaml │ │ ├── ingress.yaml │ │ ├── service.yaml │ │ ├── serviceaccount.yaml │ │ └── tests │ │ │ └── test-connection.yaml │ └── values.yaml ├── helm-install.sh └── values │ ├── auth-service │ └── values.yaml │ ├── config │ └── values.yaml │ ├── gateway │ └── values.yaml │ ├── monitor │ └── values.yaml │ ├── registry │ └── values.yaml │ ├── svca-service │ └── values.yaml │ ├── svcb-service │ └── values.yaml │ ├── values.yaml │ └── zipkin │ └── values.yaml ├── istio.yaml ├── k8s.yaml ├── monitor ├── Dockerfile ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── zhangxd │ │ └── monitor │ │ └── MonitorApplication.java │ └── resources │ ├── application.yml │ ├── bootstrap.yml │ └── logback-spring.xml ├── pom.xml ├── rabbitmq.yaml ├── registry ├── Dockerfile ├── pom.xml └── src │ ├── main │ ├── java │ │ └── cn │ │ │ └── zhangxd │ │ │ └── registry │ │ │ └── RegistryApplication.java │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml │ └── test │ └── java │ └── cn │ └── zhangxd │ └── registry │ └── ApplicationTests.java ├── screenshots ├── architecture.jpg ├── components.jpg ├── monitor1.jpg ├── monitor10.jpg ├── monitor11.jpg ├── monitor12.jpg ├── monitor2.jpg ├── monitor3.jpg ├── monitor4.jpg ├── monitor5.jpg ├── monitor6.jpg ├── monitor7.jpg ├── monitor8.jpg ├── monitor9.jpg ├── rabbit.jpg ├── registry.jpg ├── springCloud-skywalking1.png ├── springCloud-skywalking2.png ├── zipkin1.jpg ├── zipkin2.jpg └── zipkin3.jpg ├── skywalking-oap-server-with-h2.yaml ├── skywalking-ui.yaml ├── svca-service ├── Dockerfile ├── pom.xml ├── src │ └── main │ │ ├── fabric8 │ │ └── service.yml │ │ ├── java │ │ └── cn │ │ │ └── zhangxd │ │ │ └── svca │ │ │ ├── ServiceAApplication.java │ │ │ ├── client │ │ │ └── ServiceBClient.java │ │ │ ├── config │ │ │ ├── CustomLoadBalancerConfiguration.java │ │ │ └── SpringDocConfig.java │ │ │ ├── controller │ │ │ └── ServiceAController.java │ │ │ └── event │ │ │ └── LeaderElectionEventListener.java │ │ └── resources │ │ ├── bootstrap.yml │ │ └── logback-spring.xml ├── svca-k8s.yaml ├── test.http └── windows_set_env.cmd ├── svcb-service ├── Dockerfile ├── pom.xml ├── src │ └── main │ │ ├── fabric8 │ │ └── service.yml │ │ ├── java │ │ └── cn │ │ │ └── zhangxd │ │ │ └── svcb │ │ │ ├── ServiceBApplication.java │ │ │ ├── config │ │ │ └── SpringDocConfig.java │ │ │ └── controller │ │ │ └── ServiceBController.java │ │ └── resources │ │ ├── application.yml │ │ ├── bootstrap.yml │ │ └── logback-spring.xml └── svcb-k8s.yaml ├── user-biz-task ├── .gitignore ├── install-mysql-k8s.yaml ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── zhangxd │ │ └── userbiztask │ │ ├── UserBizTaskApplication.java │ │ └── runner │ │ └── MyUserBizTaskRunner.java │ └── resources │ ├── application.yml │ ├── bootstrap.yml │ └── logback-spring.xml └── zipkin ├── Dockerfile ├── pom.xml └── src └── main ├── java └── cn │ └── zhangxd │ └── zipkin │ └── ZipkinApplication.java └── resources └── application.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea/ 3 | *.iml 4 | target/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 基于 Spring Cloud 的微服务架构 2 | 3 | > kubectl create clusterrolebinding permissive-binding --clusterrole=cluster-admin --user=admin --user=kubelet --group=system:serviceaccounts 4 | 5 | 6 | 本项目Fork自https://github.com/zhangxd1989/spring-boot-cloud,关于原项目的介绍可查看 7 | 8 | https://gitee.com/zhangxd/spring-boot-cloud 9 | 10 | 或 https://github.com/zhangxd1989/spring-boot-cloud 11 | 12 | 本项目仅对原项目中的打包与部署方面进行了修改,其他地方未进行变动 13 | 14 | # 技术栈 15 | * Spring boot - 微服务的入门级微框架,用来简化 Spring 应用的初始搭建以及开发过程。 16 | * Eureka - 云端服务发现,一个基于 REST 的服务,用于定位服务,以实现云端中间层服务发现和故障转移。 17 | * Spring Cloud Config - 配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储、Git 以及 Subversion。 18 | * Hystrix - 熔断器,容错管理工具,旨在通过熔断机制控制服务和第三方库的节点,从而对延迟和故障提供更强大的容错能力。 19 | * Zuul - Zuul 是在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架。Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门。 20 | * Spring Cloud Bus - 事件、消息总线,用于在集群(例如,配置变化事件)中传播状态变化,可与 Spring Cloud Config 联合实现热部署。 21 | * Spring Cloud Sleuth - 日志收集工具包,封装了 Dapper 和 log-based 追踪以及 Zipkin 和 HTrace 操作,为 SpringCloud 应用实现了一种分布式追踪解决方案。 22 | * Ribbon - 提供云端负载均衡,有多种负载均衡策略可供选择,可配合服务发现和断路器使用。 23 | * Turbine - Turbine 是聚合服务器发送事件流数据的一个工具,用来监控集群下 hystrix 的 metrics 情况。 24 | * Spring Cloud Stream - Spring 数据流操作开发包,封装了与 Redis、Rabbit、Kafka 等发送接收消息。 25 | * Feign - Feign 是一种声明式、模板化的 HTTP 客户端。 26 | * Spring Cloud OAuth2 - 基于 Spring Security 和 OAuth2 的安全工具包,为你的应用程序添加安全控制。 27 | 28 | 此项目新增 29 | * io.fabric8.docker-maven-plugin - dokcer打包插件。 30 | * skywalking - 无侵入的服务监控。 31 | 32 | # 应用架构 33 | 34 | 该项目包含 8 个服务 35 | 36 | * registry - 服务注册与发现 37 | * config - 外部配置 38 | * monitor - 监控 39 | * zipkin - 分布式跟踪 40 | * gateway - 代理所有微服务的接口网关 41 | * auth-service - OAuth2 认证服务 42 | * svca-service - 业务服务A 43 | * svcb-service - 业务服务B 44 | 45 | 46 | # rancher+kubernetes+skywalking部署流程 47 | ## linux环境准备 48 | 3台linux,笔者这里选择的是通过虚拟机安装的centos7 minimal 49 | 50 | | ip | serverName | 51 | | ---- | ---- | 52 | | 192.168.113.143 | rancher-server | 53 | | 192.168.113.144 | k8s-node1 | 54 | | 192.168.113.145 | k8s-node2 | 55 | 56 | 57 | ### centos7 minimal安装ifconfig 58 | > ip addr 找到网卡 59 | 60 | > vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 61 | 62 | ONBOOT修改为yes 63 | 64 | > service network restart 65 | 66 | > yum provides ifconfig 67 | 68 | > yum install net-tools 69 | 70 | ### 关闭防火墙 71 | > systemctl stop firewalld 72 | 73 | > systemctl disable firewalld 74 | 75 | ### 关闭selinux 76 | > sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 //令配置立即生效 77 | 78 | ### 开启ipvs 79 | 使用ipvs替换iptables,kubeproxy中设置 80 | 81 | 要启用ipvs,必须启用转发功能 82 | ```bash 83 | cat >> /etc/sysctl.conf << EOF 84 | net.ipv4.ip_forward = 1 85 | net.bridge.bridge-nf-call-iptables = 1 86 | net.bridge.bridge-nf-call-ip6tables = 1 87 | EOF 88 | 89 | sysctl -p 90 | ``` 91 | 永久支持ipvs 92 | 93 | ``` 94 | yum -y install ipvsadm ipset 95 | 96 | # 临时生效 97 | modprobe -- ip_vs 98 | modprobe -- ip_vs_rr 99 | modprobe -- ip_vs_wrr 100 | modprobe -- ip_vs_sh 101 | modprobe -- nf_conntrack_ipv4 102 | 103 | # 永久生效 104 | cat > /etc/sysconfig/modules/ipvs.modules < /etc/sysconfig/modules/ipvs.modules < /dev/null 2>&1 120 | if [ $? -eq 0 ]; then 121 | /sbin/modprobe \${kernel_module} 122 | fi 123 | done 124 | EOF 125 | chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep ip_vs 126 | 127 | ``` 128 | 129 | ### 修改每个服务器中的host 130 | ```bash 131 | 192.168.113.143 rancher-server 132 | 192.168.113.144 k8s-node1 133 | 192.168.113.145 k8s-node2 134 | ``` 135 | ### 修改hostname 136 | > hostnamectl set-hostname rancher-server 137 | 138 | 查看hostname 139 | 140 | > hostname 141 | 142 | ## docker安装 143 | 144 | ```bash 145 | yum install -y yum-utils device-mapper-persistent-data lvm2 146 | yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 147 | yum list docker-ce --showduplicates | sort -r 148 | yum install docker-ce-18.06.3.ce 149 | systemctl start docker 150 | ``` 151 | 152 | 配置好加速器 153 | ``` 154 | sudo mkdir -p /etc/docker 155 | sudo tee /etc/docker/daemon.json <<-'EOF' 156 | { 157 | "registry-mirrors": ["https://yourname.mirror.aliyuncs.com"] 158 | } 159 | EOF 160 | sudo systemctl daemon-reload 161 | sudo systemctl restart docker 162 | ``` 163 | 164 | ## 安装rancher 165 | 166 | ``` 167 | docker pull rancher/rancher 168 | mkdir -p /docker_volume/rancher_home/rancher 169 | mkdir -p /docker_volume/rancher_home/auditlog 170 | ``` 171 | 172 | 启动 173 | ``` 174 | docker run -d --restart=unless-stopped -p 80:80 -p 443:443 \ 175 | -v /docker_volume/rancher_home/rancher:/var/lib/rancher \ 176 | -v /docker_volume/rancher_home/auditlog:/var/log/auditlog \ 177 | --name rancher rancher/rancher 178 | ``` 179 | 180 | 待启动完毕后自行搭建好k8s集群,并将kubeproxy设为ipvs工作方式 181 | 182 | ## 节点安装kubectl 183 | 184 | 安装kubectl 185 | ``` 186 | cat < /etc/yum.repos.d/kubernetes.repo 187 | [kubernetes] 188 | name=Kubernetes 189 | baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ 190 | enabled=1 191 | gpgcheck=1 192 | repo_gpgcheck=1 193 | gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg 194 | EOF 195 | ``` 196 | > yum install -y kubectl 197 | 198 | ``` 199 | vi ~/.kube/config 200 | ``` 201 | 202 | ## 服务安装 203 | 204 | ``` 205 | #-------------定义RabbitMQ部署----------------- 206 | apiVersion: apps/v1 207 | kind: Deployment 208 | metadata: 209 | name: rabbit 210 | spec: 211 | replicas: 1 212 | selector: 213 | matchLabels: 214 | app: rabbit 215 | strategy: 216 | rollingUpdate: 217 | maxSurge: 25% 218 | maxUnavailable: 25% 219 | type: RollingUpdate 220 | template: 221 | metadata: 222 | labels: 223 | app: rabbit 224 | spec: 225 | containers: 226 | - image: /rabbitmq:latest 227 | imagePullPolicy: IfNotPresent 228 | name: rabbit 229 | ports: 230 | - containerPort: 15672 231 | name: rabbit15672 232 | protocol: TCP 233 | - containerPort: 5672 234 | name: rabbit5672 235 | protocol: TCP 236 | --- 237 | #-----------------定义rabbit的代理服务,serviceName一定要和代码中的一致----------- 238 | apiVersion: v1 239 | kind: Service 240 | metadata: 241 | name: rabbitmq 242 | spec: 243 | ports: 244 | - name: rabbit32672 245 | nodePort: 32672 246 | port: 15672 247 | protocol: TCP 248 | targetPort: 15672 249 | - name: rabbit30672 250 | nodePort: 30672 251 | port: 5672 252 | protocol: TCP 253 | targetPort: 5672 254 | selector: 255 | app: rabbit 256 | type: NodePort 257 | ``` 258 | 259 | 在浏览器中输入:http://host:32672/,访问部署好的RabbitMQ。在登录页面输入用户名和密码(此处初始user/bitnami),系统将会进入RabbitMQ的主页。 260 | 261 | ### 项目打包 262 | 263 | > 登录 sudo docker login --username=[username] ccr.ccs.tencentyun.com 264 | 265 | ``` 266 | [root@VM_6_222_centos ~]# sudo docker login --username=aaabbbccc ccr.ccs.tencentyun.com 267 | Password: 268 | WARNING! Your password will be stored unencrypted in /root/.docker/config.json. 269 | Configure a credential helper to remove this warning. See 270 | https://docs.docker.com/engine/reference/commandline/login/#credentials-store 271 | 272 | Login Succeeded 273 | [root@VM_6_222_centos ~]# 274 | ``` 275 | 276 | 进行push 277 | ``` 278 | docker push ccr.ccs.tencentyun.com/spring-boot-cloud/zipkin:latest 279 | docker push ccr.ccs.tencentyun.com/spring-boot-cloud/svcb-service:latest 280 | docker push ccr.ccs.tencentyun.com/spring-boot-cloud/svca-service:latest 281 | docker push ccr.ccs.tencentyun.com/spring-boot-cloud/auth-service:latest 282 | docker push ccr.ccs.tencentyun.com/spring-boot-cloud/monitor:latest 283 | docker push ccr.ccs.tencentyun.com/spring-boot-cloud/gateway:latest 284 | docker push ccr.ccs.tencentyun.com/spring-boot-cloud/registry:latest 285 | docker push ccr.ccs.tencentyun.com/spring-boot-cloud/config:latest 286 | ``` 287 | 288 | 调试网络安装telnet 289 | 290 | 在docker内安装telnet 291 | ``` 292 | mv /etc/apt/sources.list /etc/apt/sources.list.bak && echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list 293 | ``` 294 | 295 | > apt-get update 296 | 297 | > apt-get install telnet -y 298 | 299 | > apt-get install net-tools -y 300 | 301 | 302 | 303 | ### kubernetes中部署skywalking 304 | #### skywalking-oap-server 305 | ``` 306 | apiVersion: apps/v1 307 | kind: Deployment 308 | metadata: 309 | name: skywalking-oap-server 310 | spec: 311 | replicas: 1 312 | selector: 313 | matchLabels: 314 | app: skywalking-oap-server 315 | template: 316 | metadata: 317 | labels: 318 | app: skywalking-oap-server 319 | spec: 320 | containers: 321 | - image: apache/skywalking-oap-server:latest 322 | imagePullPolicy: IfNotPresent 323 | name: skywalking-oap-server 324 | ports: 325 | - containerPort: 11800 326 | name: grpc 327 | - containerPort: 12800 328 | name: rest 329 | --- 330 | #-----------------定义skywalking的代理服务-------------- 331 | apiVersion: v1 332 | kind: Service 333 | metadata: 334 | name: skywalking-oap-server 335 | spec: 336 | ports: 337 | - name: grpcporst 338 | nodePort: 31800 339 | port: 11800 340 | protocol: TCP 341 | targetPort: 11800 342 | - name: restport 343 | nodePort: 32100 344 | port: 12800 345 | protocol: TCP 346 | targetPort: 12800 347 | selector: 348 | app: skywalking-oap-server 349 | type: NodePort 350 | ``` 351 | 352 | #### skywalking-ui 353 | ``` 354 | apiVersion: apps/v1 355 | kind: Deployment 356 | metadata: 357 | name: skywalking-ui 358 | labels: 359 | app: skywalking-ui 360 | spec: 361 | replicas: 1 362 | selector: 363 | matchLabels: 364 | app: skywalking-ui 365 | template: 366 | metadata: 367 | labels: 368 | app: skywalking-ui 369 | spec: 370 | containers: 371 | - name: skywalking-ui 372 | image: apache/skywalking-ui:latest 373 | imagePullPolicy: Always 374 | ports: 375 | - containerPort: 8080 376 | name: httpport 377 | env: 378 | - name: SW_OAP_ADDRESS 379 | value: skywalking-oap-server:12800 380 | --- 381 | #-----------------定义skywalking-ui的代理服务-------------- 382 | apiVersion: v1 383 | kind: Service 384 | metadata: 385 | name: skywalking-ui 386 | labels: 387 | service: skywalking-ui 388 | spec: 389 | ports: 390 | - port: 8080 391 | name: httpport 392 | targetPort: 8080 393 | type: ClusterIP 394 | selector: 395 | app: skywalking-ui 396 | --- 397 | #-----------------定义skywalking-ui的ingress-------------- 398 | apiVersion: extensions/v1beta1 399 | kind: Ingress 400 | metadata: 401 | name: skywalking-ui 402 | spec: 403 | rules: 404 | - host: skywalking-ui.springcloud.com 405 | http: 406 | paths: 407 | - backend: 408 | serviceName: skywalking-ui 409 | servicePort: 8080 410 | ``` 411 | 412 | #### skywalking-agent 413 | 自建,参考https://hub.docker.com/r/prophet/skywalking-agent 414 | ``` 415 | FROM alpine:3.8 416 | 417 | LABEL maintainer="761396462@qq.com" 418 | 419 | ENV SKYWALKING_VERSION=7.0.0 420 | 421 | ADD http://mirrors.tuna.tsinghua.edu.cn/apache/skywalking/${SKYWALKING_VERSION}/apache-skywalking-apm-${SKYWALKING_VERSION}.tar.gz / 422 | 423 | RUN tar -zxvf /apache-skywalking-apm-${SKYWALKING_VERSION}.tar.gz && \ 424 | mv apache-skywalking-apm-bin skywalking && \ 425 | mv /skywalking/agent/optional-plugins/apm-trace-ignore-plugin* /skywalking/agent/plugins/ && \ 426 | echo -e "\n# Ignore Path" >> /skywalking/agent/config/agent.config && \ 427 | echo "# see https://github.com/apache/skywalking/blob/v7.0.0/docs/en/setup/service-agent/java-agent/agent-optional-plugins/trace-ignore-plugin.md" >> /skywalking/agent/config/agent.config && \ 428 | echo 'trace.ignore_path=${SW_IGNORE_PATH:/health}' >> /skywalking/agent/config/agent.config 429 | ``` 430 | 431 | > docker build -t ccr.ccs.tencentyun.com/haiyang/skywalking-agent:7.0.0 . 432 | 433 | 将镜像push到远程仓库 434 | 435 | > docker push ccr.ccs.tencentyun.com/haiyang/skywalking-agent:7.0.0 436 | 437 | 项目都打包好后,执行k8s.yaml即可,便可完成整个项目的部署 438 | 439 | https://github.com/puhaiyang/spring-boot-cloud/blob/master/k8s.yaml 440 | 441 | ![skywalking1](/screenshots/springCloud-skywalking1.png) 442 | ![skywalking2](/screenshots/springCloud-skywalking2.png) -------------------------------------------------------------------------------- /auth-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD ./target/auth-service.jar /app.jar 4 | RUN bash -c 'touch /app.jar' 5 | RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone 6 | EXPOSE 5000 7 | ENTRYPOINT ["java","-Dapp.id=authService","-javaagent:/opt/skywalking/agent/skywalking-agent.jar","-Dskywalking.agent.service_name=authService","-Dskywalking.collector.backend_service=skywalking-oap-server:11800","-jar","-Djava.security.egd=file:/dev/./urandom","/app.jar"] -------------------------------------------------------------------------------- /auth-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | cn.zhangxd 9 | spring-boot-cloud 10 | 1.0-SNAPSHOT 11 | 12 | 13 | auth-service 14 | 1.0-SNAPSHOT 15 | jar 16 | ${project.artifactId} 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-data-jpa 22 | 23 | 24 | com.h2database 25 | h2 26 | runtime 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-oauth2 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-netflix-eureka-server 37 | 38 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-sleuth 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-stream-binder-rabbit 46 | 47 | 48 | 49 | org.springframework.cloud 50 | spring-cloud-starter-config 51 | 52 | 53 | org.springframework.cloud 54 | spring-cloud-starter-bus-amqp 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-aop 67 | 68 | 69 | org.springframework.retry 70 | spring-retry 71 | 72 | 73 | org.jolokia 74 | jolokia-core 75 | 76 | 77 | org.springframework.cloud 78 | spring-cloud-starter-kubernetes 79 | 1.1.4.RELEASE 80 | 81 | 82 | 83 | 84 | ${project.artifactId} 85 | 86 | 87 | org.springframework.boot 88 | spring-boot-maven-plugin 89 | 90 | 91 | org.apache.maven.plugins 92 | maven-deploy-plugin 93 | 94 | 95 | org.apache.maven.plugins 96 | maven-surefire-plugin 97 | 98 | 99 | io.fabric8 100 | fabric8-maven-plugin 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /auth-service/src/main/java/cn/zhangxd/auth/AuthApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.auth; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class AuthApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AuthApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /auth-service/src/main/java/cn/zhangxd/auth/config/OAuthConfiguration.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.auth.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.annotation.Order; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 9 | import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter; 10 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 11 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; 12 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; 13 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 14 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; 15 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; 16 | import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; 17 | 18 | import javax.sql.DataSource; 19 | 20 | @Configuration 21 | @EnableAuthorizationServer 22 | public class OAuthConfiguration extends AuthorizationServerConfigurerAdapter { 23 | 24 | @Autowired 25 | private AuthenticationManager auth; 26 | 27 | @Autowired 28 | private DataSource dataSource; 29 | 30 | private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); 31 | 32 | @Bean 33 | public JdbcTokenStore tokenStore() { 34 | return new JdbcTokenStore(dataSource); 35 | } 36 | 37 | @Override 38 | public void configure(AuthorizationServerSecurityConfigurer security) 39 | throws Exception { 40 | security.passwordEncoder(passwordEncoder); 41 | } 42 | 43 | @Override 44 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) 45 | throws Exception { 46 | endpoints 47 | .authenticationManager(auth) 48 | .tokenStore(tokenStore()) 49 | ; 50 | } 51 | 52 | @Override 53 | public void configure(ClientDetailsServiceConfigurer clients) 54 | throws Exception { 55 | 56 | clients.jdbc(dataSource) 57 | .passwordEncoder(passwordEncoder) 58 | .withClient("client") 59 | .secret("secret") 60 | .authorizedGrantTypes("password", "refresh_token") 61 | .scopes("read", "write") 62 | .accessTokenValiditySeconds(3600) // 1 hour 63 | .refreshTokenValiditySeconds(2592000) // 30 days 64 | .and() 65 | .withClient("svca-service") 66 | .secret("password") 67 | .authorizedGrantTypes("client_credentials", "refresh_token") 68 | .scopes("server") 69 | .and() 70 | .withClient("svcb-service") 71 | .secret("password") 72 | .authorizedGrantTypes("client_credentials", "refresh_token") 73 | .scopes("server") 74 | ; 75 | 76 | } 77 | 78 | @Configuration 79 | @Order(-20) 80 | protected static class AuthenticationManagerConfiguration extends GlobalAuthenticationConfigurerAdapter { 81 | 82 | @Autowired 83 | private DataSource dataSource; 84 | 85 | @Override 86 | public void init(AuthenticationManagerBuilder auth) throws Exception { 87 | auth.jdbcAuthentication().dataSource(dataSource) 88 | .withUser("dave").password("secret").roles("USER") 89 | .and() 90 | .withUser("anil").password("password").roles("ADMIN") 91 | ; 92 | } 93 | } 94 | 95 | } -------------------------------------------------------------------------------- /auth-service/src/main/java/cn/zhangxd/auth/config/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.auth.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 6 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 7 | 8 | @Configuration 9 | @EnableResourceServer 10 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 11 | 12 | @Override 13 | public void configure(HttpSecurity http) throws Exception { 14 | http 15 | .requestMatchers().antMatchers("/current") 16 | .and() 17 | .authorizeRequests() 18 | .antMatchers("/current").access("#oauth2.hasScope('read')"); 19 | } 20 | } -------------------------------------------------------------------------------- /auth-service/src/main/java/cn/zhangxd/auth/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.auth.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import java.security.Principal; 8 | 9 | @RestController 10 | @RequestMapping("/") 11 | public class UserController { 12 | 13 | @GetMapping(value = "/current") 14 | public Principal getUser(Principal principal) { 15 | return principal; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /auth-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: auth-service 4 | cloud: 5 | config: 6 | uri: http://config:30876 7 | fail-fast: true 8 | username: user 9 | password: ${CONFIG_SERVER_PASSWORD:password} 10 | retry: 11 | initial-interval: 2000 12 | max-interval: 10000 13 | multiplier: 2 14 | max-attempts: 10 15 | -------------------------------------------------------------------------------- /auth-service/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /auth-service/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS `oauth_access_token`; 2 | CREATE TABLE `oauth_access_token` ( 3 | `token_id` varchar(256) DEFAULT NULL, 4 | `token` blob, 5 | `authentication_id` varchar(256) DEFAULT NULL, 6 | `user_name` varchar(256) DEFAULT NULL, 7 | `client_id` varchar(256) DEFAULT NULL, 8 | `authentication` blob, 9 | `refresh_token` varchar(256) DEFAULT NULL 10 | ); 11 | 12 | DROP TABLE IF EXISTS `oauth_client_details`; 13 | CREATE TABLE `oauth_client_details` ( 14 | `client_id` varchar(256) NOT NULL, 15 | `resource_ids` varchar(256) DEFAULT NULL, 16 | `client_secret` varchar(256) DEFAULT NULL, 17 | `scope` varchar(256) DEFAULT NULL, 18 | `authorized_grant_types` varchar(256) DEFAULT NULL, 19 | `web_server_redirect_uri` varchar(256) DEFAULT NULL, 20 | `authorities` varchar(256) DEFAULT NULL, 21 | `access_token_validity` int(11) DEFAULT NULL, 22 | `refresh_token_validity` int(11) DEFAULT NULL, 23 | `additional_information` varchar(4096) DEFAULT NULL, 24 | `autoapprove` varchar(256) DEFAULT NULL, 25 | PRIMARY KEY (`client_id`) 26 | ); 27 | 28 | DROP TABLE IF EXISTS `oauth_refresh_token`; 29 | CREATE TABLE `oauth_refresh_token` ( 30 | `token_id` varchar(256) DEFAULT NULL, 31 | `token` blob, 32 | `authentication` blob 33 | ); 34 | 35 | DROP TABLE IF EXISTS `users`; 36 | CREATE TABLE `users` ( 37 | `username` varchar(50) NOT NULL, 38 | `password` varchar(50) NOT NULL, 39 | `enabled` tinyint(1) NOT NULL, 40 | PRIMARY KEY (`username`) 41 | ); 42 | 43 | DROP TABLE IF EXISTS `authorities`; 44 | CREATE TABLE `authorities` ( 45 | `username` varchar(50) NOT NULL, 46 | `authority` varchar(50) NOT NULL, 47 | UNIQUE KEY `ix_auth_username` (`username`,`authority`) 48 | ); -------------------------------------------------------------------------------- /bill-biz-task/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /bill-biz-task/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.4.3 9 | 10 | 11 | cn.zhangxd 12 | bill-biz-task 13 | 1.0-SNAPSHOT 14 | bill-biz-task 15 | 业务定时任务-账单 16 | 17 | 1.8 18 | Hoxton.SR6 19 | 0.9.0 20 | yyyyMMddHHmm 21 | 1.2.1 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-actuator 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-starter-task 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | io.micrometer.prometheus 39 | prometheus-rsocket-spring 40 | ${prometheus-rsocket-spring.version} 41 | 42 | 43 | org.springframework.integration 44 | spring-integration-core 45 | 46 | 47 | org.springframework.integration 48 | spring-integration-jdbc 49 | 50 | 51 | org.mariadb.jdbc 52 | mariadb-java-client 53 | 54 | 55 | org.apache.httpcomponents 56 | httpmime 57 | 4.5.2 58 | 59 | 60 | org.apache.httpcomponents 61 | httpcore 62 | 4.4.6 63 | 64 | 65 | 66 | 67 | 68 | 69 | org.springframework.cloud 70 | spring-cloud-dependencies 71 | ${spring-cloud.version} 72 | pom 73 | import 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.springframework.boot 82 | spring-boot-maven-plugin 83 | 84 | 103 | 104 | 105 | 106 | 107 | spring-releases 108 | Spring Releases 109 | https://repo.spring.io/release 110 | 111 | 112 | 113 | 114 | spring-releases 115 | Spring Releases 116 | https://repo.spring.io/release 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /bill-biz-task/src/main/java/cn/zhangxd/billbiztask/BillBizTaskApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.billbiztask; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.task.configuration.EnableTask; 6 | 7 | /** 8 | * @author puhaiyang 9 | * @date 2021/3/13 10:11 10 | * BillBizTaskApplication 11 | */ 12 | @EnableTask 13 | @SpringBootApplication 14 | public class BillBizTaskApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(BillBizTaskApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /bill-biz-task/src/main/java/cn/zhangxd/billbiztask/runner/MyBillBizTaskRunner.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.billbiztask.runner; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.CommandLineRunner; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @author puhaiyang 11 | * @date 2021/3/11 21:50 12 | * MyBillBizTaskRunner 13 | */ 14 | @Component 15 | public class MyBillBizTaskRunner implements CommandLineRunner { 16 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 17 | 18 | @Value("${biz.process.seconds:10}") 19 | private Integer processTimeSeconds; 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | logger.error("MyBillBizTaskRunner start! thread:{}", Thread.currentThread().toString()); 24 | for (int i = 1; i <= processTimeSeconds; i++) { 25 | System.out.println("biz run." + i); 26 | Thread.sleep(1_000); 27 | } 28 | logger.error("MyBillBizTaskRunner end! thread:{}", Thread.currentThread().toString()); 29 | } 30 | } -------------------------------------------------------------------------------- /bill-biz-task/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | biz.process.seconds=13 2 | spring.cloud.task.name=bill-biz-task 3 | spring.cloud.task.closecontext-enabled=true 4 | spring.datasource.url=jdbc:mysql://192.168.1.11:30306/mysql 5 | spring.datasource.driver-class-name=org.mariadb.jdbc.Driver 6 | spring.datasource.username=root 7 | spring.datasource.password=yourpassword 8 | management.metrics.tags.service=task-application 9 | management.metrics.export.prometheus.rsocket.port=7001 10 | management.metrics.export.prometheus.rsocket.enabled=true 11 | management.metrics.export.prometheus.rsocket.host=prometheus-proxy 12 | spring.cloud.task.single-instance-enabled=true -------------------------------------------------------------------------------- /bill-biz-task/src/test/java/cn/zhangxd/billbiztask/HttpClientUtil.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.billbiztask; 2 | 3 | import io.micrometer.core.instrument.util.StringUtils; 4 | import org.apache.http.HeaderElement; 5 | import org.apache.http.HeaderElementIterator; 6 | import org.apache.http.HttpEntity; 7 | import org.apache.http.HttpResponse; 8 | import org.apache.http.client.config.RequestConfig; 9 | import org.apache.http.client.methods.*; 10 | import org.apache.http.client.protocol.HttpClientContext; 11 | import org.apache.http.conn.ConnectionKeepAliveStrategy; 12 | import org.apache.http.entity.StringEntity; 13 | import org.apache.http.impl.client.CloseableHttpClient; 14 | import org.apache.http.impl.client.HttpClients; 15 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; 16 | import org.apache.http.message.BasicHeaderElementIterator; 17 | import org.apache.http.protocol.HTTP; 18 | import org.apache.http.protocol.HttpContext; 19 | import org.apache.http.util.EntityUtils; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import java.nio.charset.Charset; 24 | 25 | /** 26 | * httpclient 请求工具类 27 | * httpclient 连接池 28 | * 29 | * @author weisibin 30 | * @date 2020-5-13 09:39:57 31 | */ 32 | public class HttpClientUtil { 33 | private static Logger log = LoggerFactory.getLogger(HttpClientUtil.class); 34 | 35 | /** 36 | * http链接池 37 | */ 38 | private static PoolingHttpClientConnectionManager cm = null; 39 | /** 40 | * http客户端 41 | */ 42 | private static CloseableHttpClient httpClient = null; 43 | /** 44 | * from-请求/响应 类型 45 | */ 46 | public static final String CONTENT_TYPE_FORM = "application/x-www-form-urlencoded;charset=UTF-8"; 47 | /** 48 | * json-请求/响应 类型 49 | */ 50 | public static final String CONTENT_TYPE_JSON = "application/json;charset=UTF-8"; 51 | 52 | /** 53 | * 长连接时间保持设置 54 | */ 55 | private static final int HTTP_DEFAULT_KEEP_TIME = 60000; 56 | 57 | /** 58 | * 1、MaxtTotal是整个池子的大小; 2、DefaultMaxPerRoute是根据连接到的主机对MaxTotal的一个细分;比如: 59 | * MaxtTotal=400 DefaultMaxPerRoute=200 60 | * 而我只连接到http://sishuok.com时,到这个主机的并发最多只有200;而不是400; 而我连接到http://sishuok.com 和 61 | * http://qq.com时,到每个主机的并发最多只有200;即加起来是400(但不能超过400); 62 | * 所以起作用的设置是DefaultMaxPerRoute。 63 | */ 64 | private static final int DEFAULT_MAX_PER_ROUTE = 1000; 65 | /** 66 | * 设置连接池的大小 67 | */ 68 | private static final int MAX_TOTAL = 1000; 69 | 70 | /** 71 | * 设置链接超时 72 | */ 73 | private static final int CONNECTION_TIMEOUT = 5000; 74 | /** 75 | * 设置等待数据超时时间 76 | */ 77 | private static final int SOCKET_TIMEOUT = 15000; 78 | 79 | /** 80 | * 初始化连接池 81 | */ 82 | private static synchronized void initPools() { 83 | if (httpClient == null) { 84 | cm = new PoolingHttpClientConnectionManager(); 85 | cm.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE); 86 | cm.setMaxTotal(MAX_TOTAL); 87 | httpClient = HttpClients.custom().setKeepAliveStrategy(defaultStrategy).setConnectionManager(cm).build(); 88 | } 89 | } 90 | 91 | /** 92 | * 长连接保持设置 Http connection keepAlive 设置 93 | */ 94 | private static ConnectionKeepAliveStrategy defaultStrategy = new ConnectionKeepAliveStrategy() { 95 | @Override 96 | public long getKeepAliveDuration(HttpResponse response, HttpContext context) { 97 | HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); 98 | int keepTime = HTTP_DEFAULT_KEEP_TIME; 99 | while (it.hasNext()) { 100 | HeaderElement he = it.nextElement(); 101 | String param = he.getName(); 102 | String value = he.getValue(); 103 | if (value != null && param.equalsIgnoreCase("timeout")) { 104 | try { 105 | return Long.parseLong(value) * 1000; 106 | } catch (Exception e) { 107 | e.printStackTrace(); 108 | log.error("format KeepAlive timeout exception, exception:{}", e.toString()); 109 | throw e; 110 | } 111 | } 112 | } 113 | return keepTime * 1000; 114 | } 115 | }; 116 | 117 | /** 118 | * 执行http post 119 | * 请求 默认采用Content-Type:application/json 120 | * 响应 默认采用Content-Type:application/json 121 | * 122 | * @param uri 请求地址 123 | * @param data 请求数据 124 | * @return String 返回是数据 125 | * @throws Exception 请求异常 126 | */ 127 | public static String sendPost(String uri, String data) throws Exception { 128 | return sendPost(uri, data, CONTENT_TYPE_JSON, CONTENT_TYPE_JSON); 129 | } 130 | 131 | /** 132 | * 执行http post请求 133 | * 134 | * @param uri 请求地址 135 | * @param data 请求数据 136 | * @param reqContentType 请求content-type 137 | * @param respContentType 响应content-type 138 | * @return String 返回请求结果 139 | * @throws Exception 异常 140 | */ 141 | public static String sendPost(String uri, String data, String reqContentType, String respContentType) 142 | throws Exception { 143 | long startTime = System.currentTimeMillis(); 144 | HttpEntity httpEntity = null; 145 | HttpEntityEnclosingRequestBase method = null; 146 | String responseBody = ""; 147 | try { 148 | if (httpClient == null) { 149 | initPools(); 150 | } 151 | method = (HttpEntityEnclosingRequestBase) getRequest(uri, HttpPost.METHOD_NAME, reqContentType, 152 | respContentType); 153 | method.setEntity(new StringEntity(data, Charset.forName("UTF-8"))); 154 | HttpContext context = HttpClientContext.create(); 155 | CloseableHttpResponse httpResponse = httpClient.execute(method, context); 156 | httpEntity = httpResponse.getEntity(); 157 | if (httpEntity != null) { 158 | responseBody = EntityUtils.toString(httpEntity, "UTF-8"); 159 | log.debug("post请求信息:\n请求URL: {},\n请求参数{},\n返回状态码:{},\n返回结果:{}", uri, data, 160 | httpResponse.getStatusLine().getStatusCode(), responseBody); 161 | } 162 | } catch (Exception e) { 163 | if (method != null) { 164 | method.abort(); 165 | } 166 | e.printStackTrace(); 167 | log.error("execute post request exception, url:{},exception:{}, cost time(ms):{}", uri, e.toString(), 168 | System.currentTimeMillis() - startTime); 169 | throw e; 170 | } finally { 171 | if (httpEntity != null) { 172 | try { 173 | EntityUtils.consumeQuietly(httpEntity); 174 | } catch (Exception e) { 175 | e.printStackTrace(); 176 | log.error("execute post request exception, url:{},exception:{}, cost time(ms):{}", uri, 177 | e.toString(), System.currentTimeMillis() - startTime); 178 | throw e; 179 | } 180 | } 181 | } 182 | return responseBody; 183 | } 184 | 185 | /** 186 | * 执行GET 请求 187 | * 请求 默认采用Content-Type:application/json 188 | * 响应 默认采用Content-Type:application/json 189 | * 190 | * @param uri 请求链接 191 | * @return String 请求结果 192 | * @throws Exception 异常 193 | */ 194 | public static String sendGet(String uri) throws Exception { 195 | return sendGet(uri, CONTENT_TYPE_JSON, CONTENT_TYPE_JSON); 196 | } 197 | 198 | /** 199 | * 执行GET 请求 200 | * 201 | * @param uri 请求链接 202 | * @param reqContentType 请求ContentType 203 | * @param respContentType 响应ContentType 204 | * @return String 响应数据 205 | * @throws Exception 异常 206 | */ 207 | public static String sendGet(String uri, String reqContentType, String respContentType) throws Exception { 208 | long startTime = System.currentTimeMillis(); 209 | HttpEntity httpEntity = null; 210 | HttpRequestBase method = null; 211 | String responseBody = ""; 212 | try { 213 | if (httpClient == null) { 214 | initPools(); 215 | } 216 | method = getRequest(uri, HttpGet.METHOD_NAME, reqContentType, respContentType); 217 | HttpContext context = HttpClientContext.create(); 218 | CloseableHttpResponse httpResponse = httpClient.execute(method, context); 219 | httpEntity = httpResponse.getEntity(); 220 | if (httpEntity != null) { 221 | responseBody = EntityUtils.toString(httpEntity, "UTF-8"); 222 | log.debug("get请求信息:\n请求URL: {},\n返回状态码:{},\n返回结果:{}", uri, 223 | httpResponse.getStatusLine().getStatusCode(), responseBody); 224 | } 225 | } catch (Exception e) { 226 | if (method != null) { 227 | method.abort(); 228 | } 229 | e.printStackTrace(); 230 | log.error("execute get request exception, url:{},exception:{}, cost time(ms):{}", uri, e.toString(), 231 | System.currentTimeMillis() - startTime); 232 | throw e; 233 | } finally { 234 | if (httpEntity != null) { 235 | try { 236 | EntityUtils.consumeQuietly(httpEntity); 237 | } catch (Exception e) { 238 | e.printStackTrace(); 239 | log.error("execute get request exception, url:{},exception:{}, cost time(ms):{}", uri, 240 | e.toString(), System.currentTimeMillis() - startTime); 241 | throw e; 242 | } 243 | } 244 | } 245 | return responseBody; 246 | } 247 | 248 | /** 249 | * 创建请求 250 | * 251 | * @param uri 请求url 252 | * @param methodName 请求的方法类型 253 | * @param reqContentType 请求ContentType 254 | * @param respContentType 响应ContentType 255 | * @return HttpRequestBase http请求的基本实现对象 256 | */ 257 | private static HttpRequestBase getRequest(String uri, String methodName, String reqContentType, 258 | String respContentType) { 259 | HttpRequestBase method = null; 260 | 261 | RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT) 262 | .setConnectTimeout(CONNECTION_TIMEOUT).setConnectionRequestTimeout(CONNECTION_TIMEOUT) 263 | .setExpectContinueEnabled(false).build(); 264 | if (HttpPut.METHOD_NAME.equalsIgnoreCase(methodName)) { 265 | method = new HttpPut(uri); 266 | } else if (HttpPost.METHOD_NAME.equalsIgnoreCase(methodName)) { 267 | method = new HttpPost(uri); 268 | } else if (HttpGet.METHOD_NAME.equalsIgnoreCase(methodName)) { 269 | method = new HttpGet(uri); 270 | } else { 271 | method = new HttpPost(uri); 272 | } 273 | if (StringUtils.isBlank(reqContentType)) { 274 | reqContentType = CONTENT_TYPE_FORM; 275 | } 276 | if (StringUtils.isBlank(respContentType)) { 277 | respContentType = CONTENT_TYPE_JSON; 278 | } 279 | // 请求类型 280 | method.addHeader("Content-Type", reqContentType); 281 | method.addHeader("Accept", respContentType); 282 | method.setConfig(requestConfig); 283 | return method; 284 | } 285 | 286 | /** 287 | * 获取 httpClient 288 | * 289 | * @return CloseableHttpClient 290 | */ 291 | public static CloseableHttpClient getHttpClient() { 292 | return httpClient; 293 | } 294 | 295 | /** 296 | * 获取 httpClient连接池 297 | * 298 | * @return PoolingHttpClientConnectionManager 299 | */ 300 | public static PoolingHttpClientConnectionManager getHttpConnectionManager() { 301 | return cm; 302 | } 303 | } 304 | -------------------------------------------------------------------------------- /bill-biz-task/src/test/java/cn/zhangxd/billbiztask/HttpTest.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.billbiztask; 2 | 3 | import ch.qos.logback.classic.Level; 4 | import ch.qos.logback.classic.LoggerContext; 5 | import com.sun.media.jfxmedia.logging.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.util.Date; 9 | 10 | public class HttpTest { 11 | public static void main(String[] args) throws Exception { 12 | LoggerContext logcontext = (LoggerContext) LoggerFactory.getILoggerFactory(); 13 | logcontext.getLogger("org.apache").setLevel(Level.ERROR); 14 | logcontext.getLogger("cn.zhangxd").setLevel(Level.ERROR); 15 | // String url = "http://192.168.1.11:30860/hello/getInstances?serviceName=svca-service¶m="; 16 | String url = "http://192.168.1.11:30880?id="; 17 | for (int i = 0; i < 1000; i++) { 18 | try { 19 | String body = HttpClientUtil.sendGet(url + i); 20 | System.out.println(new Date().toLocaleString()+"\t第[" + i + "]次请求,响应结果为:" + body); 21 | System.out.println(); 22 | Thread.sleep(1_000); 23 | } catch (Exception e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cluster-role-binding.yml: -------------------------------------------------------------------------------- 1 | kind: ClusterRoleBinding 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | metadata: 4 | name: default-crb 5 | subjects: 6 | - kind: ServiceAccount 7 | name: default 8 | namespace: default 9 | roleRef: 10 | apiGroup: rbac.authorization.k8s.io 11 | kind: ClusterRole 12 | name: cluster-admin -------------------------------------------------------------------------------- /config-repo/application-dev.yml: -------------------------------------------------------------------------------- 1 | ribbon: 2 | ReadTimeout: 5000 3 | ConnectTimeout: 5000 4 | 5 | #如果hystrix和sentinel都引入了,但是没有开启哪一个熔断器,默认会采用hystrix的;feign默认采用的也是hystrix 6 | #如果是HystrixTimer报的异常,则是hystix熔断触发的 7 | #如果sentinel指定的是关闭,hystirx没有指定,则也会是用hystrix 8 | #如果手动指定将sentinel和hystrix都设为了false,则会直接抛出异常,不会触发熔断处理 9 | feign: 10 | hystrix: 11 | enabled: true 12 | sentinel: 13 | enabled: false 14 | sys: 15 | config: 16 | value: dev456 17 | 18 | spring: 19 | cloud: 20 | kubernetes: 21 | ribbon: 22 | mode: service 23 | discovery: 24 | enabled: true 25 | client: 26 | namespace: default 27 | -------------------------------------------------------------------------------- /config-repo/application-prod.yml: -------------------------------------------------------------------------------- 1 | ribbon: 2 | ReadTimeout: 5000 3 | ConnectTimeout: 5000 4 | 5 | feign: 6 | hystrix: 7 | enabled: true 8 | 9 | sys: 10 | config: 11 | value: prod123 12 | 13 | spring: 14 | cloud: 15 | kubernetes: 16 | ribbon: 17 | mode: service 18 | discovery: 19 | enabled: true 20 | client: 21 | namespace: default 22 | -------------------------------------------------------------------------------- /config-repo/application.yml: -------------------------------------------------------------------------------- 1 | ribbon: 2 | ReadTimeout: 5000 3 | ConnectTimeout: 5000 4 | 5 | logging: 6 | level: 7 | root: debug 8 | 9 | feign: 10 | hystrix: 11 | enabled: true 12 | 13 | sys: 14 | config: 15 | value: default789 16 | 17 | spring: 18 | cloud: 19 | kubernetes: 20 | ribbon: 21 | mode: service 22 | discovery: 23 | enabled: true 24 | client: 25 | namespace: default 26 | -------------------------------------------------------------------------------- /config-repo/auth-service.yml: -------------------------------------------------------------------------------- 1 | server: 2 | context-path: /uaa 3 | port: 5000 4 | 5 | management: 6 | security: 7 | enabled: false 8 | context-path: /mgmt 9 | 10 | eureka: 11 | instance: 12 | health-check-url-path: ${server.context-path}${management.context-path}/health 13 | status-page-url-path: ${server.context-path}${management.context-path}/info 14 | metadata-map: 15 | management.context-path: ${server.context-path}${management.context-path} 16 | 17 | spring: 18 | datasource: 19 | url: jdbc:h2:mem:user 20 | driver-class-name: org.h2.Driver 21 | jpa: 22 | show-sql: true 23 | -------------------------------------------------------------------------------- /config-repo/gateway.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 30080 3 | 4 | management: 5 | security: 6 | enabled: false 7 | 8 | spring: 9 | cloud: 10 | gateway: 11 | discovery: 12 | locator: 13 | enabled: true 14 | routes: 15 | - id: svca-service 16 | uri: lb://svca-service 17 | predicates: 18 | - Path=/svca/** 19 | filters: 20 | - StripPrefix=1 21 | - id: svcb-service 22 | uri: lb://svcb-service 23 | predicates: 24 | - Path=/svcb/** 25 | filters: 26 | - StripPrefix=1 27 | - id: openapi 28 | uri: http://localhost:${server.port} 29 | predicates: 30 | - Path=/v3/api-docs/** 31 | filters: 32 | - RewritePath=/v3/api-docs/(?.*), /$\{path}/v3/api-docs 33 | hystrix: 34 | command: 35 | default: 36 | execution: 37 | isolation: 38 | thread: 39 | timeoutInMilliseconds: 20000 40 | 41 | ribbon: 42 | ReadTimeout: 10000 43 | ConnectTimeout: 10000 44 | springdoc: 45 | swagger-ui: 46 | urls: 47 | - name: gateway 48 | url: /v3/api-docs 49 | - name: svca 50 | url: /v3/api-docs/svca 51 | - name: svcb 52 | url: /v3/api-docs/svcb 53 | -------------------------------------------------------------------------------- /config-repo/svca-service-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | cloud: 5 | kubernetes: 6 | discovery: 7 | enabled: true 8 | client: 9 | namespace: default 10 | 11 | sys: 12 | config: 13 | value: dev-svca-service-666 -------------------------------------------------------------------------------- /config-repo/svca-service-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | cloud: 5 | kubernetes: 6 | discovery: 7 | enabled: true 8 | client: 9 | namespace: default -------------------------------------------------------------------------------- /config-repo/svca-service.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | cloud: 5 | kubernetes: 6 | discovery: 7 | enabled: true 8 | client: 9 | namespace: default -------------------------------------------------------------------------------- /config-repo/svcb-service-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8070 3 | 4 | msg: Hello -------------------------------------------------------------------------------- /config-repo/svcb-service-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8070 3 | 4 | msg: Hello -------------------------------------------------------------------------------- /config-repo/svcb-service.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8070 3 | 4 | msg: Hello -------------------------------------------------------------------------------- /config-repo/user-biz-task-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | task: 4 | #不允许并发执行 5 | single-instance-enabled: true 6 | #task执行完毕时关闭上下文 7 | closecontext-enabled: true 8 | #业务处理时长,模拟业务耗时 9 | biz: 10 | process: 11 | seconds: 30 12 | -------------------------------------------------------------------------------- /config/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD ./target/config.jar /app.jar 4 | RUN bash -c 'touch /app.jar' 5 | RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone 6 | EXPOSE 8888 7 | ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","/app.jar"] -------------------------------------------------------------------------------- /config/config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: config 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: config 10 | strategy: 11 | rollingUpdate: 12 | maxSurge: 1 13 | maxUnavailable: 0 14 | type: RollingUpdate 15 | template: 16 | metadata: 17 | labels: 18 | app: config 19 | spec: 20 | initContainers: 21 | - name: init-skywalking-agent 22 | image: apache/skywalking-java-agent:8.12.0-java8 23 | command: 24 | - 'sh' 25 | - '-c' 26 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 27 | volumeMounts: 28 | - mountPath: /vmskywalking/agent 29 | name: skywalking-agent 30 | containers: 31 | - image: haiyanggroup-docker.pkg.coding.net/spring-boot-cloud/config/config:master-202209111517 32 | imagePullPolicy: Always 33 | name: config 34 | ports: 35 | - containerPort: 8888 36 | protocol: TCP 37 | volumeMounts: 38 | - mountPath: /opt/skywalking/agent 39 | name: skywalking-agent 40 | volumes: 41 | - name: skywalking-agent 42 | emptyDir: {} 43 | --- 44 | apiVersion: v1 45 | kind: Service 46 | metadata: 47 | name: config 48 | spec: 49 | type: NodePort 50 | ports: 51 | - name: http 52 | port: 30876 53 | protocol: TCP 54 | targetPort: 30876 55 | nodePort: 31018 56 | selector: 57 | app: config -------------------------------------------------------------------------------- /config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | cn.zhangxd 9 | spring-boot-cloud 10 | 1.0-SNAPSHOT 11 | 12 | 13 | config 14 | v3 15 | jar 16 | ${project.artifactId} 17 | 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-config-server 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-kubernetes-fabric8 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-commons 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-web 47 | 48 | 49 | 50 | 51 | ${project.artifactId} 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | org.apache.maven.plugins 59 | maven-deploy-plugin 60 | 61 | 62 | org.apache.maven.plugins 63 | maven-surefire-plugin 64 | 65 | 66 | io.fabric8 67 | fabric8-maven-plugin 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /config/src/main/fabric8/service.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: config 6 | spec: 7 | type: NodePort 8 | ports: 9 | - name: http 10 | port: 30876 11 | protocol: TCP 12 | targetPort: 30876 13 | nodePort: 30876 14 | selector: 15 | app: config -------------------------------------------------------------------------------- /config/src/main/java/cn/zhangxd/config/ConfigApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.config; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.config.server.EnableConfigServer; 8 | 9 | @EnableDiscoveryClient 10 | @EnableConfigServer 11 | @SpringBootApplication 12 | public class ConfigApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ConfigApplication.class, args); 16 | } 17 | } -------------------------------------------------------------------------------- /config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 30876 3 | spring: 4 | cloud: 5 | config: 6 | server: 7 | git: 8 | uri: https://gitee.com/puhaiyang/spring-boot-cloud.git 9 | search-paths: config-repo 10 | timeout: 20 11 | kubernetes: 12 | discovery: 13 | enabled: true 14 | management: 15 | endpoints: 16 | web: 17 | exposure: 18 | include: "*" -------------------------------------------------------------------------------- /config/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: config -------------------------------------------------------------------------------- /devops/jenkins/jenkinsfile: -------------------------------------------------------------------------------- 1 | /** 2 | * 获取项目模块列表 3 | */ 4 | def static getModuleList() { 5 | return ['auth-service', 'config', 'gateway', 'monitor', 'registry', 'svca-service', 'svcb-service', 'zipkin'] 6 | } 7 | 8 | 9 | /** 10 | * 发送钉钉审计消息 11 | * @param deployModuleName 部署的项目名称 12 | * @param packageSubmitter 申请发布人 13 | * @param auditSubmitterDingTalkMobile 审计人钉钉的手机号 14 | * @return 15 | */ 16 | def sendDingtalkAuditMsg(deployModuleName, packageSubmitter, auditSubmitterDingTalkMobile) { 17 | dingtalk( 18 | robot: dingTalkRobotId, 19 | type: 'ACTION_CARD', 20 | title: '审批通知消息', 21 | text: [ 22 | '审批提醒', 23 | '---', 24 | '大佬好呀,您有一个发布项目的审批提醒喔!', 25 | "- 模块名称: ${deployModuleName}", 26 | "- 发起人: ${packageSubmitter}" 27 | ], 28 | btns: [ 29 | [ 30 | title : '前往审批', 31 | actionUrl: 'https://www.dingtalk.com/' 32 | ], 33 | [ 34 | title : '不予处理', 35 | actionUrl: 'https://www.dingtalk.com/' 36 | ] 37 | ], 38 | at: [auditSubmitterDingTalkMobile] 39 | ) 40 | } 41 | /** 42 | * 发布部署成功的通知 43 | * @param deployModuleName 模块名称 44 | * @param packageSubmitter 发包人 45 | * @param aduitInputResult 审核人 46 | */ 47 | def sendDeploySuccessDingtalkMsg(deployModuleName, packageSubmitter, aduitInputResult) { 48 | dingtalk( 49 | robot: dingTalkRobotId, 50 | type: 'MARKDOWN', 51 | title: '部署完毕通知', 52 | atAll: true, 53 | text: [ 54 | '部署完毕通知', 55 | '---', 56 | "各位大佬好呀!", 57 | "- 模块名称: ${deployModuleName}", 58 | "- 发起人: ${packageSubmitter}", 59 | "- 审批人: ${aduitInputResult}", 60 | "", 61 | "已完成部署" 62 | ] 63 | ) 64 | } 65 | 66 | pipeline { 67 | agent any 68 | 69 | environment { 70 | //打包输入框结果 71 | packageInputResult = '' 72 | //审批输入框结果 73 | aduitInputResult = '' 74 | packageSubmitter = 'puhaiyang(具有发起打包权限的用户名)' 75 | auditSubmitter = 'puhaiyang(具有审核权限的jenkins用户名)' 76 | dingTalkRobotId = '钉钉机器人ID' 77 | auditSubmitterDingTalkMobile = '审核人的钉钉手机号,用于在钉钉群里@他' 78 | moduleList = getModuleList() 79 | } 80 | 81 | stages { 82 | stage('打包') { 83 | steps { 84 | script { 85 | //部署的模块列表 86 | packageInputResult = input id: 'Test_deploy_001', message: '请选择将要发布的模块', ok: '确定', 87 | parameters: [choice(choices: moduleList, description: '请选择部署的项目', name: 'deployModuleName')], 88 | submitter: "${packageSubmitter}", submitterParameter: 'packageSubmitter' 89 | } 90 | echo "${packageInputResult.deployModuleName} will deploy!!!" 91 | } 92 | } 93 | 94 | stage('审批') { 95 | steps { 96 | //发送通知告诉审批人有新的任务需要进行审批了 97 | sendDingtalkAuditMsg(packageInputResult.deployModuleName, packageInputResult.packageSubmitter, auditSubmitterDingTalkMobile) 98 | script { 99 | aduitInputResult = input message: "确定发布${packageInputResult.deployModuleName}模块吗?", 100 | ok: '确定', submitter: "${auditSubmitter}", submitterParameter: 'auditSubmitter' 101 | } 102 | echo "${aduitInputResult}审核完毕" 103 | } 104 | } 105 | 106 | stage('发布') { 107 | steps { 108 | echo "${packageInputResult.deployModuleName}发布完毕" 109 | //发布完,通知所有人发布完成了 110 | sendDeploySuccessDingtalkMsg("${packageInputResult.deployModuleName}", "${packageInputResult.packageSubmitter}", "${aduitInputResult}") 111 | } 112 | } 113 | } 114 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | rabbitmq: 4 | image: rabbitmq:3-management 5 | restart: always 6 | ports: 7 | - 15673:15672 8 | registry: 9 | image: spring-boot-cloud/registry 10 | ports: 11 | - "8761:8761" 12 | config: 13 | image: spring-boot-cloud/config 14 | ports: 15 | - "8888:8888" 16 | monitor: 17 | image: spring-boot-cloud/monitor 18 | ports: 19 | - "8040:8040" 20 | zipkin: 21 | image: spring-boot-cloud/zipkin 22 | ports: 23 | - "9411:9411" 24 | gateway: 25 | image: spring-boot-cloud/gateway 26 | ports: 27 | - "8060:8060" 28 | auth-service: 29 | image: spring-boot-cloud/auth-service 30 | ports: 31 | - "5000:5000" 32 | svca-service: 33 | image: spring-boot-cloud/svca-service 34 | svcb-service: 35 | image: spring-boot-cloud/svcb-service -------------------------------------------------------------------------------- /gateway/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD ./target/gateway.jar /app.jar 4 | RUN bash -c 'touch /app.jar' 5 | RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone 6 | EXPOSE 8060 7 | ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","/app.jar"] -------------------------------------------------------------------------------- /gateway/gateway.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: gateway 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: gateway 10 | strategy: 11 | rollingUpdate: 12 | maxSurge: 1 13 | maxUnavailable: 0 14 | type: RollingUpdate 15 | template: 16 | metadata: 17 | labels: 18 | app: gateway 19 | spec: 20 | initContainers: 21 | - name: init-skywalking-agent 22 | image: apache/skywalking-java-agent:8.12.0-java8 23 | volumeMounts: 24 | - name: skywalking-agent 25 | mountPath: /agent 26 | command: [ "/bin/sh" ] 27 | args: [ "-c", "cp -R /skywalking/agent /agent/" ] 28 | containers: 29 | - image: haiyanggroup-docker.pkg.coding.net/spring-boot-cloud/gateway/gateway:master-202209121517 30 | imagePullPolicy: Always 31 | name: gateway 32 | ports: 33 | - containerPort: 30080 34 | protocol: TCP 35 | env: 36 | - name: JAVA_TOOL_OPTIONS 37 | value: "-javaagent:/skywalking/agent/skywalking-agent.jar" 38 | - name: SW_AGENT_NAME 39 | value: "gateway" 40 | - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES 41 | value: "skywalking-oap-server:11800" 42 | volumeMounts: 43 | - name: skywalking-agent 44 | mountPath: /skywalking 45 | volumes: 46 | - name: skywalking-agent 47 | emptyDir: {} 48 | --- 49 | apiVersion: v1 50 | kind: Service 51 | metadata: 52 | name: gateway 53 | spec: 54 | type: NodePort 55 | ports: 56 | - name: http 57 | port: 30080 58 | protocol: TCP 59 | targetPort: 30080 60 | nodePort: 30080 61 | selector: 62 | app: gateway -------------------------------------------------------------------------------- /gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | cn.zhangxd 9 | spring-boot-cloud 10 | 1.0-SNAPSHOT 11 | 12 | 13 | gateway 14 | v3 15 | jar 16 | ${project.artifactId} 17 | 18 | 19 | 20 | 21 | org.springdoc 22 | springdoc-openapi-webflux-ui 23 | 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-kubernetes-fabric8 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-kubernetes-fabric8-loadbalancer 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-commons 37 | 38 | 39 | org.springframework.cloud 40 | spring-cloud-starter-gateway 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-webflux 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter 49 | 50 | 51 | org.springframework.cloud 52 | spring-cloud-starter-config 53 | 54 | 55 | org.springframework.cloud 56 | spring-cloud-starter-bootstrap 57 | 58 | 59 | org.apache.skywalking 60 | apm-toolkit-logback-1.x 61 | 62 | 63 | 64 | 65 | 66 | ${project.artifactId} 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-maven-plugin 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-deploy-plugin 75 | 76 | 77 | org.apache.maven.plugins 78 | maven-surefire-plugin 79 | 80 | 81 | io.fabric8 82 | fabric8-maven-plugin 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /gateway/src/main/fabric8/service.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: gateway 6 | spec: 7 | type: NodePort 8 | ports: 9 | - name: http 10 | port: 8060 11 | protocol: TCP 12 | targetPort: 8060 13 | nodePort: 30860 14 | selector: 15 | app: gateway -------------------------------------------------------------------------------- /gateway/src/main/java/cn/zhangxd/gateway/GatewayApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.gateway; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | public class GatewayApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(GatewayApplication.class, args); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /gateway/src/main/java/cn/zhangxd/gateway/config/SpringDocConfig.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.gateway.config; 2 | 3 | import io.swagger.v3.oas.models.ExternalDocumentation; 4 | import io.swagger.v3.oas.models.OpenAPI; 5 | import io.swagger.v3.oas.models.info.Info; 6 | import io.swagger.v3.oas.models.info.License; 7 | import org.springdoc.core.GroupedOpenApi; 8 | import org.springdoc.core.SwaggerUiConfigParameters; 9 | import org.springframework.cloud.gateway.route.RouteDefinition; 10 | import org.springframework.cloud.gateway.route.RouteDefinitionLocator; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | import org.springframework.context.annotation.Lazy; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | @Configuration 19 | public class SpringDocConfig { 20 | 21 | @Bean 22 | public OpenAPI myOpenAPI() { 23 | return new OpenAPI() 24 | .info(new Info().title("GATEWAY API") 25 | .description("网关") 26 | .version("v1.0.0") 27 | .license(new License().name("Apache 2.0").url("https://github.com/puhaiyang"))) 28 | .externalDocs(new ExternalDocumentation() 29 | .description("天下武功,无坚不破,唯快不破") 30 | .url("https://blog.csdn.net/puhaiyang")); 31 | } 32 | 33 | 34 | /** 35 | * springdoc根据请求url自动分组
36 | * 参考:https://github.com/springdoc/springdoc-openapi-demos/tree/master/springdoc-openapi-microservices 37 | */ 38 | @Bean 39 | @Lazy(false) 40 | public List apis(SwaggerUiConfigParameters swaggerUiConfigParameters, RouteDefinitionLocator locator) { 41 | List groups = new ArrayList<>(); 42 | List definitions = locator.getRouteDefinitions().collectList().block(); 43 | //遍历定义的路由列表 44 | for (RouteDefinition definition : definitions) { 45 | System.out.println("id: " + definition.getId()+ " "+definition.getUri().toString()); 46 | } 47 | definitions.stream().filter(routeDefinition -> routeDefinition.getId().matches(".*-service")).forEach(routeDefinition -> { 48 | //获取出名称部分 49 | String name = routeDefinition.getId().replaceAll("-service", ""); 50 | //进行自动分组 51 | swaggerUiConfigParameters.addGroup(name); 52 | GroupedOpenApi.builder().pathsToMatch("/" + name + "/**").group(name).build(); 53 | }); 54 | return groups; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8060 -------------------------------------------------------------------------------- /gateway/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: gateway 4 | cloud: 5 | # 本地调试时,不从lb中访问服务 6 | gateway: 7 | discovery: 8 | locator: 9 | enabled: true 10 | routes: 11 | - id: service_a 12 | uri: http://127.0.0.1:8080 13 | predicates: 14 | - Path=/hello/** 15 | filters: 16 | - StripPrefix=1 17 | # 开发时注释掉下面的信息,不从config拉配置 18 | config: 19 | uri: http://config:30876 20 | fail-fast: true 21 | username: user 22 | password: ${CONFIG_SERVER_PASSWORD:password} 23 | retry: 24 | initial-interval: 2000 25 | max-interval: 10000 26 | multiplier: 2 27 | max-attempts: 10 28 | -------------------------------------------------------------------------------- /gateway/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *.orig 18 | *~ 19 | # Various IDEs 20 | .project 21 | .idea/ 22 | *.tmproj 23 | .vscode/ 24 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: common-modle-springbootcloud 3 | description: A Helm chart for Kubernetes of registry 4 | 5 | # A chart can be either an 'application' or a 'library' chart. 6 | # 7 | # Application charts are a collection of templates that can be packaged into versioned archives 8 | # to be deployed. 9 | # 10 | # Library charts provide useful utilities or functions for the chart developer. They're included as 11 | # a dependency of application charts to inject those utilities and functions into the rendering 12 | # pipeline. Library charts do not define any templates and therefore cannot be deployed. 13 | type: application 14 | 15 | # This is the chart version. This version number should be incremented each time you make changes 16 | # to the chart and its templates, including the app version. 17 | # Versions are expected to follow Semantic Versioning (https://semver.org/) 18 | version: 0.1.0 19 | 20 | # This is the version number of the application being deployed. This version number should be 21 | # incremented each time you make changes to the application. Versions are not expected to 22 | # follow Semantic Versioning. They should reflect the version the application is using. 23 | appVersion: 1.16.0 24 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/templates/NOTES.txt: -------------------------------------------------------------------------------- 1 | hi,boy!the application {{ .Release.Name }} has successful deployed! 2 | 3 | dockerImage: {{ .Values.image.repository }}:{{ .Values.image.tag }} 4 | chartName: {{ .Chart.Name }} 5 | containerPort: {{ .Values.image.containerPort }} 6 | serviceType: {{ .Values.service.type }} 7 | {{- if eq "NodePort" .Values.service.type }} 8 | nodePort: {{ .Values.service.nodePort }} 9 | {{- end }} 10 | appName: {{ .Release.Name }} 11 | nameSpace: {{ .Release.Namespace }} 12 | readinessIsEnable: {{ .Values.readiness.enabled }} 13 | ------------------------- 14 | :-D Have a nice day! :-D 15 | ------------------------- -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | {{/* 3 | Expand the name of the chart. 4 | */}} 5 | {{- define "registry.name" -}} 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} 7 | {{- end }} 8 | 9 | {{/* 10 | Create a default fully qualified app name. 11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 12 | If release name contains chart name it will be used as a full name. 13 | */}} 14 | {{- define "registry.fullname" -}} 15 | {{- if .Values.fullnameOverride }} 16 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} 17 | {{- else }} 18 | {{- $name := default .Chart.Name .Values.nameOverride }} 19 | {{- if contains $name .Release.Name }} 20 | {{- .Release.Name | trunc 63 | trimSuffix "-" }} 21 | {{- else }} 22 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} 23 | {{- end }} 24 | {{- end }} 25 | {{- end }} 26 | 27 | {{/* 28 | Create chart name and version as used by the chart label. 29 | */}} 30 | {{- define "registry.chart" -}} 31 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} 32 | {{- end }} 33 | 34 | {{/* 35 | Common labels 36 | */}} 37 | {{- define "registry.labels" -}} 38 | helm.sh/chart: {{ include "registry.chart" . }} 39 | {{ include "registry.selectorLabels" . }} 40 | {{- if .Chart.AppVersion }} 41 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 42 | {{- end }} 43 | app.kubernetes.io/managed-by: {{ .Release.Service }} 44 | {{- end }} 45 | 46 | {{/* 47 | Selector labels 48 | */}} 49 | {{- define "registry.selectorLabels" -}} 50 | app.kubernetes.io/name: {{ include "registry.name" . }} 51 | app.kubernetes.io/instance: {{ .Release.Name }} 52 | {{- end }} 53 | 54 | {{/* 55 | Create the name of the service account to use 56 | */}} 57 | {{- define "registry.serviceAccountName" -}} 58 | {{- if .Values.serviceAccount.create }} 59 | {{- default (include "registry.fullname" .) .Values.serviceAccount.name }} 60 | {{- else }} 61 | {{- default "default" .Values.serviceAccount.name }} 62 | {{- end }} 63 | {{- end }} 64 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: {{ include "registry.fullname" . }} 5 | labels: 6 | {{- include "registry.labels" . | nindent 4 }} 7 | spec: 8 | {{- if not .Values.autoscaling.enabled }} 9 | replicas: {{ .Values.replicaCount }} 10 | {{- end }} 11 | selector: 12 | matchLabels: 13 | {{- include "registry.selectorLabels" . | nindent 6 }} 14 | template: 15 | metadata: 16 | {{- with .Values.podAnnotations }} 17 | annotations: 18 | {{- toYaml . | nindent 8 }} 19 | {{- end }} 20 | labels: 21 | {{- include "registry.selectorLabels" . | nindent 8 }} 22 | spec: 23 | {{- if .Values.skywalkingAgent.enabled }} 24 | initContainers: 25 | - name: init-skywalking-agent 26 | image: "{{ .Values.skywalkingAgent.image.repository | default "ccr.ccs.tencentyun.com/haiyang/skywalking-agent" }}:{{ .Values.skywalkingAgent.image.tag | default "7.0.0" }}" 27 | command: 28 | - "sh" 29 | - "-c" 30 | - "set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;" 31 | volumeMounts: 32 | - mountPath: /vmskywalking/agent 33 | name: skywalking-agent 34 | {{- end }} 35 | {{- with .Values.imagePullSecrets }} 36 | imagePullSecrets: 37 | {{- toYaml . | nindent 8 }} 38 | {{- end }} 39 | serviceAccountName: {{ include "registry.serviceAccountName" . }} 40 | securityContext: 41 | {{- toYaml .Values.podSecurityContext | nindent 8 }} 42 | containers: 43 | - name: {{ .Chart.Name }} 44 | securityContext: 45 | {{- toYaml .Values.securityContext | nindent 12 }} 46 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" 47 | imagePullPolicy: {{ .Values.image.pullPolicy }} 48 | ports: 49 | - name: http 50 | containerPort: {{ .Values.image.containerPort | default 8080 }} 51 | protocol: TCP 52 | resources: 53 | {{- toYaml .Values.resources | nindent 12 }} 54 | {{- if .Values.readiness.enabled }} 55 | readinessProbe: 56 | exec: 57 | command: 58 | - echo 59 | - '0' 60 | initialDelaySeconds: 180 61 | periodSeconds: 10 62 | {{- end }} 63 | env: 64 | - name: EUREKA_SERVER_ADDRESS 65 | value: "{{- .Values.evn.eureka_server_address }}" 66 | - name: CONFIG_SERVER_ADDRESS 67 | value: "{{- .Values.evn.config_server_address }}" 68 | - name: SPRING_PROFILES_ACTIVE 69 | value: "{{- .Values.evn.spring_profiles_active }}" 70 | {{- if .Values.skywalkingAgent.enabled }} 71 | volumeMounts: 72 | - mountPath: /opt/skywalking/agent 73 | name: skywalking-agent 74 | volumes: 75 | - name: skywalking-agent 76 | emptyDir: {} 77 | {{- end }} 78 | {{- with .Values.nodeSelector }} 79 | nodeSelector: 80 | {{- toYaml . | nindent 8 }} 81 | {{- end }} 82 | {{- with .Values.affinity }} 83 | affinity: 84 | {{- toYaml . | nindent 8 }} 85 | {{- end }} 86 | {{- with .Values.tolerations }} 87 | tolerations: 88 | {{- toYaml . | nindent 8 }} 89 | {{- end }} 90 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/templates/hpa.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.autoscaling.enabled }} 2 | apiVersion: autoscaling/v2beta1 3 | kind: HorizontalPodAutoscaler 4 | metadata: 5 | name: {{ include "registry.fullname" . }} 6 | labels: 7 | {{- include "registry.labels" . | nindent 4 }} 8 | spec: 9 | scaleTargetRef: 10 | apiVersion: apps/v1 11 | kind: Deployment 12 | name: {{ include "registry.fullname" . }} 13 | minReplicas: {{ .Values.autoscaling.minReplicas }} 14 | maxReplicas: {{ .Values.autoscaling.maxReplicas }} 15 | metrics: 16 | {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} 17 | - type: Resource 18 | resource: 19 | name: cpu 20 | targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} 21 | {{- end }} 22 | {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} 23 | - type: Resource 24 | resource: 25 | name: memory 26 | targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} 27 | {{- end }} 28 | {{- end }} 29 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/templates/ingress.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.ingress.enabled -}} 2 | {{- $fullName := include "registry.fullname" . -}} 3 | {{- $svcPort := .Values.service.port -}} 4 | {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} 5 | apiVersion: networking.k8s.io/v1beta1 6 | {{- else -}} 7 | apiVersion: extensions/v1beta1 8 | {{- end }} 9 | kind: Ingress 10 | metadata: 11 | name: {{ $fullName }} 12 | labels: 13 | {{- include "registry.labels" . | nindent 4 }} 14 | {{- with .Values.ingress.annotations }} 15 | annotations: 16 | {{- toYaml . | nindent 4 }} 17 | {{- end }} 18 | spec: 19 | {{- if .Values.ingress.tls }} 20 | tls: 21 | {{- range .Values.ingress.tls }} 22 | - hosts: 23 | {{- range .hosts }} 24 | - {{ . | quote }} 25 | {{- end }} 26 | secretName: {{ .secretName }} 27 | {{- end }} 28 | {{- end }} 29 | rules: 30 | {{- range .Values.ingress.hosts }} 31 | - host: {{ .host | quote }} 32 | http: 33 | paths: 34 | {{- range .paths }} 35 | - path: {{ . }} 36 | backend: 37 | serviceName: {{ $fullName }} 38 | servicePort: {{ $svcPort }} 39 | {{- end }} 40 | {{- end }} 41 | {{- end }} 42 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ include "registry.fullname" . }} 5 | labels: 6 | {{- include "registry.labels" . | nindent 4 }} 7 | spec: 8 | type: {{ .Values.service.type }} 9 | ports: 10 | - port: {{ .Values.service.port }} 11 | {{- if eq .Values.service.type "NodePort"}} 12 | nodePort: {{ .Values.service.nodePort }} 13 | {{- end}} 14 | targetPort: http 15 | protocol: TCP 16 | name: http 17 | selector: 18 | {{- include "registry.selectorLabels" . | nindent 4 }} 19 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/templates/serviceaccount.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.serviceAccount.create -}} 2 | apiVersion: v1 3 | kind: ServiceAccount 4 | metadata: 5 | name: {{ include "registry.serviceAccountName" . }} 6 | labels: 7 | {{- include "registry.labels" . | nindent 4 }} 8 | {{- with .Values.serviceAccount.annotations }} 9 | annotations: 10 | {{- toYaml . | nindent 4 }} 11 | {{- end }} 12 | {{- end }} 13 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/templates/tests/test-connection.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: "{{ include "registry.fullname" . }}-test-connection" 5 | labels: 6 | {{- include "registry.labels" . | nindent 4 }} 7 | annotations: 8 | "helm.sh/hook": test-success 9 | spec: 10 | containers: 11 | - name: wget 12 | image: busybox 13 | command: ['wget'] 14 | args: ['{{ include "registry.fullname" . }}:{{ .Values.service.port }}'] 15 | restartPolicy: Never 16 | -------------------------------------------------------------------------------- /helms/common-modle-springbootcloud/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | #--------------------每个项目的配置 begin------------------------ 16 | ##Deployment 17 | image: 18 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/common-modle-springbootcloud 19 | pullPolicy: Always 20 | # Overrides the image tag whose default is the chart version. 21 | tag: "latest" 22 | containerPort: 8080 23 | resources: 24 | requests: 25 | cpu: "50m" 26 | memory: "256Mi" 27 | limits: 28 | cpu: "1" 29 | memory: "1024Mi" 30 | evn: 31 | eureka_server_address: "eureka" 32 | config_server_address: "config" 33 | spring_profiles_active: "test" 34 | #平滑部署开关 35 | readiness: 36 | enabled: true 37 | ##service 38 | service: 39 | type: ClusterIP 40 | port: 8080 41 | nodePort: 8080 42 | #---------------------每个项目的配置 end----------------------- 43 | 44 | 45 | imagePullSecrets: [] 46 | nameOverride: "" 47 | fullnameOverride: "" 48 | 49 | serviceAccount: 50 | # Specifies whether a service account should be created 51 | create: false 52 | # Annotations to add to the service account 53 | annotations: {} 54 | # The name of the service account to use. 55 | # If not set and create is true, a name is generated using the fullname template 56 | name: "" 57 | 58 | podAnnotations: {} 59 | 60 | podSecurityContext: {} 61 | # fsGroup: 2000 62 | 63 | securityContext: {} 64 | # capabilities: 65 | # drop: 66 | # - ALL 67 | # readOnlyRootFilesystem: true 68 | # runAsNonRoot: true 69 | # runAsUser: 1000 70 | 71 | 72 | 73 | ingress: 74 | enabled: false 75 | annotations: {} 76 | # kubernetes.io/ingress.class: nginx 77 | # kubernetes.io/tls-acme: "true" 78 | hosts: 79 | - host: chart-example.local 80 | paths: [] 81 | tls: [] 82 | # - secretName: chart-example-tls 83 | # hosts: 84 | # - chart-example.local 85 | 86 | 87 | 88 | # We usually recommend not to specify default resources and to leave this as a conscious 89 | # choice for the user. This also increases chances charts run on environments with little 90 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 91 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 92 | # limits: 93 | # cpu: 100m 94 | # memory: 128Mi 95 | # requests: 96 | # cpu: 100m 97 | # memory: 128Mi 98 | 99 | autoscaling: 100 | enabled: false 101 | minReplicas: 1 102 | maxReplicas: 100 103 | targetCPUUtilizationPercentage: 80 104 | # targetMemoryUtilizationPercentage: 80 105 | 106 | nodeSelector: {} 107 | 108 | tolerations: [] 109 | 110 | affinity: {} 111 | -------------------------------------------------------------------------------- /helms/helm-install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ################### 配置信息begin ################### 3 | project_git_url=https://github.com/puhaiyang/spring-boot-cloud.git 4 | #docker镜像仓库地址 5 | image_domain=ccr.ccs.tencentyun.com/spring-boot-cloud 6 | #项目名称 7 | project_name=spring-boot-cloud 8 | #所有项目的git根目录 9 | git_root_path=~/git 10 | #项目的根目录 11 | project_root_path=~/git/$project_name 12 | #通用chart目录 13 | chart_root_path=$project_root_path/helms 14 | #版本号,docker的tag 15 | version=`date +%Y%m%d%H%M` 16 | #部署的namespace 17 | deploy_namespace="default" 18 | #钉钉机器人的token 19 | ding_robot_token="xxxxxxxxxxx" 20 | ################### 配置信息end ################### 21 | ########################初始化 begin########################### 22 | #不存在项目目录的话,则先进行初始化 23 | if [ ! -d $git_root_path ];then 24 | echo '不存项目目录,先进行初始化' 25 | mkdir $git_root_path 26 | cd $git_root_path 27 | git clone $project_git_url 28 | fi 29 | ########################初始化 end########################### 30 | source /etc/profile 31 | #自定义分支名 32 | if [ -z "$1" ]; then 33 | #默认分支名称 34 | branch=master 35 | else 36 | branch=$1 37 | fi 38 | 39 | echo '----------------------------------------------' 40 | echo ':-D hi,boy!welcome to automatic depoly sh! :-D' 41 | echo '----------------------------------------------' 42 | 43 | echo -e "branch:$branch, 系统服务列表:" 44 | ################################列目录 begin############################ 45 | pom_files=$(dirname $(find git/spring-boot-cloud/ -name pom.xml)) 46 | igrone_pro="spring-boot-cloud" 47 | index=0 48 | projects[0]="unknown" 49 | for i in ${pom_files[@]};do 50 | pro_name=$(basename $i) 51 | if [ "$pro_name" = "$igrone_pro" ]; then 52 | continue 53 | fi 54 | ((index++)) 55 | echo $index')'$pro_name 56 | projects[${#projects[*]}]="$pro_name" 57 | done 58 | echo -e "请输入模块对应的序号:" 59 | read project_index 60 | echo ${projects[$project_index]} 61 | #要发布的项目名 62 | pname=${projects[$project_index]} 63 | ################################列目录 end############################ 64 | echo "更新的模块:$pname" 65 | #模块的目录 66 | git=$project_root_path/$pname 67 | #切换到项目的目录 68 | cd $git 69 | #获取到新的代码 70 | git fetch --all 71 | git reset --hard origin/$branch 72 | #获取到最后一次提交的内容 73 | git_last_commit=$(git show -s --format=%s) 74 | #获取到最后一次提交者 75 | git_last_commit_author=$(git show -s --format=%an) 76 | #如果项目是maven聚合项目,需要在git的根目录进打包,-pl --projects 构建制定的模块,模块间用逗号分隔 77 | #-am --also-make 同时构建所列模块的依赖模块; 78 | cd $project_root_path 79 | echo '下面开始打包(package)...' 80 | mvn clean package -Dmaven.test.skip=true -pl $pname -am 81 | #mvn clean package -Dmaven.test.skip=true 82 | echo '好,包打好了!接下来准备打镜像!(docker image package)...' 83 | cd $git 84 | #docker镜像名 85 | docker_image=$image_domain/$pname 86 | #docker镜像名 87 | image=$docker_image:$version 88 | echo '现在开始打镜像...' 89 | docker build -f Dockerfile -t $image . 90 | echo '打好了,把镜像推到docker镜像仓库里去(push...)' 91 | docker push $image 92 | 93 | echo '好!现在准备发布更新了(pre deploy...)' 94 | echo '现在准备chart文件,通过通用chart文件来生成' 95 | path_common_chart=$chart_root_path/common-modle-springbootcloud 96 | echo $path_common_chart 97 | #在项目的target目录下创建chart目录 98 | mkdir chart 99 | echo '复制到target下的chart目录下' 100 | cp -r $path_common_chart chart 101 | #重命名 102 | mv chart/common-modle-springbootcloud chart/$pname 103 | echo '替换chart' 104 | sed -i "s/common-modle-springbootcloud/$pname/g" chart/$pname/Chart.yaml 105 | echo '替换values' 106 | sed -i "s/common-modle-springbootcloud/$pname/g" chart/$pname/values.yaml 107 | 108 | #install or upgrade 109 | ###############判断是否已发布对应的项目 begin##################### 110 | helm_ops='install' 111 | helm list -A |grep $pname 112 | if [ $? -ne 0 ];then 113 | echo "不存在"$pname"模块,将先进行install" 114 | helm_ops="install" 115 | else 116 | echo "已存在"$pname"模块,将先进行upgrade" 117 | helm_ops="upgrade" 118 | fi 119 | ###############判断是否已发布对应的项目 end##################### 120 | 121 | echo '进行发布(deploy...)' 122 | if [ -f "$chart_root_path/values/$pname/values.yaml" ];then 123 | echo '已经有配置文件了,采用配置文件进行发布' 124 | helm $helm_ops $pname chart/$pname -n $deploy_namespace -f $chart_root_path/values/$pname/values.yaml --set image.tag=$version --set image.repository=$docker_image 125 | else 126 | echo '直接进行发布' 127 | helm $helm_ops $pname chart/$pname -n $deploy_namespace --set image.tag=$version --set image.repository=$docker_image 128 | fi 129 | 130 | Message="发布通知: \n模块:${pname} \ngit提交者:$git_last_commit_author \ngit提交内容:$git_last_commit \n------have a nice day------" 131 | 132 | curl "https://oapi.dingtalk.com/robot/send?access_token=$ding_robot_token" \ 133 | -H 'Content-Type: application/json' \ 134 | -d " {\"msgtype\": \"text\", 135 | \"text\": {\"content\": \"$Message\"}}" 136 | -------------------------------------------------------------------------------- /helms/values/auth-service/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/auth-service 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 5000 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 5000 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /helms/values/config/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/config 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 8888 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 8888 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /helms/values/gateway/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/gateway 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 8060 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 8060 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /helms/values/monitor/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/monitor 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 8040 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 8040 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /helms/values/registry/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/registry 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 8761 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 8761 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /helms/values/svca-service/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/svca-service 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 8080 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 8080 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /helms/values/svcb-service/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/svcb-service 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 8070 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 8070 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /helms/values/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/registry 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 8761 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 8761 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /helms/values/zipkin/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for registry. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | #----------- skywalking agent config begin ------- 8 | skywalkingAgent: 9 | enabled: true 10 | image: 11 | repository: ccr.ccs.tencentyun.com/haiyang/skywalking-agent 12 | tag: 7.0.0 13 | #----------- skywalking agent config end ------- 14 | 15 | image: 16 | repository: ccr.ccs.tencentyun.com/spring-boot-cloud/zipkin 17 | pullPolicy: Always 18 | # Overrides the image tag whose default is the chart version. 19 | tag: "latest" 20 | containerPort: 9411 21 | 22 | imagePullSecrets: [] 23 | nameOverride: "" 24 | fullnameOverride: "" 25 | 26 | serviceAccount: 27 | # Specifies whether a service account should be created 28 | create: false 29 | # Annotations to add to the service account 30 | annotations: {} 31 | # The name of the service account to use. 32 | # If not set and create is true, a name is generated using the fullname template 33 | name: "" 34 | 35 | podAnnotations: {} 36 | 37 | podSecurityContext: {} 38 | # fsGroup: 2000 39 | 40 | securityContext: {} 41 | # capabilities: 42 | # drop: 43 | # - ALL 44 | # readOnlyRootFilesystem: true 45 | # runAsNonRoot: true 46 | # runAsUser: 1000 47 | 48 | service: 49 | type: ClusterIP 50 | port: 9411 51 | 52 | ingress: 53 | enabled: false 54 | annotations: {} 55 | # kubernetes.io/ingress.class: nginx 56 | # kubernetes.io/tls-acme: "true" 57 | hosts: 58 | - host: chart-example.local 59 | paths: [] 60 | tls: [] 61 | # - secretName: chart-example-tls 62 | # hosts: 63 | # - chart-example.local 64 | 65 | resources: {} 66 | # We usually recommend not to specify default resources and to leave this as a conscious 67 | # choice for the user. This also increases chances charts run on environments with little 68 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 69 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 70 | # limits: 71 | # cpu: 100m 72 | # memory: 128Mi 73 | # requests: 74 | # cpu: 100m 75 | # memory: 128Mi 76 | 77 | autoscaling: 78 | enabled: false 79 | minReplicas: 1 80 | maxReplicas: 100 81 | targetCPUUtilizationPercentage: 80 82 | # targetMemoryUtilizationPercentage: 80 83 | 84 | nodeSelector: {} 85 | 86 | tolerations: [] 87 | 88 | affinity: {} 89 | -------------------------------------------------------------------------------- /istio.yaml: -------------------------------------------------------------------------------- 1 | #-------------config----------------- 2 | --- 3 | apiVersion: apps/v1 4 | kind: Deployment 5 | metadata: 6 | name: config 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: config 12 | strategy: 13 | rollingUpdate: 14 | maxSurge: 1 15 | maxUnavailable: 0 16 | type: RollingUpdate 17 | template: 18 | metadata: 19 | labels: 20 | app: config 21 | spec: 22 | containers: 23 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/config:v3 24 | imagePullPolicy: Always 25 | name: config 26 | ports: 27 | - containerPort: 30876 28 | protocol: TCP 29 | --- 30 | apiVersion: v1 31 | kind: Service 32 | metadata: 33 | name: config 34 | spec: 35 | ports: 36 | - name: http 37 | port: 30876 38 | protocol: TCP 39 | targetPort: 30876 40 | selector: 41 | app: config 42 | #-------------svca-service----------------- 43 | --- 44 | apiVersion: apps/v1 45 | kind: Deployment 46 | metadata: 47 | name: svca-service 48 | spec: 49 | replicas: 1 50 | selector: 51 | matchLabels: 52 | app: svca-service 53 | strategy: 54 | rollingUpdate: 55 | maxSurge: 1 56 | maxUnavailable: 0 57 | type: RollingUpdate 58 | template: 59 | metadata: 60 | labels: 61 | app: svca-service 62 | spec: 63 | containers: 64 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/svca-service:v3 65 | imagePullPolicy: Always 66 | name: svca-service 67 | ports: 68 | - containerPort: 8080 69 | protocol: TCP 70 | --- 71 | apiVersion: v1 72 | kind: Service 73 | metadata: 74 | name: svca-service 75 | spec: 76 | ports: 77 | - name: http 78 | port: 8080 79 | protocol: TCP 80 | targetPort: 8080 81 | selector: 82 | app: svca-service 83 | #-------------svcb-service----------------- 84 | --- 85 | apiVersion: apps/v1 86 | kind: Deployment 87 | metadata: 88 | name: svcb-service 89 | spec: 90 | replicas: 1 91 | selector: 92 | matchLabels: 93 | app: svcb-service 94 | strategy: 95 | rollingUpdate: 96 | maxSurge: 1 97 | maxUnavailable: 0 98 | type: RollingUpdate 99 | template: 100 | metadata: 101 | labels: 102 | app: svcb-service 103 | spec: 104 | containers: 105 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/svcb-service:v3 106 | imagePullPolicy: Always 107 | name: svcb-service 108 | ports: 109 | - containerPort: 8070 110 | protocol: TCP 111 | --- 112 | apiVersion: v1 113 | kind: Service 114 | metadata: 115 | name: svcb-service 116 | spec: 117 | ports: 118 | - name: http 119 | port: 8070 120 | protocol: TCP 121 | targetPort: 8070 122 | selector: 123 | app: svcb-service 124 | #-------------gateway----------------- 125 | --- 126 | apiVersion: apps/v1 127 | kind: Deployment 128 | metadata: 129 | name: gateway 130 | spec: 131 | replicas: 1 132 | selector: 133 | matchLabels: 134 | app: gateway 135 | strategy: 136 | rollingUpdate: 137 | maxSurge: 1 138 | maxUnavailable: 0 139 | type: RollingUpdate 140 | template: 141 | metadata: 142 | labels: 143 | app: gateway 144 | spec: 145 | containers: 146 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/gateway:v3 147 | imagePullPolicy: Always 148 | name: gateway 149 | ports: 150 | - containerPort: 8060 151 | protocol: TCP 152 | --- 153 | apiVersion: v1 154 | kind: Service 155 | metadata: 156 | name: gateway 157 | spec: 158 | ports: 159 | - name: http 160 | port: 8060 161 | protocol: TCP 162 | targetPort: 8060 163 | selector: 164 | app: gateway 165 | --- -------------------------------------------------------------------------------- /k8s.yaml: -------------------------------------------------------------------------------- 1 | #-------------registry----------------- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: registry 6 | spec: 7 | replicas: 1 8 | selector: 9 | matchLabels: 10 | app: registry 11 | strategy: 12 | rollingUpdate: 13 | maxSurge: 1 14 | maxUnavailable: 0 15 | type: RollingUpdate 16 | template: 17 | metadata: 18 | labels: 19 | app: registry 20 | spec: 21 | initContainers: 22 | - name: init-skywalking-agent 23 | image: apache/skywalking-java-agent:8.12.0-java8 24 | command: 25 | - 'sh' 26 | - '-c' 27 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 28 | volumeMounts: 29 | - mountPath: /vmskywalking/agent 30 | name: skywalking-agent 31 | containers: 32 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/registry:latest 33 | imagePullPolicy: Always 34 | name: registry 35 | ports: 36 | - containerPort: 8761 37 | protocol: TCP 38 | volumeMounts: 39 | - mountPath: /opt/skywalking/agent 40 | name: skywalking-agent 41 | volumes: 42 | - name: skywalking-agent 43 | emptyDir: {} 44 | --- 45 | apiVersion: v1 46 | kind: Service 47 | metadata: 48 | name: registry 49 | spec: 50 | ports: 51 | - name: http 52 | port: 8761 53 | protocol: TCP 54 | targetPort: 8761 55 | selector: 56 | app: registry 57 | --- 58 | apiVersion: extensions/v1beta1 59 | kind: Ingress 60 | metadata: 61 | name: registry-nginx 62 | spec: 63 | rules: 64 | - host: registry.springcloud.com 65 | http: 66 | paths: 67 | - backend: 68 | serviceName: registry 69 | servicePort: 8761 70 | #-------------config----------------- 71 | --- 72 | apiVersion: apps/v1 73 | kind: Deployment 74 | metadata: 75 | name: config 76 | spec: 77 | replicas: 1 78 | selector: 79 | matchLabels: 80 | app: config 81 | strategy: 82 | rollingUpdate: 83 | maxSurge: 1 84 | maxUnavailable: 0 85 | type: RollingUpdate 86 | template: 87 | metadata: 88 | labels: 89 | app: config 90 | spec: 91 | initContainers: 92 | - name: init-skywalking-agent 93 | image: apache/skywalking-java-agent:8.12.0-java8 94 | command: 95 | - 'sh' 96 | - '-c' 97 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 98 | volumeMounts: 99 | - mountPath: /vmskywalking/agent 100 | name: skywalking-agent 101 | containers: 102 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/config:latest 103 | imagePullPolicy: Always 104 | name: config 105 | ports: 106 | - containerPort: 8888 107 | protocol: TCP 108 | volumeMounts: 109 | - mountPath: /opt/skywalking/agent 110 | name: skywalking-agent 111 | volumes: 112 | - name: skywalking-agent 113 | emptyDir: {} 114 | --- 115 | apiVersion: v1 116 | kind: Service 117 | metadata: 118 | name: config 119 | spec: 120 | ports: 121 | - name: http 122 | port: 8888 123 | protocol: TCP 124 | targetPort: 8888 125 | selector: 126 | app: config 127 | #-------------svca-service----------------- 128 | --- 129 | apiVersion: apps/v1 130 | kind: Deployment 131 | metadata: 132 | name: svca-service 133 | spec: 134 | replicas: 1 135 | selector: 136 | matchLabels: 137 | app: svca-service 138 | strategy: 139 | rollingUpdate: 140 | maxSurge: 1 141 | maxUnavailable: 0 142 | type: RollingUpdate 143 | template: 144 | metadata: 145 | labels: 146 | app: svca-service 147 | spec: 148 | initContainers: 149 | - name: init-skywalking-agent 150 | image: apache/skywalking-java-agent:8.12.0-java8 151 | command: 152 | - 'sh' 153 | - '-c' 154 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 155 | volumeMounts: 156 | - mountPath: /vmskywalking/agent 157 | name: skywalking-agent 158 | containers: 159 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/svca-service:latest 160 | imagePullPolicy: Always 161 | name: svca-service 162 | ports: 163 | - containerPort: 8080 164 | protocol: TCP 165 | volumeMounts: 166 | - mountPath: /opt/skywalking/agent 167 | name: skywalking-agent 168 | volumes: 169 | - name: skywalking-agent 170 | emptyDir: {} 171 | --- 172 | apiVersion: v1 173 | kind: Service 174 | metadata: 175 | name: svca-service 176 | spec: 177 | ports: 178 | - name: http 179 | port: 8080 180 | protocol: TCP 181 | targetPort: 8080 182 | selector: 183 | app: svca-service 184 | #-------------svcb-service----------------- 185 | --- 186 | apiVersion: apps/v1 187 | kind: Deployment 188 | metadata: 189 | name: svcb-service 190 | spec: 191 | replicas: 1 192 | selector: 193 | matchLabels: 194 | app: svcb-service 195 | strategy: 196 | rollingUpdate: 197 | maxSurge: 1 198 | maxUnavailable: 0 199 | type: RollingUpdate 200 | template: 201 | metadata: 202 | labels: 203 | app: svcb-service 204 | spec: 205 | initContainers: 206 | - name: init-skywalking-agent 207 | image: apache/skywalking-java-agent:8.12.0-java8 208 | command: 209 | - 'sh' 210 | - '-c' 211 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 212 | volumeMounts: 213 | - mountPath: /vmskywalking/agent 214 | name: skywalking-agent 215 | containers: 216 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/svcb-service:latest 217 | imagePullPolicy: Always 218 | name: svcb-service 219 | ports: 220 | - containerPort: 8070 221 | protocol: TCP 222 | volumeMounts: 223 | - mountPath: /opt/skywalking/agent 224 | name: skywalking-agent 225 | volumes: 226 | - name: skywalking-agent 227 | emptyDir: {} 228 | --- 229 | apiVersion: v1 230 | kind: Service 231 | metadata: 232 | name: svcb-service 233 | spec: 234 | ports: 235 | - name: http 236 | port: 8070 237 | protocol: TCP 238 | targetPort: 8070 239 | selector: 240 | app: svcb-service 241 | #-------------auth-service----------------- 242 | --- 243 | apiVersion: apps/v1 244 | kind: Deployment 245 | metadata: 246 | name: auth-service 247 | spec: 248 | replicas: 1 249 | selector: 250 | matchLabels: 251 | app: auth-service 252 | strategy: 253 | rollingUpdate: 254 | maxSurge: 1 255 | maxUnavailable: 0 256 | type: RollingUpdate 257 | template: 258 | metadata: 259 | labels: 260 | app: auth-service 261 | spec: 262 | initContainers: 263 | - name: init-skywalking-agent 264 | image: apache/skywalking-java-agent:8.12.0-java8 265 | command: 266 | - 'sh' 267 | - '-c' 268 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 269 | volumeMounts: 270 | - mountPath: /vmskywalking/agent 271 | name: skywalking-agent 272 | containers: 273 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/auth-service:latest 274 | imagePullPolicy: Always 275 | name: auth-service 276 | ports: 277 | - containerPort: 5000 278 | protocol: TCP 279 | volumeMounts: 280 | - mountPath: /opt/skywalking/agent 281 | name: skywalking-agent 282 | volumes: 283 | - name: skywalking-agent 284 | emptyDir: {} 285 | --- 286 | apiVersion: v1 287 | kind: Service 288 | metadata: 289 | name: auth-service 290 | spec: 291 | ports: 292 | - name: http 293 | port: 5000 294 | protocol: TCP 295 | targetPort: 5000 296 | selector: 297 | app: auth-service 298 | #-------------gateway----------------- 299 | --- 300 | apiVersion: apps/v1 301 | kind: Deployment 302 | metadata: 303 | name: gateway 304 | spec: 305 | replicas: 1 306 | selector: 307 | matchLabels: 308 | app: gateway 309 | strategy: 310 | rollingUpdate: 311 | maxSurge: 1 312 | maxUnavailable: 0 313 | type: RollingUpdate 314 | template: 315 | metadata: 316 | labels: 317 | app: gateway 318 | spec: 319 | initContainers: 320 | - name: init-skywalking-agent 321 | image: apache/skywalking-java-agent:8.12.0-java8 322 | command: 323 | - 'sh' 324 | - '-c' 325 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 326 | volumeMounts: 327 | - mountPath: /vmskywalking/agent 328 | name: skywalking-agent 329 | containers: 330 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/gateway:latest 331 | imagePullPolicy: Always 332 | name: gateway 333 | ports: 334 | - containerPort: 8060 335 | protocol: TCP 336 | env: 337 | - name: SKYWALKING_ADDR 338 | value: skywalking-oap-server 339 | - name: APP_ID 340 | value: gateway 341 | volumeMounts: 342 | - mountPath: /opt/skywalking/agent 343 | name: skywalking-agent 344 | volumes: 345 | - name: skywalking-agent 346 | emptyDir: {} 347 | --- 348 | apiVersion: v1 349 | kind: Service 350 | metadata: 351 | name: gateway 352 | spec: 353 | ports: 354 | - name: http 355 | port: 8060 356 | protocol: TCP 357 | targetPort: 8060 358 | selector: 359 | app: gateway 360 | --- 361 | apiVersion: extensions/v1beta1 362 | kind: Ingress 363 | metadata: 364 | name: gateway 365 | spec: 366 | rules: 367 | - host: gateway.springcloud.com 368 | http: 369 | paths: 370 | - backend: 371 | serviceName: gateway 372 | servicePort: 8060 373 | #-------------zipkin----------------- 374 | --- 375 | apiVersion: apps/v1 376 | kind: Deployment 377 | metadata: 378 | name: zipkin 379 | spec: 380 | replicas: 1 381 | selector: 382 | matchLabels: 383 | app: zipkin 384 | strategy: 385 | rollingUpdate: 386 | maxSurge: 1 387 | maxUnavailable: 0 388 | type: RollingUpdate 389 | template: 390 | metadata: 391 | labels: 392 | app: zipkin 393 | spec: 394 | initContainers: 395 | - name: init-skywalking-agent 396 | image: apache/skywalking-java-agent:8.12.0-java8 397 | command: 398 | - 'sh' 399 | - '-c' 400 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 401 | volumeMounts: 402 | - mountPath: /vmskywalking/agent 403 | name: skywalking-agent 404 | containers: 405 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/zipkin:latest 406 | imagePullPolicy: Always 407 | name: zipkin-server 408 | ports: 409 | - containerPort: 9411 410 | protocol: TCP 411 | env: 412 | - name: SKYWALKING_ADDR 413 | value: skywalking-oap-server 414 | - name: APP_ID 415 | value: zipkin-server 416 | volumeMounts: 417 | - mountPath: /opt/skywalking/agent 418 | name: skywalking-agent 419 | volumes: 420 | - name: skywalking-agent 421 | emptyDir: {} 422 | 423 | --- 424 | apiVersion: v1 425 | kind: Service 426 | metadata: 427 | name: zipkin 428 | spec: 429 | ports: 430 | - name: http 431 | port: 9411 432 | protocol: TCP 433 | targetPort: 9411 434 | selector: 435 | app: zipkin 436 | --- 437 | apiVersion: extensions/v1beta1 438 | kind: Ingress 439 | metadata: 440 | name: zipkin-nginx 441 | spec: 442 | rules: 443 | - host: zipkin.springcloud.com 444 | http: 445 | paths: 446 | - backend: 447 | serviceName: zipkin 448 | servicePort: 9411 449 | #-------------monitor----------------- 450 | --- 451 | apiVersion: apps/v1 452 | kind: Deployment 453 | metadata: 454 | name: monitor 455 | spec: 456 | replicas: 1 457 | selector: 458 | matchLabels: 459 | app: monitor 460 | strategy: 461 | rollingUpdate: 462 | maxSurge: 1 463 | maxUnavailable: 0 464 | type: RollingUpdate 465 | template: 466 | metadata: 467 | labels: 468 | app: monitor 469 | spec: 470 | initContainers: 471 | - name: init-skywalking-agent 472 | image: apache/skywalking-java-agent:8.12.0-java8 473 | command: 474 | - 'sh' 475 | - '-c' 476 | - 'set -ex;mkdir -p /vmskywalking/agent;cp -r /skywalking/agent/* /vmskywalking/agent;' 477 | volumeMounts: 478 | - mountPath: /vmskywalking/agent 479 | name: skywalking-agent 480 | containers: 481 | - image: ccr.ccs.tencentyun.com/spring-boot-cloud/monitor:latest 482 | imagePullPolicy: Always 483 | name: config 484 | ports: 485 | - containerPort: 8040 486 | protocol: TCP 487 | volumeMounts: 488 | - mountPath: /opt/skywalking/agent 489 | name: skywalking-agent 490 | volumes: 491 | - name: skywalking-agent 492 | emptyDir: {} 493 | --- 494 | apiVersion: v1 495 | kind: Service 496 | metadata: 497 | name: monitor 498 | spec: 499 | ports: 500 | - name: http 501 | port: 8040 502 | protocol: TCP 503 | targetPort: 8040 504 | selector: 505 | app: monitor 506 | --- 507 | apiVersion: extensions/v1beta1 508 | kind: Ingress 509 | metadata: 510 | name: monitor-nginx 511 | spec: 512 | rules: 513 | - host: monitor.springcloud.com 514 | http: 515 | paths: 516 | - backend: 517 | serviceName: monitor 518 | servicePort: 8040 -------------------------------------------------------------------------------- /monitor/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD ./target/monitor.jar /app.jar 4 | RUN bash -c 'touch /app.jar' 5 | RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone 6 | EXPOSE 8040 8041 7 | ENTRYPOINT ["java","-Dapp.id=monitor","-javaagent:/opt/skywalking/agent/skywalking-agent.jar","-Dskywalking.agent.service_name=monitor","-Dskywalking.collector.backend_service=skywalking-oap-server:11800","-jar","-Djava.security.egd=file:/dev/./urandom","/app.jar"] -------------------------------------------------------------------------------- /monitor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | cn.zhangxd 9 | spring-boot-cloud 10 | 1.0-SNAPSHOT 11 | 12 | 13 | monitor 14 | 1.0-SNAPSHOT 15 | jar 16 | ${project.artifactId} 17 | 18 | 19 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-stream-rabbit 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-starter-netflix-eureka-server 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-security 50 | 51 | 52 | 53 | 54 | ${project.artifactId} 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /monitor/src/main/java/cn/zhangxd/monitor/MonitorApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.monitor; 2 | 3 | //import de.codecentric.boot.admin.config.EnableAdminServer; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 10 | 11 | @SpringBootApplication 12 | @EnableDiscoveryClient 13 | //@EnableAdminServer 14 | public class MonitorApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(MonitorApplication.class, args); 18 | } 19 | 20 | @Configuration 21 | public static class SecurityConfig extends WebSecurityConfigurerAdapter { 22 | @Override 23 | protected void configure(HttpSecurity http) throws Exception { 24 | // Page with login form is served as /login.html and does a POST on /login 25 | http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll(); 26 | // The UI does a POST on /logout on logout 27 | http.logout().logoutUrl("/logout"); 28 | // The ui currently doesn't support csrf 29 | http.csrf().disable(); 30 | 31 | // Requests for the login page and the static assets are allowed 32 | http.authorizeRequests() 33 | .antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**") 34 | .permitAll(); 35 | // ... and any other request needs to be authorized 36 | http.authorizeRequests().antMatchers("/**").authenticated(); 37 | 38 | // Enable so that the clients can authenticate via HTTP basic for registering 39 | http.httpBasic(); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /monitor/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter: error 4 | 5 | server: 6 | port: 8040 7 | 8 | turbine: 9 | stream: 10 | port: 8041 11 | 12 | eureka: 13 | instance: 14 | hostname: registry 15 | prefer-ip-address: true 16 | metadata-map: 17 | user.name: ${security.user.name} 18 | user.password: ${security.user.password} 19 | client: 20 | service-url: 21 | defaultZone: http://user:${REGISTRY_SERVER_PASSWORD:password}@registry:8761/eureka/ 22 | 23 | spring: 24 | rabbitmq: 25 | host: rabbitmq 26 | port: 30672 27 | username: user 28 | password: bitnami 29 | boot: 30 | admin: 31 | routes: 32 | endpoints: env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream 33 | turbine: 34 | clusters: default 35 | location: http://monitor:${turbine.stream.port} 36 | 37 | security: 38 | user: 39 | name: admin 40 | password: ${MONITOR_SERVER_PASSWORD:admin} -------------------------------------------------------------------------------- /monitor/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: monitor -------------------------------------------------------------------------------- /monitor/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | cn.zhangxd 8 | spring-boot-cloud 9 | 1.0-SNAPSHOT 10 | pom 11 | ${project.artifactId} 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 2.6.1 17 | 18 | 19 | 20 | 21 | config 22 | gateway 23 | monitor 24 | svca-service 25 | svcb-service 26 | 27 | 28 | 29 | UTF-8 30 | 1.8 31 | spring-boot-cloud 32 | 2021.0.4 33 | 1.5.4 34 | 4.4.1 35 | 8.12.0 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-actuator 42 | 43 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | org.projectlombok 54 | lombok 55 | 1.18.24 56 | provided 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.cloud 64 | spring-cloud-dependencies 65 | ${spring.cloud.version} 66 | pom 67 | import 68 | 69 | 70 | org.springdoc 71 | springdoc-openapi-ui 72 | 1.6.11 73 | 74 | 75 | org.springdoc 76 | springdoc-openapi-webflux-ui 77 | 1.6.11 78 | 79 | 80 | org.apache.skywalking 81 | apm-toolkit-trace 82 | ${skywalking.version} 83 | 84 | 85 | org.apache.skywalking 86 | apm-toolkit-logback-1.x 87 | ${skywalking.version} 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | org.springframework.boot 99 | spring-boot-maven-plugin 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /rabbitmq.yaml: -------------------------------------------------------------------------------- 1 | #-------------定义RabbitMQ部署----------------- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: rabbit 6 | spec: 7 | replicas: 1 8 | selector: 9 | matchLabels: 10 | app: rabbit 11 | strategy: 12 | rollingUpdate: 13 | maxSurge: 25% 14 | maxUnavailable: 25% 15 | type: RollingUpdate 16 | template: 17 | metadata: 18 | labels: 19 | app: rabbit 20 | spec: 21 | containers: 22 | - image: bitnami/rabbitmq:latest 23 | imagePullPolicy: IfNotPresent 24 | name: rabbit 25 | ports: 26 | - containerPort: 15672 27 | name: rabbit15672 28 | protocol: TCP 29 | - containerPort: 5672 30 | name: rabbit5672 31 | protocol: TCP 32 | --- 33 | #-----------------定义rabbit的代理服务,serviceName一定要和代码中的一致----------- 34 | apiVersion: v1 35 | kind: Service 36 | metadata: 37 | name: rabbitmq 38 | spec: 39 | ports: 40 | - name: rabbit32672 41 | nodePort: 32672 42 | port: 32672 43 | protocol: TCP 44 | targetPort: 15672 45 | - name: rabbit30672 46 | nodePort: 30672 47 | port: 30672 48 | protocol: TCP 49 | targetPort: 5672 50 | selector: 51 | app: rabbit 52 | type: NodePort 53 | -------------------------------------------------------------------------------- /registry/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD ./target/registry.jar /app.jar 4 | RUN bash -c 'touch /app.jar' 5 | RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone 6 | EXPOSE 8761 7 | ENTRYPOINT ["java","-Dapp.id=registry","-javaagent:/opt/skywalking/agent/skywalking-agent.jar","-Dskywalking.agent.service_name=registry","-Dskywalking.collector.backend_service=skywalking-oap-server:11800","-jar","-Djava.security.egd=file:/dev/./urandom","/app.jar"] -------------------------------------------------------------------------------- /registry/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | cn.zhangxd 9 | spring-boot-cloud 10 | 1.0-SNAPSHOT 11 | 12 | 13 | registry 14 | 1.0-SNAPSHOT 15 | jar 16 | ${project.artifactId} 17 | 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-eureka-server 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-security 26 | 27 | 28 | 29 | 30 | ${project.artifactId} 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-maven-plugin 35 | 36 | 37 | io.fabric8 38 | docker-maven-plugin 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /registry/src/main/java/cn/zhangxd/registry/RegistryApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.registry; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class RegistryApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(RegistryApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /registry/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | instance: 6 | hostname: registry 7 | prefer-ip-address: true 8 | client: 9 | registerWithEureka: false 10 | fetchRegistry: false 11 | service-url: 12 | defaultZone: http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/ 13 | 14 | security: 15 | user: 16 | name: user 17 | password: ${REGISTRY_SERVER_PASSWORD:password} 18 | -------------------------------------------------------------------------------- /registry/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: registry -------------------------------------------------------------------------------- /registry/src/test/java/cn/zhangxd/registry/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.registry; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.boot.test.web.client.TestRestTemplate; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import java.util.Map; 14 | 15 | import static org.junit.Assert.assertEquals; 16 | import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @SpringBootTest(webEnvironment = RANDOM_PORT) 20 | public class ApplicationTests { 21 | 22 | @Autowired 23 | private TestRestTemplate testRestTemplate; 24 | @Value("${security.user.name}") 25 | private String username; 26 | @Value("${security.user.password}") 27 | private String password; 28 | 29 | @Test 30 | public void catalogLoads() { 31 | @SuppressWarnings("rawtypes") 32 | ResponseEntity entity = 33 | testRestTemplate 34 | .withBasicAuth(username, password) 35 | .getForEntity("/eureka/apps", Map.class); 36 | assertEquals(HttpStatus.OK, entity.getStatusCode()); 37 | } 38 | 39 | @Test 40 | public void adminLoads() { 41 | @SuppressWarnings("rawtypes") 42 | ResponseEntity entity = 43 | testRestTemplate 44 | .withBasicAuth(username, password) 45 | .getForEntity("/env", Map.class); 46 | assertEquals(HttpStatus.OK, entity.getStatusCode()); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /screenshots/architecture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/architecture.jpg -------------------------------------------------------------------------------- /screenshots/components.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/components.jpg -------------------------------------------------------------------------------- /screenshots/monitor1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor1.jpg -------------------------------------------------------------------------------- /screenshots/monitor10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor10.jpg -------------------------------------------------------------------------------- /screenshots/monitor11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor11.jpg -------------------------------------------------------------------------------- /screenshots/monitor12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor12.jpg -------------------------------------------------------------------------------- /screenshots/monitor2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor2.jpg -------------------------------------------------------------------------------- /screenshots/monitor3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor3.jpg -------------------------------------------------------------------------------- /screenshots/monitor4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor4.jpg -------------------------------------------------------------------------------- /screenshots/monitor5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor5.jpg -------------------------------------------------------------------------------- /screenshots/monitor6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor6.jpg -------------------------------------------------------------------------------- /screenshots/monitor7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor7.jpg -------------------------------------------------------------------------------- /screenshots/monitor8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor8.jpg -------------------------------------------------------------------------------- /screenshots/monitor9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/monitor9.jpg -------------------------------------------------------------------------------- /screenshots/rabbit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/rabbit.jpg -------------------------------------------------------------------------------- /screenshots/registry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/registry.jpg -------------------------------------------------------------------------------- /screenshots/springCloud-skywalking1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/springCloud-skywalking1.png -------------------------------------------------------------------------------- /screenshots/springCloud-skywalking2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/springCloud-skywalking2.png -------------------------------------------------------------------------------- /screenshots/zipkin1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/zipkin1.jpg -------------------------------------------------------------------------------- /screenshots/zipkin2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/zipkin2.jpg -------------------------------------------------------------------------------- /screenshots/zipkin3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puhaiyang/spring-boot-cloud/0344ca2cffeed1be3470a167d1ac5cfd97300336/screenshots/zipkin3.jpg -------------------------------------------------------------------------------- /skywalking-oap-server-with-h2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: skywalking-oap-server 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: skywalking-oap-server 10 | template: 11 | metadata: 12 | labels: 13 | app: skywalking-oap-server 14 | spec: 15 | containers: 16 | - image: apache/skywalking-oap-server:9.2.0 17 | imagePullPolicy: IfNotPresent 18 | name: skywalking-oap-server 19 | ports: 20 | - containerPort: 11800 21 | name: grpc 22 | - containerPort: 12800 23 | name: rest 24 | env: 25 | - name: TZ 26 | value: Asia/Shanghai 27 | --- 28 | #-----------------定义skywalking的代理服务-------------- 29 | apiVersion: v1 30 | kind: Service 31 | metadata: 32 | name: skywalking-oap-server 33 | spec: 34 | ports: 35 | - name: grpcporst 36 | nodePort: 31800 37 | port: 11800 38 | protocol: TCP 39 | targetPort: 11800 40 | - name: restport 41 | nodePort: 32100 42 | port: 12800 43 | protocol: TCP 44 | targetPort: 12800 45 | selector: 46 | app: skywalking-oap-server 47 | type: NodePort -------------------------------------------------------------------------------- /skywalking-ui.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: skywalking-ui 5 | labels: 6 | app: skywalking-ui 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: skywalking-ui 12 | template: 13 | metadata: 14 | labels: 15 | app: skywalking-ui 16 | spec: 17 | containers: 18 | - name: skywalking-ui 19 | image: apache/skywalking-ui:9.2.0 20 | imagePullPolicy: Always 21 | ports: 22 | - containerPort: 8080 23 | name: httpport 24 | env: 25 | - name: SW_OAP_ADDRESS 26 | value: http://skywalking-oap-server:12800 27 | - name: TZ 28 | value: Asia/Shanghai 29 | --- 30 | #-----------------定义skywalking-ui的代理服务-------------- 31 | apiVersion: v1 32 | kind: Service 33 | metadata: 34 | name: skywalking-ui 35 | labels: 36 | service: skywalking-ui 37 | spec: 38 | ports: 39 | - port: 8080 40 | name: httpport 41 | targetPort: 8080 42 | nodePort: 31068 43 | type: NodePort 44 | selector: 45 | app: skywalking-ui 46 | --- 47 | #-----------------定义skywalking-ui的ingress-------------- 48 | apiVersion: extensions/v1beta1 49 | kind: Ingress 50 | metadata: 51 | name: skywalking-ui 52 | spec: 53 | rules: 54 | - host: skywalking-ui.springcloud.com 55 | http: 56 | paths: 57 | - backend: 58 | serviceName: skywalking-ui 59 | servicePort: 8080 -------------------------------------------------------------------------------- /svca-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD ./target/svca-service.jar /app.jar 4 | RUN bash -c 'touch /app.jar' 5 | RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone 6 | EXPOSE 8080 7 | ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","/app.jar"] -------------------------------------------------------------------------------- /svca-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | cn.zhangxd 9 | spring-boot-cloud 10 | 1.0-SNAPSHOT 11 | 12 | 13 | svca-service 14 | v3 15 | jar 16 | ${project.artifactId} 17 | 18 | 19 | 20 | 21 | 22 | org.springdoc 23 | springdoc-openapi-ui 24 | 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-kubernetes-fabric8 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-kubernetes-fabric8-loadbalancer 33 | 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-commons 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-web 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-starter-openfeign 50 | 51 | 52 | org.jolokia 53 | jolokia-core 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-starter-config 58 | 59 | 60 | org.springframework.cloud 61 | spring-cloud-starter-bootstrap 62 | 63 | 64 | org.apache.skywalking 65 | apm-toolkit-trace 66 | 67 | 68 | org.apache.skywalking 69 | apm-toolkit-logback-1.x 70 | 71 | 72 | 73 | 74 | ${project.artifactId} 75 | 76 | 77 | org.springframework.boot 78 | spring-boot-maven-plugin 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-deploy-plugin 83 | 84 | 85 | org.apache.maven.plugins 86 | maven-surefire-plugin 87 | 88 | 89 | io.fabric8 90 | fabric8-maven-plugin 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /svca-service/src/main/fabric8/service.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: svca-service 6 | spec: 7 | ports: 8 | - name: http 9 | port: 8080 10 | protocol: TCP 11 | targetPort: 8080 12 | selector: 13 | app: svca-service -------------------------------------------------------------------------------- /svca-service/src/main/java/cn/zhangxd/svca/ServiceAApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svca; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.openfeign.EnableFeignClients; 8 | 9 | 10 | @EnableDiscoveryClient 11 | @EnableFeignClients 12 | @SpringBootApplication 13 | public class ServiceAApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ServiceAApplication.class, args); 17 | } 18 | 19 | 20 | 21 | } -------------------------------------------------------------------------------- /svca-service/src/main/java/cn/zhangxd/svca/client/ServiceBClient.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svca.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | 9 | @FeignClient(name = "svcb-service",url = "${local.feign.server.svcb-service.url:}",fallback = ServiceBClient.ServiceBClientFallback.class) 10 | public interface ServiceBClient { 11 | 12 | @GetMapping(value = "/") 13 | String printServiceB(); 14 | 15 | @Component 16 | class ServiceBClientFallback implements ServiceBClient { 17 | 18 | private static final Logger LOGGER = LoggerFactory.getLogger(ServiceBClientFallback.class); 19 | 20 | @Override 21 | public String printServiceB() { 22 | LOGGER.info("异常发生,进入fallback方法"); 23 | return "SERVICE B FAILED! - FALLING BACK"; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /svca-service/src/main/java/cn/zhangxd/svca/config/CustomLoadBalancerConfiguration.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svca.config; 2 | 3 | import org.springframework.context.ConfigurableApplicationContext; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class CustomLoadBalancerConfiguration { 9 | 10 | // @Bean 11 | // public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier( 12 | // ConfigurableApplicationContext context) { 13 | // return ServiceInstanceListSupplier.builder() 14 | // .withDiscoveryClient() 15 | // .withHints() 16 | // .withCaching() 17 | // .build(context); 18 | // } 19 | } 20 | -------------------------------------------------------------------------------- /svca-service/src/main/java/cn/zhangxd/svca/config/SpringDocConfig.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svca.config; 2 | 3 | import io.swagger.v3.oas.models.ExternalDocumentation; 4 | import io.swagger.v3.oas.models.OpenAPI; 5 | import io.swagger.v3.oas.models.info.Info; 6 | import io.swagger.v3.oas.models.info.License; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | public class SpringDocConfig { 12 | 13 | @Bean 14 | public OpenAPI myOpenAPI() { 15 | return new OpenAPI() 16 | .info(new Info().title("SVCA SERVICE API") 17 | .description("svca service") 18 | .version("v1.0.0") 19 | .license(new License().name("Apache 2.0").url("https://github.com/puhaiyang"))) 20 | .externalDocs(new ExternalDocumentation() 21 | .description("天下武功,无坚不破,唯快不破") 22 | .url("https://blog.csdn.net/puhaiyang")); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /svca-service/src/main/java/cn/zhangxd/svca/controller/ServiceAController.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svca.controller; 2 | 3 | import cn.zhangxd.svca.client.ServiceBClient; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.apache.skywalking.apm.toolkit.trace.Tag; 6 | import org.apache.skywalking.apm.toolkit.trace.Trace; 7 | import org.apache.skywalking.apm.toolkit.trace.TraceContext; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.cloud.client.ServiceInstance; 11 | import org.springframework.cloud.client.discovery.DiscoveryClient; 12 | import org.springframework.cloud.context.config.annotation.RefreshScope; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import javax.annotation.Resource; 17 | import java.security.Principal; 18 | import java.util.Enumeration; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Properties; 22 | 23 | @Slf4j 24 | @RefreshScope 25 | @RestController 26 | public class ServiceAController { 27 | 28 | @Value("${name:unknown}") 29 | private String name; 30 | 31 | @Autowired 32 | DiscoveryClient discoveryClient; 33 | @Resource 34 | private ServiceBClient serviceBClient; 35 | 36 | 37 | @GetMapping(value = "getProp") 38 | public String getProp() { 39 | Properties properties = System.getProperties(); 40 | StringBuilder stringBuilder = new StringBuilder(); 41 | Enumeration enumeration = properties.propertyNames(); 42 | while (enumeration.hasMoreElements()) { 43 | Object o = enumeration.nextElement(); 44 | String line = "key:" + enumeration.nextElement() + " value:" + properties.get(o); 45 | line = line + "\n"; 46 | System.out.println(line); 47 | stringBuilder.append(line); 48 | } 49 | return stringBuilder.toString(); 50 | } 51 | 52 | @GetMapping(value = "getEnv") 53 | public String getEnv() { 54 | Map getenv = System.getenv(); 55 | StringBuilder stringBuilder = new StringBuilder(); 56 | for (String s : getenv.keySet()) { 57 | String line = "key:" + s + " value:" + getenv.get(s); 58 | line = line + "\n"; 59 | System.out.println(line); 60 | stringBuilder.append(line); 61 | } 62 | log.info("[getEnv] tid:{} segmentId:{} spanId:{}", TraceContext.traceId(), TraceContext.segmentId(), TraceContext.spanId()); 63 | log.info("[getEnv] info:{}", stringBuilder.toString()); 64 | return stringBuilder.toString(); 65 | } 66 | 67 | 68 | @GetMapping(value = "getInstances") 69 | public String getInstances(String serviceName) { 70 | List instances = discoveryClient.getInstances(serviceName); 71 | StringBuilder sb = new StringBuilder(); 72 | for (ServiceInstance instance : instances) { 73 | sb.append("uri:" + instance.getUri() + " host:" + instance.getHost() + " port:" + instance.getPort()); 74 | } 75 | log.info("[getInstances] info:{}", sb.toString()); 76 | return "result,instances:" + instances.toString() + " list:" + sb.toString(); 77 | } 78 | 79 | @Trace 80 | @GetMapping(value = "/") 81 | public String printServiceA() { 82 | List services = discoveryClient.getServices(); 83 | for (String service : services) { 84 | List instances = discoveryClient.getInstances(service); 85 | System.out.println("------------" + service + "--------------"); 86 | for (ServiceInstance instance : instances) { 87 | log.info("[printServiceA] serviceName:{} instances:{} port:{}", service, instance.getHost(), instance.getPort()); 88 | } 89 | } 90 | log.info("[printServiceA] tid:{} segmentId:{} spanId:{}", TraceContext.traceId(), TraceContext.segmentId(), TraceContext.spanId()); 91 | return "result:" + serviceBClient.printServiceB(); 92 | } 93 | 94 | @Trace 95 | @Tag(key = "mytag1", value = "arg[0]") 96 | @Tag(key = "result", value = "returnedObj") 97 | @GetMapping(path = "/test") 98 | public String test(String param) { 99 | return "param" + param; 100 | } 101 | 102 | @GetMapping(path = "/current") 103 | public Principal getCurrentAccount(Principal principal) { 104 | return principal; 105 | } 106 | } -------------------------------------------------------------------------------- /svca-service/src/main/java/cn/zhangxd/svca/event/LeaderElectionEventListener.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svca.event; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.ApplicationEvent; 6 | import org.springframework.context.ApplicationListener; 7 | //import org.springframework.integration.leader.event.OnGrantedEvent; 8 | //import org.springframework.integration.leader.event.OnRevokedEvent; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.net.InetAddress; 12 | import java.net.UnknownHostException; 13 | 14 | @Component 15 | public class LeaderElectionEventListener implements ApplicationListener { 16 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 17 | 18 | @Override 19 | public void onApplicationEvent(ApplicationEvent applicationEvent) { 20 | String localIp = getLocalIp(); 21 | // if (applicationEvent instanceof OnGrantedEvent) { 22 | // OnGrantedEvent onGrantedEvent = (OnGrantedEvent) applicationEvent; 23 | // logger.error("[onApplicationEvent] onGrantedEvent:{} source:{} role:{} ip:{}", onGrantedEvent.toString(), onGrantedEvent.getSource(), onGrantedEvent.getRole(), localIp); 24 | // } else if (applicationEvent instanceof OnRevokedEvent) { 25 | // OnRevokedEvent onRevokedEvent = (OnRevokedEvent) applicationEvent; 26 | // logger.error("[onApplicationEvent] onRevokedEvent:{} source:{} role:{} ip:{}", onRevokedEvent.toString(), onRevokedEvent.getSource(), onRevokedEvent.getRole(), localIp); 27 | // } else { 28 | // logger.error("[onApplicationEvent] otherEvent:{} source:{} timestamp:{} ip:{}", applicationEvent.toString(), applicationEvent.getSource(), applicationEvent.getTimestamp(), localIp); 29 | // } 30 | } 31 | 32 | private String getLocalIp() { 33 | try { 34 | InetAddress addr = InetAddress.getLocalHost(); 35 | return addr.getHostAddress(); 36 | } catch (UnknownHostException e) { 37 | e.printStackTrace(); 38 | return "unkown ip"; 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /svca-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: svca-service 4 | cloud: 5 | config: 6 | uri: http://config:30876 7 | fail-fast: true 8 | username: user 9 | password: ${CONFIG_SERVER_PASSWORD:password} 10 | retry: 11 | initial-interval: 2000 12 | max-interval: 10000 13 | multiplier: 2 14 | max-attempts: 10 15 | #本地服务请求测试配置,读取对应的环境变量 16 | local: 17 | feign: 18 | server: 19 | svcb-service: 20 | url: ${FEIGN_URL_SVCBSERVICE:} 21 | 22 | -------------------------------------------------------------------------------- /svca-service/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /svca-service/svca-k8s.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: svca-service 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: svca-service 10 | strategy: 11 | rollingUpdate: 12 | maxSurge: 1 13 | maxUnavailable: 0 14 | type: RollingUpdate 15 | template: 16 | metadata: 17 | labels: 18 | app: svca-service 19 | spec: 20 | initContainers: 21 | - name: init-skywalking-agent 22 | image: apache/skywalking-java-agent:8.12.0-java8 23 | volumeMounts: 24 | - name: skywalking-agent 25 | mountPath: /agent 26 | command: [ "/bin/sh" ] 27 | args: [ "-c", "cp -R /skywalking/agent /agent/" ] 28 | containers: 29 | - image: haiyanggroup-docker.pkg.coding.net/spring-boot-cloud/svca-service/svca-service:master-202209121521 30 | imagePullPolicy: Always 31 | name: svca-service 32 | ports: 33 | - containerPort: 30880 34 | protocol: TCP 35 | env: 36 | - name: JAVA_TOOL_OPTIONS 37 | value: "-javaagent:/skywalking/agent/skywalking-agent.jar" 38 | - name: SW_AGENT_NAME 39 | value: "svca-service" 40 | - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES 41 | value: "skywalking-oap-server:11800" 42 | volumeMounts: 43 | - name: skywalking-agent 44 | mountPath: /skywalking 45 | volumes: 46 | - name: skywalking-agent 47 | emptyDir: {} 48 | --- 49 | apiVersion: v1 50 | kind: Service 51 | metadata: 52 | name: svca-service 53 | spec: 54 | type: NodePort 55 | ports: 56 | - name: http 57 | port: 30880 58 | protocol: TCP 59 | nodePort: 30880 60 | targetPort: 30880 61 | selector: 62 | app: svca-service -------------------------------------------------------------------------------- /svca-service/test.http: -------------------------------------------------------------------------------- 1 | GET http://localhost:30880/getProp -------------------------------------------------------------------------------- /svca-service/windows_set_env.cmd: -------------------------------------------------------------------------------- 1 | //新增或修改值 2 | setx FEIGN_URL_SVCBSERVICE http://127.0.0.1:8070 3 | 4 | //删除值 5 | wmic ENVIRONMENT where "name='FEIGN_URL_SVCBSERVICE'" delete -------------------------------------------------------------------------------- /svcb-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD ./target/svcb-service.jar /app.jar 4 | RUN bash -c 'touch /app.jar' 5 | RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone 6 | EXPOSE 8070 7 | ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","/app.jar"] -------------------------------------------------------------------------------- /svcb-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | cn.zhangxd 9 | spring-boot-cloud 10 | 1.0-SNAPSHOT 11 | 12 | 13 | svcb-service 14 | 1.0-SNAPSHOT 15 | jar 16 | ${project.artifactId} 17 | 18 | 19 | 20 | 21 | org.springdoc 22 | springdoc-openapi-ui 23 | 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-kubernetes-fabric8 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-kubernetes-fabric8-loadbalancer 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-commons 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-web 45 | 46 | 47 | org.springframework.cloud 48 | spring-cloud-starter-openfeign 49 | 50 | 51 | org.jolokia 52 | jolokia-core 53 | 54 | 55 | org.springframework.cloud 56 | spring-cloud-starter-config 57 | 58 | 59 | org.springframework.cloud 60 | spring-cloud-starter-bootstrap 61 | 62 | 63 | org.apache.skywalking 64 | apm-toolkit-trace 65 | 66 | 67 | org.apache.skywalking 68 | apm-toolkit-logback-1.x 69 | 70 | 71 | 72 | 73 | ${project.artifactId} 74 | 75 | 76 | org.springframework.boot 77 | spring-boot-maven-plugin 78 | 79 | 80 | org.apache.maven.plugins 81 | maven-deploy-plugin 82 | 83 | 84 | org.apache.maven.plugins 85 | maven-surefire-plugin 86 | 87 | 88 | io.fabric8 89 | fabric8-maven-plugin 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /svcb-service/src/main/fabric8/service.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: svcb-service 6 | spec: 7 | ports: 8 | - name: http 9 | port: 8070 10 | protocol: TCP 11 | targetPort: 8070 12 | selector: 13 | app: svcb-service -------------------------------------------------------------------------------- /svcb-service/src/main/java/cn/zhangxd/svcb/ServiceBApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svcb; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @EnableDiscoveryClient 9 | @EnableFeignClients 10 | @SpringBootApplication 11 | public class ServiceBApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ServiceBApplication.class, args); 15 | } 16 | } -------------------------------------------------------------------------------- /svcb-service/src/main/java/cn/zhangxd/svcb/config/SpringDocConfig.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svcb.config; 2 | 3 | import io.swagger.v3.oas.models.ExternalDocumentation; 4 | import io.swagger.v3.oas.models.OpenAPI; 5 | import io.swagger.v3.oas.models.info.Info; 6 | import io.swagger.v3.oas.models.info.License; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | public class SpringDocConfig { 12 | 13 | @Bean 14 | public OpenAPI myOpenAPI() { 15 | return new OpenAPI() 16 | .info(new Info().title("SVCB SERVICE API") 17 | .description("svcb service") 18 | .version("v1.0.0") 19 | .license(new License().name("Apache 2.0").url("https://github.com/puhaiyang"))) 20 | .externalDocs(new ExternalDocumentation() 21 | .description("天下武功,无坚不破,唯快不破") 22 | .url("https://blog.csdn.net/puhaiyang")); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /svcb-service/src/main/java/cn/zhangxd/svcb/controller/ServiceBController.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.svcb.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.skywalking.apm.toolkit.trace.TraceContext; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.cloud.client.ServiceInstance; 8 | import org.springframework.cloud.client.discovery.DiscoveryClient; 9 | import org.springframework.cloud.context.config.annotation.RefreshScope; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.List; 14 | 15 | @Slf4j 16 | @RefreshScope 17 | @RestController 18 | public class ServiceBController { 19 | 20 | @Autowired 21 | DiscoveryClient discoveryClient; 22 | 23 | @Value("${msg:unknown}") 24 | private String msg; 25 | 26 | @GetMapping(value = "/") 27 | public String printServiceB() { 28 | StringBuilder sb = new StringBuilder(); 29 | List services = discoveryClient.getServices(); 30 | for (String service : services) { 31 | List instances = discoveryClient.getInstances(service); 32 | for (ServiceInstance serviceInstance : instances) { 33 | sb.append(serviceInstance.getServiceId() + " (" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + ")" + "===>[][i am v5][i am v5][i am v5][]Say " + msg); 34 | } 35 | } 36 | log.info("[printServiceB] tid:{} segmentId:{} spanId:{}", TraceContext.traceId(), TraceContext.segmentId(), TraceContext.spanId()); 37 | return "i am svcb-service" + sb.toString(); 38 | } 39 | } -------------------------------------------------------------------------------- /svcb-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8070 -------------------------------------------------------------------------------- /svcb-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: svcb-service 4 | cloud: 5 | config: 6 | uri: http://config:30876 7 | fail-fast: true 8 | username: user 9 | password: ${CONFIG_SERVER_PASSWORD:password} 10 | retry: 11 | initial-interval: 2000 12 | max-interval: 10000 13 | multiplier: 2 14 | max-attempts: 10 -------------------------------------------------------------------------------- /svcb-service/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /svcb-service/svcb-k8s.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: svcb-service 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: svcb-service 10 | strategy: 11 | rollingUpdate: 12 | maxSurge: 1 13 | maxUnavailable: 0 14 | type: RollingUpdate 15 | template: 16 | metadata: 17 | labels: 18 | app: svcb-service 19 | spec: 20 | initContainers: 21 | - name: init-skywalking-agent 22 | image: apache/skywalking-java-agent:8.12.0-java8 23 | volumeMounts: 24 | - name: skywalking-agent 25 | mountPath: /agent 26 | command: [ "/bin/sh" ] 27 | args: [ "-c", "cp -R /skywalking/agent /agent/" ] 28 | containers: 29 | - image: haiyanggroup-docker.pkg.coding.net/spring-boot-cloud/svcb-service/svcb-service:master-202209121519 30 | imagePullPolicy: Always 31 | name: svcb-service 32 | ports: 33 | - containerPort: 30870 34 | protocol: TCP 35 | env: 36 | - name: JAVA_TOOL_OPTIONS 37 | value: "-javaagent:/skywalking/agent/skywalking-agent.jar" 38 | - name: SW_AGENT_NAME 39 | value: "svcb-service" 40 | - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES 41 | value: "skywalking-oap-server:11800" 42 | volumeMounts: 43 | - name: skywalking-agent 44 | mountPath: /skywalking 45 | volumes: 46 | - name: skywalking-agent 47 | emptyDir: {} 48 | --- 49 | apiVersion: v1 50 | kind: Service 51 | metadata: 52 | name: svcb-service 53 | spec: 54 | type: NodePort 55 | ports: 56 | - name: http 57 | port: 30870 58 | protocol: TCP 59 | nodePort: 30870 60 | targetPort: 30870 61 | selector: 62 | app: svcb-service -------------------------------------------------------------------------------- /user-biz-task/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /user-biz-task/install-mysql-k8s.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: mysql-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: mysql 9 | strategy: 10 | type: Recreate 11 | template: 12 | metadata: 13 | labels: 14 | app: mysql 15 | spec: 16 | containers: 17 | - image: mysql:5.7 18 | name: mysql-con 19 | imagePullPolicy: IfNotPresent 20 | env: 21 | - name: MYSQL_ROOT_PASSWORD 22 | value: "123456" 23 | ports: 24 | - containerPort: 3306 25 | name: mysql 26 | --- 27 | apiVersion: v1 28 | kind: Service 29 | metadata: 30 | name: mysql-service 31 | labels: 32 | app: mysql 33 | spec: 34 | type: NodePort 35 | selector: 36 | app: mysql 37 | ports: 38 | - protocol : TCP 39 | nodePort: 30306 40 | port: 3306 41 | targetPort: 3306 -------------------------------------------------------------------------------- /user-biz-task/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | cn.zhangxd 7 | spring-boot-cloud 8 | 1.0-SNAPSHOT 9 | 10 | 11 | user-biz-task 12 | 1.0-SNAPSHOT 13 | user-biz-task 14 | 定时任务-业务 15 | 16 | 17 | 18 | 19 | org.springframework.cloud 20 | spring-cloud-starter-config 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-task 25 | 26 | 27 | org.springframework.integration 28 | spring-integration-core 29 | 30 | 31 | org.springframework.integration 32 | spring-integration-jdbc 33 | 34 | 35 | io.micrometer 36 | micrometer-registry-prometheus 37 | 38 | 39 | 40 | 41 | ${project.artifactId} 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-deploy-plugin 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-surefire-plugin 54 | 55 | 56 | io.fabric8 57 | fabric8-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /user-biz-task/src/main/java/cn/zhangxd/userbiztask/UserBizTaskApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.userbiztask; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.task.configuration.EnableTask; 6 | 7 | @EnableTask 8 | @SpringBootApplication 9 | public class UserBizTaskApplication { 10 | 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(UserBizTaskApplication.class, args); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /user-biz-task/src/main/java/cn/zhangxd/userbiztask/runner/MyUserBizTaskRunner.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.userbiztask.runner; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.CommandLineRunner; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @author puhaiyang 11 | * @date 2021/3/11 21:50 12 | * MyUserBizTaskRunner 13 | */ 14 | @Component 15 | public class MyUserBizTaskRunner implements CommandLineRunner { 16 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 17 | 18 | @Value("${biz.process.seconds:10}") 19 | private Integer processTimeSeconds; 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | logger.error("MyUserBizTaskRunner start! thread:{}", Thread.currentThread().toString()); 24 | for (int i = 1; i <= processTimeSeconds; i++) { 25 | System.out.println("biz run." + i); 26 | Thread.sleep(1_000); 27 | } 28 | logger.error("MyUserBizTaskRunner end! thread:{}", Thread.currentThread().toString()); 29 | } 30 | } -------------------------------------------------------------------------------- /user-biz-task/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | task: 4 | single-instance-enabled: true 5 | closecontext-enabled: true 6 | management: 7 | metrics: 8 | export: 9 | prometheus: 10 | enabled: true 11 | 12 | -------------------------------------------------------------------------------- /user-biz-task/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: user-biz-task 4 | cloud: 5 | config: 6 | uri: http://config:30876 7 | fail-fast: true 8 | username: user 9 | password: ${CONFIG_SERVER_PASSWORD:password} 10 | retry: 11 | initial-interval: 2000 12 | max-interval: 10000 13 | multiplier: 2 14 | max-attempts: 10 15 | profile: dev -------------------------------------------------------------------------------- /user-biz-task/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /zipkin/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD ./target/zipkin.jar /app.jar 4 | RUN bash -c 'touch /app.jar' 5 | RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone 6 | EXPOSE 9411 7 | ENTRYPOINT ["java","-Dapp.id=zipkin","-javaagent:/opt/skywalking/agent/skywalking-agent.jar","-Dskywalking.agent.service_name=zipkin","-Dskywalking.collector.backend_service=skywalking-oap-server:11800","-jar","-Djava.security.egd=file:/dev/./urandom","/app.jar"] -------------------------------------------------------------------------------- /zipkin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | cn.zhangxd 9 | spring-boot-cloud 10 | 1.0-SNAPSHOT 11 | 12 | 13 | zipkin 14 | 1.0-SNAPSHOT 15 | jar 16 | ${project.artifactId} 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-sleuth 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-stream-binder-rabbit 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-security 38 | 39 | 40 | 41 | 42 | ${project.artifactId} 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | io.fabric8 50 | docker-maven-plugin 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /zipkin/src/main/java/cn/zhangxd/zipkin/ZipkinApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zhangxd.zipkin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author zhangxd 8 | */ 9 | @SpringBootApplication 10 | //@EnableZipkinStreamServer 11 | public class ZipkinApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ZipkinApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /zipkin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: zipkin 4 | rabbitmq: 5 | host: ${RABBITMQ_HOST:rabbitmq} 6 | port: 5672 7 | username: user 8 | password: bitnami 9 | 10 | server: 11 | port: 9411 12 | 13 | security: 14 | user: 15 | name: admin 16 | password: ${ZIPKIN_SERVER_PASSWORD:admin} 17 | --------------------------------------------------------------------------------