当前位置:网站首页>Nacos的基本使用(1)——入门
Nacos的基本使用(1)——入门
2022-07-27 16:25:00 【热爱旅行的小李同学】
Nacos的基本使用
文章目录
一、基本概念
(1)Nacos:
Nacos 是阿里巴巴推出来的一个新开源项目,是一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。Nacos
致力于帮助您发现、配置和管理微服务。Nacos
提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。Nacos
帮助您更敏捷和容易地构建、交付和管理微服务平台。 Nacos 是构建以“服务”为中心的现代应用架构 (例如微服务范式、云原生范式)
的服务基础设施。
(2)常见的注册中心:
Eureka(原生,2.0遇到性能瓶颈,停止维护)
Zookeeper(支持,专业的独立产品。例如:dubbo)
Consul(原生,GO语言开发)
Nacos
相对于 Spring Cloud Eureka 来说,Nacos 更强大。Nacos = Spring Cloud Eureka + Spring Cloud Config
Nacos 可以与 Spring, Spring Boot, Spring Cloud 集成,并能代替 Spring Cloud Eureka, Spring Cloud Config
- 通过 Nacos Server 和 spring-cloud-starter-alibaba-nacos-discovery 实现服务的注册与发现。
(3)Nacos功能
Nacos是以服务为主要服务对象的中间件,Nacos支持所有主流的服务发现、配置和管理。
Nacos主要提供以下四大功能:
服务发现和服务健康监测
动态配置服务
动态DNS服务
服务及其元数据管理
(4)Nacos结构图
可以把Nacos理解为一个中介,连接消费者consumer和生产者provider
二、Nacos的下载和安装
1 下载地址
github地址: https://github.com/alibaba/nacos/releases
2 启动Nacos服务
- Linux/Unix/Mac
启动命令(standalone代表着单机模式运行,非集群模式)
启动命令:sh startup.sh -m standalone
- Windows
启动命令:cmd startup.cmd 或者双击startup.cmd运行文件。
访问:http://localhost:8848/nacos
用户名密码:nacos/nacos

三、注册服务
第一步: 在模块中引入相关依赖
在 pom.xml 中添加服务注册相关依赖
<!--服务注册-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
第二步:在要注册的模块的配置文件中进行配置
在application.properties/yml上添加nacos服务地址
# Nacos服务地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
第三步:添加Nacos注解
在项目启动类上添加上 @EnableDiscoveryClient 注解
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;
@SuppressWarnings("all")
@SpringBootApplication
@ComponentScan(basePackages = "com.atguigu")//扫描包
@EnableDiscoveryClient // nacos注册
public class EduApplication {
public static void main(String[] args) {
SpringApplication.run(EduApplication.class,args);
}
}
第四步:重新启动项目
日志输出如下:
启动了3个项目,注册中心如图
边栏推荐
- JMeter interface automation - how to solve the content type conflict of request headers
- LeetCode 刷题 第一天
- `this.$emit` 子组件给父组件传递多个参数
- Interceptor interceptor
- LeetCode 刷题 第三天
- Blog Garden beautification tutorial
- Unity学习笔记(刚体-物理-碰撞器-触发器)
- C static method and non static method
- How to generate random numbers with standard distribution or Gaussian distribution
- Nacos基本概念和单机部署
猜你喜欢

LeetCode 刷题 第二天

Unity学习笔记(刚体-物理-碰撞器-触发器)

Performance analysis of continuous time system (1) - performance index and first and second order analysis of control system

「测试新手百科」5 分钟快速上手Pytest 自动化测试框架

Full automatic breast pump chip dltap703sd

Low noise anion fan touch IC

Sentinel1.8.4 persistent Nacos configuration

Unity-显示Kinect深度数据

During the interface test, connect to the database and back up, restore and verify the data source

MySQL 03 高级查询(一)
随机推荐
During the interface test, connect to the database and back up, restore and verify the data source
【微信小程序】项目实战—抽签应用
IDEA成功连接Database但不显示表怎么办
Kinect for Unity3d----KinectManager
npm的身份证和依赖
大冤种们,新进测试行业,如何正确选择意向企业?
SSM项目使用过滤器实现登录监听
WPS turns off annoying advertisements
MongoDB
Docker - docker installation, MySQL installation on docker, and project deployment on docker
MySQL 05 stored procedure
Unity learning notes (realize the conveyor belt)
express
MySQL 04 高级查询(二)
Leetcode brushes questions the next day
Jmeter接口自动化-如何解决请求头Content-Type冲突问题
连续时间系统的性能分析(2)-二阶系统性能改善方式PID,PR
MySQL 01 关系型数据库设计
CMD command
PHP string operation