0
点赞
收藏
分享

微信扫一扫

nacos 使用

small_Sun 2022-03-12 阅读 63

#nacos 使用说明

  1. nacos 有多个命名空间,项目中使用wiilead后端开发环境和wiilead生成环境。默认只有修改dev环境的配置。在项目中配置ID即可使用
  2. 项目中使用maven 引入相关依赖,该依赖直接放到了root pom.xml 中,所以其他模块不用单独配置
 		<dependency>
 			<groupId>org.springframework.cloud</groupId>
 			<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
 		</dependency>
 		<!-- nacos 配置中心-->
 		<dependency>
 			<groupId>org.springframework.cloud</groupId>
 			<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
 		</dependency>

4.项目中通过在bootstrap.yml 中配置,使用nacos

spring:
  #基础配置
  profiles:
    active: dev
  application:
    name: wiilead-message-biz
  # 配置中心
  cloud:
    nacos:
      #注册中心
      discovery:
        server-addr: wiilead-discovery-nacos # IP:端口,端口默认是8848
        namespace: wiilead-${spring.profiles.active}  #指定nacos的命名空间
      #配置中心
      config:
        server-addr: wiilead-config-nacos
        namespace: wiilead-${spring.profiles.active}
        file-extension: yaml  #文件类型
        ext-config[0]: # 0,1,2 指定多个配置文件,都会加载,数字小的先加载,后面的会对前面的进行覆盖
          data-id: application-${spring.profiles.active}.yaml # 通用的基础配置
          refresh: true
        ext-config[1]:
          data-id: springdb-${spring.profiles.active}.yaml # mysql + redis 的配置
          refresh: true
        ext-config[2]:
          data-id: wiilead-alm-biz-${spring.profiles.active}.yaml # 示例,每一个微服务的差异性配置
          refresh: true
  1. 注册中心的使用,建议后端同学自己安装一个nacos避免大家把服务都注册到了线上nacos中。
    修改本地的hosts文件,配置 wiilead-discovery-nacos 指定注册中心地址,配置wiilead-config-nacos
    指定配置中心地址。配置中心可以直接使用线上的。也可以在本地使用,nacos 支持配置的导入导出十分方便
    请谨慎的修改线上的配置。
举报

相关推荐

0 条评论