1、从github下载nacos服务
https://github.com/alibaba/nacos/releases
2、解压启动
解压进入bin目录单例启动:cd nacos/bin
linux:sh startup.sh -m standalone
windows:cmd startup.cmd -m standalone
!!!假如报:ERROR read cluster conf fail 用bash startup.sh -m standalone命令执行。使用sh命令会报错,因而是因为startup.sh文件中的[[ ]] 的问题,sh命令并不能识别,只有bash才行。
3、客户端
添加依赖
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
- 添加注解到启动类
@EnableDiscoveryClient
- 配置文件
server:
port: 18080
spring:
application:
name: service-****
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
网友评论