使用带有密码的nacos作为Sentinel数据源网关yml配置

nacos中网关的配置如下

server:
  port: 18600

spring:
  cloud:
    sentinel:
      app:
        #标识网关项目
        type: 1
      # 取消控制台懒加载
      eager: true
      transport:
        # 控制台地址
        dashboard: 10.xxx.xxx.4:8088
         #网关ip
        client-ip: 10.xxx.xxx.4
      # nacos配置持久化 
      datasource:
        ds-flow:
          nacos:
            server-addr: 10.xxx.xxx.4:xxxx
            namespace: ed2c5b61-68c2-4c07-8446-37bcc9064e0a
            dataId: sentinel-pojo-gateway
            groupId: DEFAULT_GROUP
            data-type: json
            #流控规则
            rule-type: flow
            username: nacos
            password: yuanhangXXXXX
        ds-degrade:
          nacos:
            server-addr: 10.xxx.xxx.4:xxxx
            namespace: ed2c5b61-68c2-4c07-8446-37bcc9064e0a
            dataId: sentinel-degrade-gateway
            groupId: DEFAULT_GROUP
            data-type: json
            #熔断规则
            rule-type: degrade
            username: nacos
            password: yuanhangXXXXX            

    gateway:
      discovery:
        locator:
          lowerCaseServiceId: true
          enabled: true
      routes:
        # 认证中心
        - id: yh-platform-auth
          uri: lb://yh-platform-auth
          predicates:
            - Path=/auth/**
          filters:
            # 验证码处理
            - CacheRequestFilter
            - StripPrefix=1
        # 系统模块
        - id: yh-platform-system
          uri: lb://yh-platform-system
          predicates:
            - Path=/system/**
          filters:
            - StripPrefix=1
        # 文件服务
        - id: yh-platform-file
          uri: lb://yh-platform-file
          predicates:
            - Path=/file/**
          filters:
            - StripPrefix=1
         # hkhj
        - id: yh-platform-prj
          uri: lb://yh-platform-prj
          predicates:
            - Path=/prj/**
          filters:
            - StripPrefix=1


# 不校验白名单
ignore:
  whites:
    - /auth/login
    - /csrf
    - /auth/logoutApp
    - /auth/loginApp

使用服务器上的Nacos作为配置中心,你可以按照以下步骤进行配置: 1. 首先,确保你的服务器上已经安装了Nacos。你可以从Nacos的官方网站下载并安装Nacos。 2. 在你的项目中添加Nacos的依赖。如果你使用的是Spring Boot项目,可以在`pom.xml`文件中添加以下依赖: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-config-nacos</artifactId> </dependency> ``` 3. 在`application.yml`或`application.properties`文件中配置Nacos的相关信息。例如: ```yaml spring: cloud: nacos: config: server-addr: ${nacos.server-addr} namespace: ${nacos.namespace} group: ${nacos.group} username: ${nacos.username} password: ${nacos.password} ``` 这里的`${nacos.server-addr}`是Nacos服务器的地址,`${nacos.namespace}`是命名空间,`${nacos.group}`是配置分组,`${nacos.username}`和`${nacos.password}`是登录Nacos的用户名和密码。 4. 创建一个配置类,用于从Nacos获取配置信息。例如: ```java import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; @Configuration public class NacosConfig { @Value("${nacos.config.data-id}") private String dataId; @Value("${nacos.config.group}") private String group; // Getter and Setter methods } ``` 这里的`${nacos.config.data-id}`是需要获取的配置的ID,`${nacos.config.group}`是配置所属的分组。 5. 在需要使用配置的地方注入`NacosConfig`类,并使用其中的属性值。 以上就是使用服务器上的Nacos作为配置中心的基本步骤。你可以根据自己的需求进行相应的配置和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

非ban必选

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值