前言:由於公司的要求不同,比如有些公司使用K8s部署項目,來替代nacos實現服務發現功能,所以本文簡單記錄一下如何去掉nacos
pig4cloud官網拉取的demo是複合工程,我本地是先把複合工程拆分爲多個獨立的工程,然後再實現的去掉nacos服務。
獨立出來的工程主要有,pig-auth、pig-upms、pig-security、pig-gateway、pig-log、pig-common等,具體的拆分步驟可參考網上的例子。
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency>
3,將原有nacos配置中心上的配置文件遷移到application.yml文件中並修改
server: port: 9999 spring: application: name: @artifactId@ cloud: gateway: routes: # 認證中心 - id: pig-auth uri: http://pig-auth:3000 predicates: - Path=/auth/** filters: # 驗證碼處理 - ValidateCodeGatewayFilter # 前端密碼解密 - PasswordDecoderFilter #UPMS 模塊 - id: pig-upms-biz uri: http://pig-upms-biz:4000 predicates: - Path=/admin/** filters: # 限流配置 - name: RequestRateLimiter args: key-resolver: '#{@remoteAddrKeyResolver}' redis-rate-limiter.replenishRate: 100 redis-rate-limiter.burstCapacity: 200 # 代碼生成模塊 - id: pig-codegen uri: http://pig-codegen:5002 predicates: - Path=/gen/** # 代碼生成模塊 - id: pig-quartz uri: http://pig-quartz:5007 predicates: - Path=/job/** # 固定路由轉發配置 無修改 - id: openapi uri: http://pig-gateway:9999 predicates: - Path=/v3/api-docs/** filters: - RewritePath=/v3/api-docs/(?<path>.*), /$\{path}/$\{path}/v3/api-docs gateway: encode-key: 'thanks,pig4cloud' ignore-clients: - test - client
二,pig-auth 服務調整
1,同上
2,同上
3,將原有nacos配置中心上的配置文件遷移到application.yml文件中並修改
server:
port: 3000
spring:
application:
name: @artifactId@
freemarker:
allow-request-override: false
allow-session-override: false
cache: true
charset: UTF-8
check-template-location: true
content-type: text/html
enabled: true
expose-request-attributes: false
expose-session-attributes: false
expose-spring-macro-helpers: true
prefer-file-system-access: true
suffix: .ftl
template-loader-path: classpath:/templates/
# 配置文件加密根密碼
jasypt:
encryptor:
password: pig
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
pig:
upms:
url: http://pig-upms-biz:4000
auth:
url: http://pig-auth:3000
三,pig-upms 服務調整
1,同上
2,同上
3,pig-umps-api 服務新增application.yml配置文件
pig:
upms:
url: http://pig-upms-biz:4000
auth:
url: http://pig-auth:3000
4,pig-umps-biz 服務新增application.yml配置文件內容調整
server: port: 4000 spring: application: name: @artifactId@ datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver username: root password: mysql url: jdbc:mysql://localhost:3306/pig?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true cache: type: redis redis: host: pig-redis cloud: sentinel: eager: true transport: dashboard: pig-sentinel:5003 # 文件上傳相關 支持阿里雲、華爲雲、騰訊、minio file: bucketName: s3demo local: enable: true base-path: /Users/lengleng/Downloads/img mybatis-plus: mapper-locations: classpath:/mapper/*Mapper.xml type-handlers-package: com.pig4cloud.pig.common.mybatis.handler global-config: banner: false db-config: id-type: auto table-underline: true logic-delete-value: 1 logic-not-delete-value: 0 configuration: map-underscore-to-camel-case: true jdbc-type-for-null: 'null' log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # feign 配置 feign: sentinel: enabled: true okhttp: enabled: true httpclient: enabled: false client: config: default: connectTimeout: 10000 readTimeout: 10000 compression: request: enabled: true response: enabled: true pig: upms: url: http://pig-upms-biz:4000 auth: url: http://pig-auth:3000
5,pig-umps-api 服務調整所有的feign接口
四,本地host文件修改
1,文件管理器打開 C:\Windows\System32\drivers\etc找到hosts文件並修改
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 activate.navicat.com
127.0.0.1 pig-mysql
127.0.0.1 pig-redis
127.0.0.1 pig-gateway
127.0.0.1 pig-register
127.0.0.1 pig-sentinel
127.0.0.1 pig-monitor
127.0.0.1 pig-job
127.0.0.1 pig-seata
127.0.0.1 pig-auth
127.0.0.1 pig-upms-biz
2,代碼調整完之後build,clean install,然後依次啓動pig-auth, pig-upms, pig-gateway服務,整合結束。