美文网首页
Nacos服务注册与发现

Nacos服务注册与发现

作者: engineer_tang | 来源:发表于2021-04-04 11:47 被阅读0次

    1. 简介

    为了支撑更大流量,我们会采用微服务架构,通过微服务的拆分、水平扩容等来提升系统性能,解决复杂的业务问题。
    Nacos是微服务中的注册中心,主要提供如下功能:

    • 服务地址的管理。
    • 服务注册。
    • 服务动态感知。
      Nacos的关键特性:
    • 服务发现和服务健康监测
    • 动态配置服务
    • 动态DNS服务
    • 服务及其元数据管理

    2. Nacos安装

    git clone https://github.com/alibaba/nacos.git
    cd nacos/
    mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U  
    ls -al distribution/target/
    
    // change the $version to your actual path
    cd distribution/target/nacos-server-$version/nacos/bin
    

    启动服务器
    Linux/Unix/Mac
    启动命令(standalone代表着单机模式运行,非集群模式):

    sh startup.sh -m standalone
    

    如果您使用的是ubuntu系统,或者运行脚本报错提示[[符号找不到,可尝试如下运行:

    bash startup.sh -m standalone
    

    Windows
    启动命令(standalone代表着单机模式运行,非集群模式):

    cmd startup.cmd -m standalone
    

    3. 服务注册&发现和配置管理

    3.1 服务注册

    curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'
    

    3.2 服务发现

    curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instance/list?serviceName=nacos.naming.serviceName'
    

    3.3 发布配置

    curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld"
    

    3.4 获取配置

    curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test"
    

    3.5 关闭服务器

    Linux/Unix/Mac

    sh shutdown.sh
    

    Windows

    cmd shutdown.cmd
    

    或者双击shutdown.cmd运行文件。

    相关文章

      网友评论

          本文标题:Nacos服务注册与发现

          本文链接:https://www.haomeiwen.com/subject/vmlfkltx.html