首先安装好nacos之后直接引入客户端依赖和配置文件,同时把eureka的内容去掉
从nacos官网 https://nacos.io/zh-cn/index.html 下载安装包
下载好之后解压,打开配置文件 conf/application.properties 配置一下mysql和地址,其他的的按需配置
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://db:port/nacos-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user=root
db.password=root
nacos集群地址
vim conf/cluster.conf
192.168.1.2:8848
192.168.1.3:8848
配置之后启动就好了
./startup.sh
./startup.sh-m standalone //如果是单机带个参数
注意spring cloud 版本问题,如果不对会出现一些不兼容
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env-name>local</env-name>
<port>8006</port>
<nacos-config-url>nacos.url</nacos-config-url>
<nacos-register-url>nacos.url</nacos-register-url>
</properties>
</profile>
</profiles>
server:
address: 0.0.0.0
port: 18006
spring:
profiles:
active: @env-name@
application:
name: api-@artifactId@
cloud:
nacos:
discovery:
server-addr: @nacos-register-url@
config:
server-addr: @nacos-config-url@
file-extension: yml