Simple configuration and use of Nacos

1. What is Nacos?

Official website address: What is Nacos

Introduction: Nacos is a new open source project  launched by Alibaba . It is a dynamic service discovery, configuration management and service management platform that makes it easier to build cloud-native applications .

Nacos is dedicated to helping you discover, configure and manage microservices . Nacos provides a set of easy-to-use feature sets to help you quickly realize dynamic service discovery, service configuration, service metadata, and traffic management .

Nacos helps you build, deliver and manage microservice platforms more agilely and easily. Nacos is a service infrastructure for building a "service"-centric modern application architecture (such as microservice paradigm, cloud native paradigm).

2. The use of Nacos (taking microservice projects as an example) 

1. Nacos dependencies need to be introduced in the project:

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

2. Add nacos related configuration to the project:

 PS: If bootstrap.yml and application.yml exist at the same time, bootstrap.yml has a higher priority.

3. Start Nacos:

 Enter in this directory: cmd, open the command line interface, and enter the startup command (stand-alone startup):

startup.cmd -m standalone

The following is the startup success interface:

 

 Access address: http://192.168.XXX.X:8848/nacos/index.html

 4. Configuration content

After the browser access is successful, some basic configuration needs to be done. My interface is the effect after multiple modules of a microservice project have been configured.

(1) Gateway configuration:

spring:  
  cloud:
    gateway:
      discovery:
        locator:
          lowerCaseServiceId: true
          enabled: true
      routes:
        # 认证中心
        - id: bigdata-auth
          uri: lb://bigdata-auth
          predicates:
            - Path=/auth/**
          filters:
            # 验证码处理
            - CacheRequestFilter
            - ValidateCodeFilter
            - StripPrefix=1
            - StripPrefix=1
        # 系统模块
        - id: bigdata-system
          uri: lb://bigdata-system
          predicates:
            - Path=/system/**
          filters:
            - StripPrefix=1

(2), add the relevant configuration of this module in Nacos (that is, your application.yml in the project)

The name should be the same as your module name:

 

After the project is successfully started in the background, you can see the corresponding service status in Nacos. 

Guess you like

Origin blog.csdn.net/yy12345_6_/article/details/126690337