Nacos下载和安装
1. 下载地址
下载地址:https://github.com/alibaba/nacos/releases
下载版本:nacos-server-1.1.4.tar.gz或nacos-server-1.1.4.zip,解压任意目录即可
------注:当前SpringBoot版本为2.2.1.RELEASE
2. 启动
1.Linux/Unix/Mac
----启动命令:sh startup.sh -m standalone (standalone代表着单机模式运行,非集群模式)
2.Windows
----启动命令:cmd startup.cmd 或者双击startup.cmd运行文件。
3. 访问
访问地址:http://localhost:8848/nacos
用户名密码:nacos/nacos
服务注册
1. 引入依赖
----工程结构:
guli_parent
common (公共模块)
service (服务模块)
service-edu (模块1--主要业务模块)
service-oss (模块2--文件模块)
service-vod (模块3--视频模块)
----guli_parent设置依赖版本
<properties>
<cloud-alibaba.version>0.2.2.RELEASE</cloud-alibaba.version>
</properties>
<dependencyManagement>
<dependencies>
<!--Spring Cloud 当前SpringBoot版本为2.2.1.RELEASE-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
----service模块引入依赖
<!--服务注册-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
2. application配置
# 服务名 该名称会显示在Nacos中的服务列表
spring.application.name=service-edu # 服务名不要加下划线"_"
......
# nacos服务地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
3. 加启动注解
在微服务启动类上加此注解:
@EnableDiscoveryClient
4. Nacos服务列表