Nacos-server 2.2.3 搭建与 SpringBoot 集成

Nacos server 2.2.3

applicaion.properties

### Default web context path:
server.servlet.contextPath=/nacos
### Include message field
server.error.include-message=ALWAYS
### Default web server port:
server.port=9848



#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.10.120:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=dev_lab

### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

### Metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200

### Metrics for influx
management.metrics.export.influx.enabled=false


#*************** Access Log Related Configurations ***************#
### If turn on the access log:
server.tomcat.accesslog.enabled=true

### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

### The directory of access log:
server.tomcat.basedir=file:.

#*************** Access Control Related Configurations ***************#
### If enable spring security, this option is deprecated in 1.2.0:
#spring.security.enabled=false

### The ignore urls of auth
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**

### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos

### If turn on auth system:
nacos.core.auth.enabled=true

### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true

### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false

### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=xxxxxx
nacos.core.auth.server.identity.value=xxxxxx

### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.cache.enable=false
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
### The default token (Base64 String):
### original code : TodayIs20240105.AudioHouIsOurClientSuccessManager.
nacos.core.auth.plugin.nacos.token.secret.key=VG9kYXlJczIwMjQwMTA1LkF1ZGlvSG91SXNPdXJDbGllbnRTdWNjZXNzTWFuYWdlci4=



#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

# 防火墙白名单

允许端口访问 8848 以及偏移量 9848 9849

# 启动

# 进入 bin目录

sh startup.sh -m standalone # 单节点启动

Springboot Service

pom.xml

<properties>
    <!-- boot cloud alibaba 兼容版本 -->
    <spring-boot.version>2.6.13</spring-boot.version>
    <spring-cloud.version>2021.0.5</spring-cloud.version>
    <alibaba-cloud.version>2021.0.5.0</alibaba-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>

    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>

    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>${spring-boot.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-all</artifactId>
        <version>${hutool.version}</version>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
    </dependency>

</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <artifactId>spring-boot-dependencies</artifactId>
            <groupId>org.springframework.boot</groupId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${alibaba-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <profile.environment>dev</profile.environment>
            <nacos.namespace.id>b6f15d1d-c724-4040-a94c-26fee7721ac1</nacos.namespace.id>
            <nacos.server-addrs>192.168.0.1:9848,192.168.0.2:9848</nacos.server-addrs>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <profile.environment>test-120</profile.environment>
            <nacos.namespace.id>776090bc-2b8b-45fd-8296-e4132a989c06</nacos.namespace.id>
            <nacos.server-addrs>192.168.0.1:9848,192.168.0.2:9848</nacos.server-addrs>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <profile.environment>prod</profile.environment>
            <nacos.namespace.id>a31f4272-7bc2-477f-9919-0462b9ee27ad</nacos.namespace.id>
            <nacos.server-addrs>192.168.0.1:9848,192.168.0.2:9848</nacos.server-addrs>
        </properties>
    </profile>
</profiles>

application.yml

server:
  port: 7999

spring:
  application:
    name: demo
  profiles:
    active: @profile.environment@
  main:
    #允许存在多个Feign调用相同Service的接口
    allow-bean-definition-overriding: true
  config:
    import:
      - optional:nacos:common-storage.yml?group=COMMON&refreshEnabled=true
      - optional:nacos:demo.yml?group=${spring.application.name}&refreshEnabled=false
  cloud:
      # Loadbalancer 负载
      loadbalancer:
          enabled: true
          nacos:
            # 使用Nacos负载策略,开发环境可以利用就近访问机制定向访问,启动参数如下:
            # -Dspring.cloud.nacos.discovery.cluster-name=自定义
            enabled: true
          cache:
            # 暂时关闭缓存
            enabled: false
      nacos:
        server-addr: @nacos.server-addrs@
        username: nacos
        password: xxxxx
        discovery:
          namespace: @nacos.namespace.id@
          group: demo
          metadata:
            #心跳间隔。时间单位:毫秒。心跳间隔
            preserved.heart.beat.interval: 1000
            #心跳暂停。时间单位:毫秒。 即服务端6秒收不到客户端心跳,会将该客户端注册的实例设为不健康:
            preserved.heart.beat.timeout: 3000
            #Ip删除超时。时间单位:毫秒。即服务端9秒收不到客户端心跳,会将该客户端注册的实例删除:
            preserved.ip.delete.timeout: 3000
        config:
          namespace: @nacos.namespace.id@
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值