1.nacos启用为服务

  1. <dependency>
  2. <groupId>com.xy</groupId>
  3. <artifactId>xy-core-framework-common-api-distributed</artifactId>
  4. <version>${xy-core-framework.version}</version>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>org.springframework.security</groupId>
  8. <artifactId>spring-security-crypto</artifactId>
  9. </exclusion>
  10. </exclusions>
  11. </dependency>

2.添加nacos配置

  1. server.port=8094
  2. server-addr=192.168.1.3
  3. nacos.namespace=afb35e27-a583-40c1-a4d2-411a2b9764cd
  4. #server-addr=192.168.3.50
  5. #nacos.namespace=c31a0971-b627-4aa8-8a64-109afab2ab6b
  6. #server-addr=10.30.0.143
  7. #nacos.namespace=e5756e6a-218e-45f3-bbbd-af36c69f2bf4
  8. #############################################################
  9. spring.cloud.nacos.config.server-addr=${server-addr}:8848
  10. #spring.profiles.active=dev
  11. #spring.cloud.nacos.config.cluster-name=
  12. spring.cloud.nacos.config.namespace=${nacos.namespace}
  13. spring.cloud.nacos.config.group=local
  14. #spring.cloud.nacos.config.name=company_demo-dev
  15. spring.cloud.nacos.config.file-extension=properties
  16. #spring.cloud.nacos.config.prefix=company-demo
  17. spring.cloud.nacos.config.refresh-enabled=true
  18. spring.cloud.nacos.config.enabled=true
  19. spring.cloud.nacos.config.encode=UTF-8
  20. spring.cloud.nacos.config.extension-configs[0].data-id=redis-common.properties
  21. spring.cloud.nacos.config.extension-configs[0].group=common
  22. spring.cloud.nacos.config.extension-configs[0].refresh=true
  23. spring.cloud.nacos.config.extension-configs[1].data-id=rocket-common.properties
  24. spring.cloud.nacos.config.extension-configs[1].group=common
  25. spring.cloud.nacos.config.extension-configs[1].refresh=true
  26. spring.cloud.nacos.config.extension-configs[2].data-id=dubbo-common.properties
  27. spring.cloud.nacos.config.extension-configs[2].group=common
  28. spring.cloud.nacos.config.extension-configs[2].refresh=true
  29. spring.cloud.nacos.config.extension-configs[3].data-id=info-common.properties
  30. spring.cloud.nacos.config.extension-configs[3].group=common
  31. spring.cloud.nacos.config.extension-configs[3].refresh=true
  32. spring.cloud.nacos.config.extension-configs[4].data-id=management-common.properties
  33. spring.cloud.nacos.config.extension-configs[4].group=common
  34. spring.cloud.nacos.config.extension-configs[4].refresh=true
  35. spring.cloud.nacos.config.extension-configs[5].data-id=generator-id-common.properties
  36. spring.cloud.nacos.config.extension-configs[5].group=common
  37. spring.cloud.nacos.config.extension-configs[5].refresh=true
  38. spring.cloud.nacos.config.extension-configs[6].data-id=lark-common.properties
  39. spring.cloud.nacos.config.extension-configs[6].group=common
  40. spring.cloud.nacos.config.extension-configs[6].refresh=true
  41. spring.cloud.nacos.config.extension-configs[7].data-id=mybatis-plus-common.properties
  42. spring.cloud.nacos.config.extension-configs[7].group=common
  43. spring.cloud.nacos.config.extension-configs[7].refresh=true
  44. spring.cloud.nacos.config.extension-configs[8].data-id=arthas-common.properties
  45. spring.cloud.nacos.config.extension-configs[8].group=common
  46. spring.cloud.nacos.config.extension-configs[8].refresh=true
  47. spring.cloud.nacos.config.extension-configs[9].data-id=i18n-common.properties
  48. spring.cloud.nacos.config.extension-configs[9].group=common
  49. spring.cloud.nacos.config.extension-configs[9].refresh=true
  50. spring.cloud.nacos.config.extension-configs[10].data-id=logback-common.properties
  51. spring.cloud.nacos.config.extension-configs[10].group=common
  52. spring.cloud.nacos.config.extension-configs[10].refresh=true
  53. spring.cloud.nacos.config.extension-configs[11].data-id=sentinel-common.properties
  54. spring.cloud.nacos.config.extension-configs[11].group=common
  55. spring.cloud.nacos.config.extension-configs[11].refresh=true
  56. spring.cloud.nacos.config.extension-configs[12].data-id=zk-common.properties
  57. spring.cloud.nacos.config.extension-configs[12].group=common
  58. spring.cloud.nacos.config.extension-configs[12].refresh=true
  59. spring.cloud.nacos.config.extension-configs[13].data-id=job-common.properties
  60. spring.cloud.nacos.config.extension-configs[13].group=common
  61. spring.cloud.nacos.config.extension-configs[13].refresh=true
  62. #spring.cloud.nacos.config.endpoint=${spring.application.name}
  63. #spring.cloud.nacos.config.access-key=
  64. #spring.cloud.nacos.config.secret-key=
  65. #spring.cloud.nacos.config.config-long-poll-timeout=3000
  66. #spring.cloud.nacos.config.timeout=9000
  67. #spring.cloud.nacos.config.config-retry-time=3
  68. #spring.cloud.nacos.config.max-retry=5
  69. #spring.cloud.nacos.config.enable-remote-sync-config=false
  70. #spring.cloud.nacos.config.shared-configs=
  71. #spring.cloud.nacos.config.context-path=
  72. #spring.cloud.nacos.config.environment=
  73. #spring.cloud.nacos.config.extension-configs=
  74. #############################################################
  75. spring.cloud.nacos.discovery.server-addr=${server-addr}:8848
  76. spring.cloud.nacos.discovery.service=${spring.application.name}
  77. #spring.cloud.nacos.discovery.cluster-name=
  78. spring.cloud.nacos.discovery.namespace=${nacos.namespace}
  79. spring.cloud.nacos.discovery.group=local
  80. spring.cloud.nacos.discovery.enabled=true
  81. #spring.cloud.nacos.discovery.access-key=
  82. #spring.cloud.nacos.discovery.secret-key=
  83. spring.cloud.nacos.discovery.instance-enabled=true
  84. #spring.cloud.nacos.discovery.ip=
  85. #spring.cloud.nacos.discovery.endpoint=
  86. #spring.cloud.nacos.discovery.heart-beat-interval=3000
  87. #spring.cloud.nacos.discovery.heart-beat-timeout=6000
  88. #spring.cloud.nacos.discovery.ip-delete-timeout=9000
  89. #spring.cloud.nacos.discovery.log-name=
  90. #spring.cloud.nacos.discovery.naming-load-cache-at-start=true
  91. #spring.cloud.nacos.discovery.network-interface=
  92. #spring.cloud.nacos.discovery.metadata.version=1
  93. #spring.cloud.nacos.discovery.port=-1
  94. spring.cloud.nacos.discovery.register-enabled=true
  95. #spring.cloud.nacos.discovery.secure=false
  96. #spring.cloud.nacos.discovery.watch.enabled=true
  97. #spring.cloud.nacos.discovery.watch-delay=30000
  98. #spring.cloud.nacos.discovery.weight=1

3.在nacos中配置资源信息

xy-common-api-distributed - 图1

common配置详情

redis-common.properties

  1. #通用设置
  2. spring.redis.host=${server-addr}
  3. spring.redis.port=6379
  4. spring.redis.database=0
  5. spring.redis.jedis.pool.max-active=800
  6. spring.redis.jedis.pool.max-idle=800
  7. spring.redis.jedis.pool.max-wait=1000
  8. spring.redis.jedis.pool.min-idle=0
  9. #设置在自己的项目中
  10. spring.redis.distributed.lock.enable=true
  11. spring.redis.distributed.lock.client=redis_template

rocket-common.properties

  1. ############################# rocket mq config###########################################
  2. #通用配置
  3. rocketmq.name-server=${server-addr}:9876
  4. rocketmq.access-channel=LOCAL
  5. rocketmq.producer.group=${spring.application.name}
  6. #rocketmq.producer.access-key=
  7. #rocketmq.producer.secret-key=
  8. #rocketmq.producer.enable-msg-trace=true
  9. #rocketmq.producer.customized-trace-topic=
  10. #rocketmq.producer.max-message-size=4194394
  11. rocketmq.producer.compress-message-body-threshold=4096
  12. rocketmq.producer.retry-next-server=false
  13. rocketmq.producer.retry-times-when-send-failed=2
  14. rocketmq.producer.retry-times-when-send-async-failed=2
  15. rocketmq.producer.send-message-timeout=3000
  16. #配置在自己的项目中
  17. #是否开启mq消息监听,如果开启,则正常消费消息,如果关系,服务当前节点则不在消费任何消息
  18. rocketmq.consumer.enable=true
  19. #rocketmq.consumer.group=${spring.application.name}-consumer

dubbo-common.properties

  1. ######################### dubbo config ###############################################
  2. dubbo.application.name=${spring.application.name}
  3. dubbo.application.qos-enable=true
  4. ###--------registry config------------
  5. #zookeeper://localhost:2181
  6. #nacos://localhost:8848
  7. dubbo.registry.address=zookeeper://${server-addr}:2181
  8. dubbo.registry.check=true
  9. #否是关闭注册
  10. dubbo.registry.register=true
  11. ###--------protocol config------------
  12. dubbo.protocol.name=dubbo
  13. dubbo.protocol.port=20880
  14. dubbo.protocol.dispatcher=all
  15. dubbo.protocol.threadpool=fixed
  16. dubbo.protocol.threads=100
  17. ###--------provider config------------
  18. dubbo.provider.delay=2000
  19. dubbo.provider.executes=10
  20. dubbo.provider.actives=10
  21. dubbo.provider.timeout=3000
  22. dubbo.provider.retries=2
  23. dubbo.provider.loadbalance=random
  24. dubbo.application.shutwait=15000
  25. #dubbo.service.com.company.demo.DemoServiceApi.timeout=5000
  26. ###--------config-center config------------
  27. #dubbo.config-center.address=zookeeper://${local.ip}:2181
  28. #dubbo.config-center.protocol=nacos
  29. ###--------consumer config------------
  30. dubbo.consumer.timeout=3000
  31. dubbo.consumer.check=true
  32. dubbo.consumer.actives=10
  33. dubbo.consumer.reconnect=true
  34. dubbo.consumer.sent=true
  35. dubbo.consumer.corethreads=10
  36. dubbo.consumer.threadpool=fixed
  37. dubbo.consumer.threads=10
  38. dubbo.consumer.lazy=false
  39. #dubbo.reference.org.apache.dubbo.samples.api.DemoService.timeout=6000
  40. #dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.timeout=7000

info-common.properties

  1. info.app=${spring.application.name}
  2. info.site=www.company.com
  3. info.build.groupId=@project.groupId@
  4. info.build.artifactId=@project.artifactId@
  5. info.build.finalName$=@project.build.finalName@
  6. info.build.version=2.0.96110

management-common.properties

  1. ##############################---配置监控信息---##########################################
  2. #spring.jmx.enabled=true
  3. #spring.jmx.unique-names=true
  4. #spring.jmx.default-domain=
  5. #management.metrics.tags.application=${spring.application.name}
  6. #management.auditevents.enabled=false
  7. #management.endpoint.auditevents.enabled=false
  8. #management.endpoint.auditevents.cache.time-to-live=5
  9. #management.endpoints.web.exposure.include=*
  10. #management.endpoint.health.enabled=false
  11. #management.endpoint.health.show-details=always
  12. #management.endpoint.beans.enabled=false
  13. #management.endpoint.beans.cache.time-to-live=0ms
  14. #management.endpoint.shutdown.enabled=false
  15. ######## 属性尝试 ##########
  16. #management.endpoint.httptrace.enabled=false
  17. #management.endpoint.env.post.enabled=false
  18. #################
  19. ###springbootAdmin 开启日志打印
  20. #management.endpoint.logfile.enabled=true
  21. #management.endpoint.logfile.external-file=./logs/${spring.application.name}/${spring.application.name}.log
  22. #management.endpoint.logfile.cache.time-to-live=0ms

generator-id-common.properties

  1. #######################分布式id##################################
  2. com.xy.id.generator.zk.enable=true
  3. com.xy.id.generator.zk.connect-string=${server-addr}:2181
  4. com.xy.id.generator.cloud-service=ali
  5. com.xy.id.generator.zk.username=

lark-common.properties

  1. #####lark 告警消息
  2. xy.core.push.enable=true
  3. xy.core.push.channel=lark
  4. xy.core.push.alarm-url=https://open.larksuite.com/open-apis/bot/v2/hook/a2636256-20e0-43d1-8218-4c107fd9bf44
  5. xy.core.push.logic-url=https://open.larksuite.com/open-apis/bot/v2/hook/c40bdb56-567f-498e-a41a-8776f1d98f27

mybatis-plus-common.properties

  1. ####################### mybatis plus config #################################################
  2. mybatis-plus.mapper-locations=classpath*:/mybatis/*.xml
  3. #mybatis-plus.type-aliases-package=com.company.demo.entities
  4. mybatis-plus.global-config.db-config.id-type=auto
  5. mybatis-plus.global-config.db-config.logic-delete-field=deleted
  6. mybatis-plus.global-config.db-config.logic-delete-value=1
  7. mybatis-plus.global-config.db-config.logic-not-delete-value=0
  8. #mybatis-plus.global-config.db-config.column-format=
  9. #mybatis-plus.global-config.db-config.table-prefix=
  10. mybatis-plus.global-config.db-config.table-underline=true
  11. mybatis-plus.configuration.map-underscore-to-camel-case=true
  12. mybatis-plus.configuration.call-setters-on-nulls=true
  13. ##是否开启sql性能检查
  14. mybatis-plus.illegal-s-q-l-inner-interceptor=true

arthas-common.properties

  1. ####################### arthas config ##########################
  2. arthas.agent-id=${spring.application.id}
  3. ## 使用tunnel-server所在服务器ip
  4. arthas.tunnel-server=ws://192.168.1.2:7777/ws

i18n-common.properties

  1. spring.messages.encoding=UTF-8
  2. spring.messages.basename=i18n/messages
  3. spring.messages.fallback-to-system-locale=false

logback-common.properties

  1. ############################ logback config ############################################
  2. logging.config=classpath:logback-spring.xml
  3. logging.file.path=./logs/${spring.application.name}
  4. #默认日志级别
  5. logging.level.root=info
  6. logging.level.sql=debug
  7. logging.level.web=debug

sentinel-common.properties

  1. ########################### 负载均衡 ##############################################
  2. spring.cloud.loadbalancer.retry.enabled=true
  3. spring.cloud.sentinel.enabled=true
  4. spring.cloud.sentinel.transport.dashboard=${server-addr}:8858
  5. spring.cloud.sentinel.transport.port=8719
  6. #应用与Sentinel控制台的心跳间隔时间
  7. spring.cloud.sentinel.transport.heartbeat-interval-ms=1000
  8. #Sentinel自动化配置是否生效
  9. spring.cloud.sentinel.filter.enabled=true
  10. spring.cloud.sentinel.metric.charset=UTF-8
  11. #取消Sentinel控制台懒加载
  12. spring.cloud.sentinel.eager=true
  13. #Sentinel 日志文件所在的目录
  14. spring.cloud.sentinel.log.dir=./logs/${spring.application.name}/sentinel
  15. spring.cloud.sentinel.xy.enable=true
  16. spring.cloud.sentinel.xy.mvc-interceptor-enable=true
  17. spring.cloud.sentinel.xy.total-interceptor-enable=true

zk-common.properties

  1. zookeeper.address=192.168.1.2:2181
  2. zookeeper.timeout=30
  3. zookeeper.lock-enable=true

job-common.properties

  1. # 定时任务是否开启
  2. elasticjob.enabled=true
  3. #定时任务注册的zk地址
  4. elasticjob.reg-center.server-lists=zookeeper-svc:2181
  5. #定时任务注册的命名空间 默认job/${spring.application.name}
  6. elasticjob.reg-center.namespace=job/${spring.application.name}
  7. #是否跟踪任务执行trace
  8. elasticjob.datasource.enable=true
  9. #任务开启trace记录的数据库地址,目前默认在trace系统中
  10. elasticjob.datasource.url=jdbc:mysql://t-mysql.celcxdxq82fd.us-west-2.rds.amazonaws.com:3306/trendsi_trace?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
  11. elasticjob.datasource.type=com.zaxxer.hikari.HikariDataSource
  12. elasticjob.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  13. elasticjob.datasource.username=trendsi
  14. elasticjob.datasource.password=b3?(`*f_:h8SBXr$