Spring Cloud Alibaba是阿里巴巴爲分佈式應用提供的一站式解決方案,可以更方便快捷地搭建分佈式平臺,nacos擁有着替換eureka server ,spring cloud config等組件的目標和意圖,旨在可以更簡便快速地去管理服務、註冊服務、管理配置。html
nacos 官方學習文檔: https://nacos.io/zh-cn/docs/quick-start.html
下載nacos: https://github.com/alibaba/nacos/releases
也可使用以下命令安裝並編譯項目:java
git clone https://github.com/alibaba/nacos.git cd nacos/ mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
項目構建完畢後,會在\nacos\distribution\target\ 目錄下生成對應的包:
git
進入到/nacos/bin 目錄下 D:\Program Files\nacos\distribution\target\nacos-server-1.4.2-SNAPSHOT\nacos\bin:
執行命令 startup.cmd -m standalone, 以單例模式啓動nacos服務器:github
cd D:\Program Files\nacos\distribution\target\nacos-server-1.4.2-SNAPSHOT\nacos\bin d: startup.cmd -m standalone
啓動成功後,會出現以下logo:
訪問: http://192.168.31.166:8848/nacos/index.html, 用戶名和密碼都是nacos,登陸成功後,就能夠看到以下的nacos首頁:
web
本身建的項目至關於一個微服務客戶端,在本例中就是一個nacos客戶端,要想將服務註冊到nacos server中,咱們須要作三件事spring
nacos客戶端依賴:apache
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency>
pom.xml文件完整配置:bootstrap
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.8.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.exam.springcloud</groupId> <artifactId>spring-cloud-alibaba</artifactId> <version>0.0.1-SNAPSHOT</version> <name>spring-cloud-alibaba</name> <description>project for Spring Boot</description> <properties> <java.version>1.8</java.version> <spring.cloud.alibaba.version>2.2.1.RELEASE</spring.cloud.alibaba.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine