Cloud Native 7 min read

Advanced Nacos: Service Cluster Setup, Configuration Loading Order, and Common Issues

This guide explains how to build a Nacos service cluster, configure providers and consumers, write the necessary Spring Cloud Nacos YAML and Java controller code, detail the steps for setting up multiple Nacos nodes, and troubleshoot typical startup errors.

Java Captain
Java Captain
Java Captain
Advanced Nacos: Service Cluster Setup, Configuration Loading Order, and Common Issues

Advanced Nacos

1. Service Cluster Requirements

Service providers must be deployed in a cluster, and service consumers should be able to display information of each service instance in the cluster.

Provider Controller Modification

Update the provider's controller to print the server port:

package com.czxy.controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@RestController
public class EchoController {
@Resource
private HttpServletRequest request;
@RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
public String echo(@PathVariable String string) {
int serverPort = request.getServerPort();
return "Hello Nacos Discovery " + string + ":" + serverPort;
}
}

YAML Configuration for Provider

Two example configurations are shown, one for port 8170 and another for port 8270. Both set the Spring application name and point to the Nacos discovery server:

# Port number
server:
  port: 8170
spring:
  application:
    name: service-provider  # Service name
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848  # Nacos address

2. Loading Configuration File Order

Nacos supports three ways to load DataId configurations, with the newer properties replacing the deprecated ones:

A: Shared configuration (deprecated) – spring.cloud.nacos.config.shared-dataids, spring.cloud.nacos.config.refreshable-dataids
B: Extension configuration (deprecated) – spring.cloud.nacos.config.ext-config[n]
C: Internal rule concatenation – spring.cloud.nacos.config.prefix, spring.cloud.nacos.config.file-extension, spring.cloud.nacos.config.group

3. Nacos Cluster Setup

Overview

A cluster requires three or more Nacos nodes. You can use the built‑in data source or an external MySQL data source. When configuring multiple nodes on a single host, ports must not be consecutive (e.g., 8841/8843/8845 is valid, 8841/8842/8843 is not).

Configuration Steps

For each node, copy the original Nacos directory, rename it (e.g., nacos-2.1.0-8841 ), modify the port, configure the data source, copy and rename conf/cluster.conf.example to cluster.conf , and start the service with startup.cmd .

Node 1 (Port 8841)

Copy Nacos and rename to nacos-2.1.0-8841 .

Configure the data source.

Change the port to 8841.

Copy conf/cluster.conf.example to cluster.conf .

Run startup.cmd and verify successful startup.

Node 2 (Port 8843)

Copy the node 1 directory and rename to nacos-2.1.0-8843 .

Change the port to 8843.

Start with startup.cmd .

Node 3 (Port 8845)

Copy the node 1 directory and rename to nacos-2.1.0-8845 .

Change the port to 8845.

Start with startup.cmd .

4. Common Errors and Troubleshooting

db.num is null – caused by missing database configuration.

Unable to start embedded Tomcat – either the cluster configuration file is missing or the installation directory contains non‑ASCII characters.

Memory insufficient – increase the JVM memory allocation.

Cannot determine JNI library name for ARCH='x86' OS='windows 10' name='rocksdb' – caused by a mismatch between Nacos (64‑bit) and the JDK architecture.

JNI library loading error – missing dependent libraries for RocksDB JNI.

Conclusion

The article provides a comprehensive walkthrough of advanced Nacos features, including service clustering, configuration loading order, and troubleshooting tips, helping developers and operations teams to efficiently manage microservice environments.

JavaCloud NativeService DiscoveryConfigurationNacosClusterSpring Cloud
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

login 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.