Cloud Native 12 min read

How to Deploy Nacos Server and Integrate It with Spring Cloud

This guide walks you through installing Nacos Server from source, starting it in standalone mode, using its management console, registering services and configurations via curl, and finally integrating Nacos with a Spring Cloud application for service discovery and config management.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
How to Deploy Nacos Server and Integrate It with Spring Cloud

Nacos Server Deployment from Source

Prerequisites: JDK 1.8+ and Maven 3.2.x+. Clone the official repository, build with Maven profile release-nacos while skipping tests, then locate the generated distribution.

git clone https://github.com/alibaba/nacos.git
cd nacos
mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
ls -al distribution/target/
cd distribution/target/nacos-server-<em>VERSION</em>/nacos/bin

In the bin directory there are startup scripts for Linux/Unix/Mac ( startup.sh), Ubuntu ( bash startup.sh) and Windows ( startup.cmd). Start a single‑node instance with the -m standalone flag:

# Linux/Unix/Mac
sh startup.sh -m standalone
# Ubuntu
bash startup.sh -m standalone
# Windows
startup.cmd -m standalone

Alternatively launch the server programmatically by invoking the main method of the Nacos class and setting the JVM property -Dnacos.standalone=true:

public class Nacos {
    public static void main(String[] args) {
        System.setProperty(Constants.STANDALONE_MODE_PROPERTY_NAME, "true");
        SpringApplication.run(Nacos.class, args);
    }
}

Management Console

When the server starts it prints the console URL. By default the UI is reachable at http://127.0.0.1:8848/nacos/index.html. The default credentials are user nacos and password nacos. The console provides modules for configuration management, service discovery, permission management, namespaces and cluster management.

Nacos console screenshot
Nacos console screenshot

Basic Operations via REST API (cURL)

Register a service instance (the instance will be removed automatically when health checks fail):

curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'

Query registered instances :

curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instance/list?serviceName=nacos.naming.serviceName'

Publish a configuration (dataId, group and content are user‑defined):

curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld"

Retrieve a configuration :

curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test"

Integration with Spring Cloud

Create a Spring Boot project and add Spring Cloud and Spring Cloud Alibaba dependencies. The following pom.xml is a minimal example (Spring Boot 2.4.2, Spring Cloud 2020.0.0, Alibaba Cloud 2021.1):

<project xmlns="http://maven.apache.org/POM/4.0.0"
         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.4.2</version>
    </parent>
    <groupId>com.springcloud</groupId>
    <artifactId>spring-cloud-alibaba-nacos</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>2020.0.0</spring-cloud.version>
        <cloud-alibaba.version>2021.1</cloud-alibaba.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Configure the Nacos discovery address in src/main/resources/application.yml:

spring:
  application:
    name: nacos-spring-cloud-learn
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848

Run the Spring Boot application. The service registers automatically with the Nacos server; the registration can be verified in the console or by the same curl query used earlier.

Key Points

Source‑code deployment provides a clear learning path and ensures consistent module versions.

Standalone mode is started with -m standalone or JVM property -Dnacos.standalone=true.

REST APIs cover service registration, instance query, configuration publishing and retrieval.

Spring Cloud integration requires compatible versions of Spring Boot, Spring Cloud and Alibaba Cloud; compatibility tables are available on the Spring Cloud project site.

The default namespace is public and default credentials are nacos/nacos.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaMicroservicesservice discoveryConfiguration ManagementmavenNacosSpring Cloud
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.