hz/cctp-production/cctp-projects/README.md

156 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 配置中心`cctp-config`
微服务配置中心默认端口8030
## 命令脚本
Linux环境下执行 nk-ms.sh start|stop|restart|status
Windows环境下执行 start.bat (暂未提供)
## 使用方式
步骤1`pom.xml`中增加依赖配置
```xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
... ...
</dependencies>
```
步骤2不使用`application.yml`,只使用`bootstrap.yml`配置文件内容如下:
```yml
server:
port: <微服务端口号>
spring:
profiles:
active: ${NACOS_NAMESPACE:dev}
application:
name: <微服务名称>
cloud:
config:
label: ${APP_LABEL:master}
discovery:
enabled: true
service-id: cctp-config
---
spring:
profiles: dev
eureka:
instance:
instance-id: ${spring.cloud.client.ip-address}:${server.port}
prefer-ip-address: true
client:
serviceUrl:
defaultZone: http://user:password123@192.168.77.24:8761/eureka
---
spring:
profiles: sit
eureka:
instance:
instance-id: ${spring.cloud.client.ip-address}:${server.port}
prefer-ip-address: true
client:
serviceUrl:
defaultZone: http://user:password123@${EUREKA_HOST:eureka.cctp.sit.northking.net}/eureka
---
spring:
profiles: prod
eureka:
instance:
instance-id: ${spring.cloud.client.ip-address}:${server.port}
prefer-ip-address: true
client:
serviceUrl:
defaultZone: http://user:password123@${EUREKA_HOST:eureka.cctp.prod.northking.net}/eureka
```
步骤3 在配置中心的数据库中修改或者增加各个微服务的配置数据
配置中心的数据库IP 192.168.77.26 192.168.77.47
数据库名称cctp_config
表名re_service_config
字段解释如下:
+ app_name: 微服务名称
+ profile: 环境名称dev-开发sit-测试prod-生产;
+ app_label: 版本默认master不用修改
# K8S配置及使用
## Dockerfile镜像配置文件
工程目录下的`Dockerfile`文件是打包Docker镜像的配置文件可能修改的内容如下
+ EXPOSE 端口号,与微服务的端口号一致
+ ENV APP_NAME 微服务名称
+ ENV APP_VERSION 版本号与Maven配置文件pom.xml里的版本一致
## k8s部署配置文件
工程目录下的`*.deployment.yaml`文件是k8s的部署文件可能修改的内容如下
+ name 部署的名称
+ k8s-app: 标签名称
+ image: 镜像地址
+ containerPort 容器的端口号
## 打包部署的脚本
工程目录下的`docker-ctl.sh`文件是k8s打包部署的脚本文件可能修改的内容如下
+ APP_NAME 微服务名称
+ APP_VERSION Docker镜像的版本号与maven的版本号无关
脚本文件使用如下:
```shell script
./docker-ctl.sh < Command1 Command2 Command3 ... >
```
命令可选项:
+ clean: 清理镜像、容器、
+ build: 编译java代码+打jar包+打Docker镜像
+ debug: 本地调试打包的Docker镜像
+ push: 将打包的镜像推送到docker镜像私服仓库
+ pull: 从docker镜像私服仓库拉取镜像到本地
+ deploy: 将docker镜像部署到k8s
举例如下:
```shell script
# 打包镜像
./docker-ctl.sh build
## 打包、推送镜像、部署k8s
./docker-ctl.sh build push deploy
## 重启k8s里的部署服务重新部署就是重启
./docker-ctl.sh deploy
```
## k8s相关命令
```shell script
# 查看`cctp`空间下所有部署的内容
kubectl -n cctp get all
# 查看 `podId`的日志,即微服务的日志
kubectl -n cctp logs -f <podId>
# 进入指定容器内部
kubectl -n cctp exec -it <podId> sh
```