其他分享
首页 > 其他分享> > SpringCloudAlibaba-注册中心_配置中心(Nacos)

SpringCloudAlibaba-注册中心_配置中心(Nacos)

作者:互联网

Nacos

概述

为什么叫Nacos?

前4个分别为 Naming和Configuration的前2个字母,s是Service;

what

 

Dynamic Naming and Configuration Service

一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台;

  (注册中心+配置中心)

  Nacos 等价于 Eureka+Config+Bus

https://github.com/alibaba/Nacos

https://nacos.io/zh-cn/

https://nacos.io/zh-cn/docs/what-is-nacos.html

https://spring-cloud-alibaba-group.github.io/github-pages/2021/en-us/index.html#_spring_cloud_alibaba_nacos_discovery

NacosServer安装与运行

下载

https://github.com/alibaba/nacos/tags

解压包 并 运行bin下的startup.sh

登录

  http://127.0.0.1:8848/nacos/#/login

  默认账号/密码 nacos/nacos

NacosClient

父pom

<dependencyManagement>
        <dependencies>
            <!--spring boot 2.2.2-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.2.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.8.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

  

provider

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

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


server:
  port: 9001

spring:
  application:
    name: nacos-provider
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848

management:
  endpoints:
    web:
      exposure:
        include: '*'



@SpringBootApplication
@EnableDiscoveryClient
public class NacosProviderDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(NacosProviderDemoApplication.class, args);
    }
}


@RestController
public class EchoController {
    @GetMapping(value = "/echo/{string}")
    public String echo(@PathVariable String string) {
        return "Hello Nacos Discovery " + string;
    }
}

  

 

 

 

  

 

 

 

  

标签:中心,spring,boot,Nacos,alibaba,nacos,SpringCloudAlibaba,cloud
来源: https://www.cnblogs.com/anpeiyong/p/16595837.html