### Get Configuration and Sign Listener Example Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage Example demonstrating how to get configuration content and register a listener. The listener's receiveConfigInfo method will be called upon configuration changes. A timeout is specified for the initial retrieval. ```java try { String serverAddr = "{serverAddr}"; String dataId = "{dataId}"; String group = "{group}"; Properties properties = new Properties(); properties.put("serverAddr", serverAddr); ConfigService configService = NacosFactory.createConfigService(properties); String content = configService.getConfigAndSignListener(dataId, group, 5000, new Listener() { @Override public void receiveConfigInfo(String configInfo) { System.out.println("recieve1:" + configInfo); } @Override public Executor getExecutor() { return null; } }); System.out.println(content); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Get Subscribed Services Example Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage This example demonstrates how to obtain and print the list of services the client is currently subscribed to. ```java NamingService naming = NamingFactory.createNamingService(System.getProperty("serveAddr")); System.out.println(naming.getSubscribeServices()); ``` -------------------------------- ### Start Envoy Client Source: https://nacos.io/docs/latest/ecology/use-nacos-with-istio Command to start the Envoy client container. Ensure Envoy is installed or available as a Docker image. ```bash docker start envoy ``` -------------------------------- ### Get Paginated Service List Example Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage This example shows how to fetch a paginated list of services using the `getServicesOfServer` method. It prints the total count and the data for the requested page. ```java NamingService naming = NamingFactory.createNamingService(System.getProperty("serveAddr")); // 等价于`naming.getServicesOfServer(1, 10, "DEFAULT_GROUP");` ListView result = naming.getServicesOfServer(1, 10); System.out.println(result.getCount()); System.out.println(result.getData()); ``` -------------------------------- ### Install Grafana on Mac Source: https://nacos.io/docs/latest/guide/admin/monitor-guide Commands to install and start Grafana using Homebrew. ```bash brew install grafana brew services start grafana ``` -------------------------------- ### Publish Configuration Example Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage Example demonstrating how to initialize the Nacos ConfigService and publish a configuration. Ensure server address, dataId, and group are correctly set. ```java try { // Initialize configuration service, console automatically obtains the following parameters through the example code String serverAddr = "{serverAddr}"; String dataId = "{dataId}"; String group = "{group}"; Properties properties = new Properties(); properties.put("serverAddr", serverAddr); ConfigService configService = NacosFactory.createConfigService(properties); boolean isPublishOk = configService.publishConfig(dataId, group, "content"); System.out.println(isPublishOk); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Install Grafana on Linux Source: https://nacos.io/docs/latest/guide/admin/monitor-guide Commands to install and start Grafana via yum. ```bash sudo yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.4-1.x86_64.rpm sudo service grafana-server start ``` -------------------------------- ### Install Nacos Go SDK Source: https://nacos.io/docs/latest/manual/user/go-sdk/usage Use `go get` to install the Nacos Go SDK. Ensure you are using Go version 1.15 or later and Nacos version 2.x or later. ```bash $ go get -u github.com/nacos-group/nacos-sdk-go/v2 ``` -------------------------------- ### Response Example for Import MCP Tools Source: https://nacos.io/docs/latest/manual/admin/console-api Example of a successful response after importing MCP tools, showing the tool's metadata. ```json { "code" : 0, "message" : "success", "data" : [ { "name" : "getNacosInformation", "description" : "Get nacos detail information by nacos cluster name, the information includes nacos hosts and accessToken, accessToken is optional.", "inputSchema" : { "type" : "object", "properties" : { "arg0" : { "type" : "string", "description" : "nacos cluster name" } }, "required" : [ "arg0" ], "additionalProperties" : false } } ] } ``` -------------------------------- ### Get Configuration Source: https://nacos.io/docs/latest/quickstart/quick-start-docker Retrieve a configuration using a `curl` command. This example fetches the configuration with `dataId` `quickstart.test.config` and `groupName` `test`. ```APIDOC ## Get Configuration Retrieve a configuration using a `curl` command. This example fetches the configuration with `dataId` `quickstart.test.config` and `groupName` `test`. ```bash curl -X GET 'http://127.0.0.1:8848/nacos/v3/client/cs/config?dataId=quickstart.test.config&groupName=test' ``` ``` -------------------------------- ### Java SDK - Get All Instances Source: https://nacos.io/docs/latest/guide/user/parameters-check Example of retrieving all instances for a service, potentially filtered by clusters, using the Java SDK. This method is subject to parameter validation rules. ```java List getAllInstances(String serviceName, List clusters) throws NacosException; ``` -------------------------------- ### Example Usage for Getting MCP Service Details Source: https://nacos.io/docs/latest/manual/admin/maintainer-sdk Shows how to retrieve MCP service details using various combinations of parameters like service name, version, namespace, and mcpId. Includes error handling for NacosException. ```java try { McpServerDetailInfo result = aiMaintainerService.getMcpServerDetail("test"); result = aiMaintainerService.getMcpServerDetail("test", "1.0.0"); result = aiMaintainerService.getMcpServerDetail("public", "test", "1.0.0"); result = aiMaintainerService.getMcpServerDetail("public", "test", null, "1.0.0"); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Start NacosSync Server Source: https://nacos.io/docs/latest/ecology/use-nacos-sync Start the NacosSync server using the provided startup script. The 'restart' option ensures a fresh start. ```bash $ nacosSync/bin: sh startup.sh restart ``` -------------------------------- ### Prompt Query Response Example Source: https://nacos.io/docs/latest/manual/user/open-api Example of a successful response when querying for a prompt. ```json { "code": 0, "message": "success", "data": { "promptKey": "myPrompt", "version": "1.0", "template": "You are a helpful assistant.", "md5": "..." } } ``` -------------------------------- ### Batch Update Instance Metadata Example Source: https://nacos.io/docs/latest/manual/admin/maintainer-sdk This example demonstrates how to perform a batch update of instance metadata. It shows how to define the service, the target instances (identified by IP and port), and the new metadata to be applied. ```java try { Service service = new Service(); service.setNamespaceId(Constants.DEFAULT_NAMESPACE_ID); service.setGroupName(Constants.DEFAULT_GROUP); service.setName("maintain.client.test"); Instance instance = new Instance(); instance.setIp("127.0.0.1"); instance.setPort(8080); Map newMetadata = Collections.singletonMap("testK", "testV"); InstanceMetadataBatchResult result = namingMaintainService.batchUpdateInstanceMetadata(service, Collections.singletonList(instance), newMetadata); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Combined Request and Response Template Example Source: https://nacos.io/docs/latest/manual/user/ai/mcp-template A comprehensive example chaining requestTemplate, argsPosition, and responseTemplate. Demonstrates dynamic URL construction with path and query parameters, and response body formatting. ```json { "requestTemplate": { "url": "/users/{{ userId }}/orders?lang={{ .args.lang }}&key={{ ${nacos.appKey/amap}.data }}", "method": "GET" }, "argsPosition": { "userId": "path", "lang": "query", "traceId": "header" }, "responseTemplate": { "body": "用户:{{ .user.name }} 订单数:{{ len .orders }} " } } ``` -------------------------------- ### Subscribe and Unsubscribe with Selector Example Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage This example demonstrates how to subscribe to service instances based on an IP selector and then unsubscribe using the same parameters. It highlights the use of NamingSelectorFactory and EventListener. ```java NamingService naming = NamingFactory.createNamingService(System.getProperty("serveAddr")); EventListener serviceListener = event -> { if (event instanceof NamingEvent) { System.out.println(((NamingEvent) event).getServiceName()); System.out.println(((NamingEvent) event).getInstances()); } }; // 只会选择订阅ip为`127.0`开头的实例。 NamingSelector selector = NamingSelectorFactory.newIpSelector("127.0.*"); naming.subscribe("nacos.test.service", "DEFAULT_GROUP", selector, serviceListener); naming.unsubscribe("nacos.test.service", "DEFAULT_GROUP", selector, serviceListener); ``` -------------------------------- ### Remove Configuration Example Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage Example demonstrating how to initialize the Nacos ConfigService and remove a configuration. The operation will return true even if the configuration does not exist. ```java try { // Initialize configuration service, console automatically obtains the following parameters through the example code String serverAddr = "{serverAddr}"; String dataId = "{dataId}"; String group = "{group}"; Properties properties = new Properties(); properties.put("serverAddr", serverAddr); ConfigService configService = NacosFactory.createConfigService(properties); boolean isRemoveOk = configService.removeConfig(dataId, group); System.out.println(isRemoveOk); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Example: Unsubscribe Agent Card using Nacos Java SDK Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage This example demonstrates initializing the AiService, subscribing to an agent card, and then unsubscribing using the same listener. It covers both latest and specific version unsubscriptions. ```java Properties properties = new Properties(); properties.setProperty(PropertyKeyConst.SERVER_ADDR, "{serverAddr}"); AiService aiService = AiFactory.createAiService(properties); AbstractNacosAgentCardListener listener = new AbstractNacosAgentCardListener() {}; try { aiService.subscribeAgentCard("test", listener); aiService.unsubscribeAgentCard("test", listener); aiService.unsubscribeAgentCard("test", "", listener); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Example Usage of Fuzzy Subscription Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage This example demonstrates how to initialize the Nacos naming service and use the `fuzzyWatchWithServiceKeys` method to subscribe to services with fuzzy patterns, including handling events and capacity limits. ```APIDOC ### Request Example ```java try { // Initialize configuration service. Obtain the following parameters automatically from the console example code. String serverAddr = "{serverAddr}"; String serviceNamePattern = "service*"; String groupPattern = "group*"; Properties properties = new Properties(); properties.put("serverAddr", serverAddr); properties.put("namespace", "mynamespaceId"); NamingService namingService = NacosFactory.createNamingService(properties); Future> future = namingService.fuzzyWatchWithServiceKeys(serviceNamePattern, groupPattern, new AbstractFuzzyWatchEventWatcher() { @Override public void onEvent(FuzzyWatchChangeEvent event) { System.out.println(event.toString()); } @Override public void onPatternOverLimit() { System.out.println("pattern service over limit "); } @Override public void onServiceReachUpLimit() { System.out.println("pattern service over limit "); } }); } catch (NacosException e) { e.printStackTrace(); } ``` ``` -------------------------------- ### Start Nacos using Docker Compose (Standalone MySQL) Source: https://nacos.io/docs/latest/quickstart/quick-start-docker Initializes the MySQL database and then starts a Nacos standalone instance using a Docker Compose file configured for MySQL. Ensure the mysql-init.sh script is executable. ```bash ./mysql-init.sh && docker-compose -f standalone-mysql.yaml up ``` -------------------------------- ### Get Nacos Console Guide Content Response Source: https://nacos.io/docs/latest/manual/admin/console-api Example response when requesting Nacos console guide content. It indicates whether the console UI is enabled and provides a link to documentation. ```json { "code": 0, "message": "success", "data": "当前节点已关闭Nacos开源控制台使用,请修改application.properties中的nacos.console.ui.enabled参数为true打开开源控制台使用,详情查看文档中关于关闭默认控制台部分。" } ``` -------------------------------- ### Example Usage for Listing MCP Services Source: https://nacos.io/docs/latest/manual/admin/maintainer-sdk Demonstrates how to call the listMcpServer methods with different parameters and handle potential NacosExceptions. Includes examples for fetching all services, paginated services, services by name, and services by namespace and name. ```java try { Page result = aiMaintainerService.listMcpServer(); result = aiMaintainerService.listMcpServer(1, 100); result = aiMaintainerService.listMcpServer("", 1, 100); result = aiMaintainerService.listMcpServer("public", "", 1, 100); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Execute Quick Start Script Source: https://nacos.io/docs/latest/quickstart/quick-start-kubernetes Run the quick-startup.sh script to deploy Nacos on Kubernetes. Ensure the script has execute permissions. ```bash cd nacos-k8s chmod +x quick-startup.sh ./quick-startup.sh ``` -------------------------------- ### List Configurations using a Specific Profile Source: https://nacos.io/docs/latest/manual/admin/nacos-cli This command demonstrates using the '--profile' flag to load a specific profile ('prod' in this case) and then lists configurations. ```bash nacos-cli --profile prod config-list ``` -------------------------------- ### 设置Nacos JVM启动参数 Source: https://nacos.io/docs/latest/guide/admin/system-configurations 在startup.sh脚本中通过JAVA_OPT变量设置JVM参数,例如配置nacos.home路径。 ```bash JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}" ``` -------------------------------- ### Get Console Guide Information Source: https://nacos.io/docs/latest/manual/admin/console-api Retrieves the guide information for the Nacos console. This is typically called when closing the Nacos console UI. ```APIDOC ## GET /v3/console/server/guide ### Description Retrieves the guide information for the Nacos console. This is typically called when closing the Nacos console UI. ### Method GET ### Endpoint /v3/console/server/guide ### Parameters No parameters are required for this request. ### Request Example ```curl curl -X GET 'http://127.0.0.1:8080/v3/console/server/guide' ``` ### Response #### Success Response (200) - **data** (string) - The console guide content. ``` -------------------------------- ### Start Nacos in Standalone Mode (Linux/Unix/Mac) Source: https://nacos.io/docs/latest/guide/admin/deployment Use this command to start Nacos in standalone mode for testing or single-machine trials. Ensure you are in the Nacos installation directory. ```bash # Standalone means it is non-cluster Mode. $ sh startup.sh -m standalone ``` -------------------------------- ### Start Nacos in Standalone Mode (Windows) Source: https://nacos.io/docs/latest/guide/admin/deployment Use this command to start Nacos in standalone mode on Windows for testing or single-machine trials. Ensure you are in the Nacos installation directory. ```batch # Standalone means it is non-cluster Mode. $ cmd startup.cmd -m standalone ``` -------------------------------- ### Register Instance (Example for Update) Source: https://nacos.io/docs/latest/manual/admin/maintainer-sdk This example demonstrates how to register an instance, which can be used to update an existing instance's properties like 'enabled' status. It shows variations for different scopes (default group, specific namespace). ```java try { Instance instance = new Instance(); instance.setIp("127.0.0.1"); instance.setPort(8080); instance.setEphemeral(false); instance.setEnabled(false); # 以下请求均给更新服务`maintain.client.test`下的一个实例,实例的ip为`127.0.0.1`,端口为`8080`, 将实例的`enabled`修改为`false`。 String result = namingMaintainService.registerInstance("maintain.client.test", instance); result = namingMaintainService.registerInstance(Constants.DEFAULT_GROUP,"maintain.client.test", instance); result = namingMaintainService.registerInstance(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "maintain.client.test", instance); Service service = new Service(); service.setNamespaceId(Constants.DEFAULT_NAMESPACE_ID); service.setGroupName(Constants.DEFAULT_GROUP); service.setName("maintain.client.test"); result = namingMaintainService.registerInstance(service, instance); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Get Configuration Source: https://nacos.io/docs/latest/manual/user/go-sdk/usage Retrieves the content of a configuration. ```go content, err := configClient.GetConfig(vo.ConfigParam{ DataId: "dataId", Group: "group"}) ``` -------------------------------- ### Example: Fuzzy Service Subscription with Capacity Limit Handling Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage Demonstrates how to initiate a fuzzy subscription and handle potential capacity limit events using an anonymous inner class implementing FuzzyWatchEventWatcher and FuzzyWatchLoadWatcher. ```java try { // 初始化配置服务,控制台通过示例代码自动获取下面参数 String serverAddr = "{serverAddr}"; String serviceNamePattern = "service*"; String groupPattern = "group*"; Properties properties = new Properties(); properties.put("serverAddr", serverAddr); properties.put("namespace", "mynamespaceId"); Future> future = namingService.fuzzyWatchWithServiceKeys(serviceNamePattern, groupPattern, new AbstractFuzzyWatchEventWatcher() { @Override public void onEvent(FuzzyWatchChangeEvent event) { System.out.println(event.toString()); } @Override public void onPatternOverLimit() { System.out.println("pattern service over limit "); } @Override public void onServiceReachUpLimit() { System.out.println("pattern service over limit "); } }); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### 启动 Nacos 服务器 (Linux/Unix/Mac) Source: https://nacos.io/docs/latest/quickstart/quick-start 使用 startup.sh 脚本启动 Nacos 服务,-m standalone 参数表示单机模式运行。 ```bash sh startup.sh -m standalone ``` ```bash bash startup.sh -m standalone ``` -------------------------------- ### Get Nacos Console Guide Content (API) Source: https://nacos.io/docs/latest/manual/admin/console-api Use this endpoint to retrieve Nacos console guide information. This is called by the default Nacos console UI when it's closed. Requires no authentication. ```bash curl -X GET 'http://127.0.0.1:8080/v3/console/server/guide' ``` -------------------------------- ### Get Nacos Console Liveness Status Response Source: https://nacos.io/docs/latest/manual/admin/console-api Example response for the Nacos console liveness status. A 'ok' response indicates the console is functioning correctly. ```json { "code": 0, "message": "success", "data": "ok" } ``` -------------------------------- ### Implement Dubbo Provider Bootstrap Source: https://nacos.io/docs/latest/ecology/use-nacos-with-dubbo Main class to load the XML context and start the Dubbo provider. ```java package com.alibaba.nacos.example.dubbo.provider; import com.alibaba.dubbo.demo.service.DemoService; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.io.IOException; /** * {@link DemoService} provider demo XML bootstrap */ public class DemoServiceProviderXmlBootstrap { public static void main(String[] args) throws IOException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); context.setConfigLocation("/META-INF/spring/dubbo-provider-context.xml"); context.refresh(); System.out.println("DemoService provider (XML) is starting..."); System.in.read(); } } ``` -------------------------------- ### Get Nacos Namespace List Response Source: https://nacos.io/docs/latest/manual/admin/console-api Example response for the Nacos namespace list. It includes namespace ID, name, description, configuration count, quota, and type. ```json { "code": 0, "message": "success", "data": [ { "namespace": "public", "namespaceShowName": "public", "namespaceDesc": "Default Namespace", "quota": 200, "configCount": 0, "type": 0 } ] } ``` -------------------------------- ### Example Usage for Searching MCP Services Source: https://nacos.io/docs/latest/manual/admin/maintainer-sdk Illustrates how to use the searchMcpServer methods to find MCP services, including examples for searching with no specific name, with pagination, and with namespace and name filtering. Catches NacosException for error handling. ```java try { Page result = aiMaintainerService.searchMcpServer(""); result = aiMaintainerService.searchMcpServer("", 1, 100); result = aiMaintainerService.searchMcpServer("public", "", 1, 100); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Deploy NFS-Client Provisioner Source: https://nacos.io/docs/latest/manual/admin/deployment/deployment-cluster Create the ServiceAccount and deploy the NFS-Client Provisioner. ```bash kubectl create -f deploy/nfs/deployment.yaml ``` -------------------------------- ### 启动 Nacos-bootstrap Source: https://nacos.io/docs/latest/contribution/source-code-run-and-start 使用 startup.sh 脚本以 merged 模式启动 Nacos。 ```bash distribution/target/nacos-server-${version}/nacos/bin/startup.sh -m standalone -d merged ``` -------------------------------- ### Get Nacos Node Running Information Response Source: https://nacos.io/docs/latest/manual/admin/console-api Example response detailing Nacos node information, including IP, port, state, raft metadata, and supported abilities. ```json { "code": 0, "message": "success", "data": [ { "ip": "127.0.0.1", "port": 8848, "state": "UP", "extendInfo": { "lastRefreshTime": 1733221062619, "raftMetaData": { "metaDataMap": { "naming_instance_metadata": { "leader": "127.0.0.1:7848", "raftGroupMember": [ "127.0.0.1:7848" ], "term": 1 }, "naming_persistent_service": { "leader": "127.0.0.1:7848", "raftGroupMember": [ "127.0.0.1:7848" ], "term": 1 }, "naming_persistent_service_v2": { "leader": "127.0.0.1:7848", "raftGroupMember": [ "127.0.0.1:7848" ], "term": 1 }, "naming_service_metadata": { "leader": "127.0.0.1:7848", "raftGroupMember": [ "127.0.0.1:7848" ], "term": 1 } } }, "raftPort": "7848", "readyToUpgrade": true, "supportGrayModel": true, "version": "3.0.0-SNAPSHOT" }, "address": "127.0.0.1:8848", "failAccessCnt": 0, "abilities": { "remoteAbility": { "supportRemoteConnection": true, "grpcReportEnabled": true }, "configAbility": { "supportRemoteMetrics": false }, "namingAbility": { "supportJraft": true } }, "grpcReportEnabled": true } ] } ``` -------------------------------- ### Query System Switches (HTTP GET) Source: https://nacos.io/docs/latest/guide/user/open-api Use this endpoint to retrieve the current status of Nacos system switches. No specific setup is required beyond having a running Nacos instance. ```bash curl -X GET 'http://127.0.0.1:8848/nacos/v2/ns/operator/switches' ``` -------------------------------- ### Discover Service Source: https://nacos.io/docs/latest/quickstart/quick-start-docker Discover registered services using a `curl` command. This example retrieves a list of instances for the service named `quickstart.test.service`. ```APIDOC ## Discover Service Discover registered services using a `curl` command. This example retrieves a list of instances for the service named `quickstart.test.service`. ```bash curl -X GET 'http://127.0.0.1:8848/nacos/v3/client/ns/instance/list?serviceName=quickstart.test.service' ``` ``` -------------------------------- ### Run Nacos CLI with Default Settings (Interactive Wizard) Source: https://nacos.io/docs/latest/manual/admin/nacos-cli Execute Nacos CLI without any arguments. If no profile is found, it will automatically launch an interactive wizard to guide the user through setup and create the default profile. ```bash # 不传任何参数时,自动进入交互向导生成 default profile,并连接其中的服务器 nacos-cli ``` -------------------------------- ### Example: Subscribe to Agent Card using Nacos Java SDK Source: https://nacos.io/docs/latest/manual/user/java-sdk/usage This example shows how to initialize the AiService and subscribe to agent card updates, both for the latest version and a specific version. It includes a basic listener implementation. ```java Properties properties = new Properties(); properties.setProperty(PropertyKeyConst.SERVER_ADDR, "{serverAddr}"); AiService aiService = AiFactory.createAiService(properties); try { aiService.subscribeAgentCard("test", new AbstractNacosAgentCardListener() { @Override public void onEvent(NacosAgentCardEvent event) { System.out.println("---------------agent card listener called start--------------- "); System.out.println(JacksonUtils.toJson(event.getAgentCard())); System.out.println("---------------agent card listener called end--------------- "); } }); aiService.subscribeAgentCard("test", "", new AbstractNacosAgentCardListener() { @Override public void onEvent(NacosAgentCardEvent event) { System.out.println("---------------agent card listener called start--------------- "); System.out.println(JacksonUtils.toJson(event.getAgentCard())); System.out.println("---------------agent card listener called end--------------- "); } }); } catch (NacosException e) { e.printStackTrace(); } ``` -------------------------------- ### Install Nacos CLI via npm Source: https://nacos.io/docs/latest/manual/admin/nacos-cli Install Nacos CLI globally using npm if you have Node.js installed. This command also shows how to verify the installation. ```bash # npm 全局安装 npm install -g @nacos-group/cli nacos-cli --help # 或使用 npx 免安装直接使用 npx @nacos-group/cli --help ``` -------------------------------- ### Install Nacos CLI via Official Script (Windows PowerShell) Source: https://nacos.io/docs/latest/manual/admin/nacos-cli Install Nacos CLI on Windows using PowerShell with the official installation script. This method downloads, executes, and cleans up the installer. ```powershell iwr -UseBasicParsing https://nacos.io/nacos-installer.ps1 -OutFile $env:TEMP\nacos-installer.ps1; & $env:TEMP\nacos-installer.ps1 -cli; Remove-Item $env:TEMP\nacos-installer.ps1 ``` -------------------------------- ### Use Explicitly Specified Configuration File Source: https://nacos.io/docs/latest/manual/admin/nacos-cli This example shows how to use the '--config' flag to load settings from a specific configuration file, overriding profile and environment variable settings. ```bash # 显式指定配置文件 nacos-cli --config /path/to/custom.conf skill-list ``` -------------------------------- ### Install Nacos CLI via Official Script (Linux/macOS) Source: https://nacos.io/docs/latest/manual/admin/nacos-cli Use this command to install Nacos CLI on Linux or macOS systems using the official installation script. This is the recommended and simplest installation method. ```bash curl -fsSL https://nacos.io/nacos-installer.sh | bash -s -- --cli ``` -------------------------------- ### 验证运行环境 Source: https://nacos.io/docs/latest/contribution/source-code-run-and-start 检查 Java、Maven 和 MySQL 是否已正确安装并配置。 ```bash java -version mvn -v mysql -V ``` -------------------------------- ### Java SDK Authentication Example Source: https://nacos.io/docs/latest/guide/user/auth Initialize the Nacos configuration service with server address, username, and password for authentication. ```java try { // Initialize the configuration service, and the console automatically obtains the following parameters through the sample code. String serverAddr = "{serverAddr}"; Properties properties = new Properties(); properties.put("serverAddr", serverAddr); // if need username and password to login properties.put("username","nacos"); properties.put("password","nacos"); ConfigService configService = NacosFactory.createConfigService(properties); } catch (NacosException e) { // TODO Auto-generated catch block e.printStackTrace(); } ``` -------------------------------- ### Start Prometheus Service Source: https://nacos.io/docs/latest/guide/admin/monitor-guide Commands to start Prometheus on different operating systems. ```bash ./prometheus --config.file="prometheus.yml" ``` ```bash prometheus.exe --config.file=prometheus.yml ``` -------------------------------- ### Start Nacos using Docker Compose (Standalone MySQL) Source: https://nacos.io/docs/latest/quickstart/quick-start-docker Start Nacos services using Docker Compose with the `standalone-mysql.yaml` configuration file. This involves initializing the MySQL database before starting the Nacos services. ```APIDOC ## Start Nacos using Docker Compose (Standalone MySQL) Start Nacos services using Docker Compose with the `standalone-mysql.yaml` configuration file. This involves initializing the MySQL database before starting the Nacos services. ```bash cd example ./mysql-init.sh && docker-compose -f standalone-mysql.yaml up ``` ``` -------------------------------- ### 启动 Nacos 服务器 (Windows) Source: https://nacos.io/docs/latest/quickstart/quick-start 使用 startup.cmd 脚本启动 Nacos 服务,-m standalone 参数表示单机模式运行。 ```cmd startup.cmd -m standalone ``` -------------------------------- ### Start Nacos Server Source: https://nacos.io/docs/latest/ecology/use-nacos-with-istio Command to start the Nacos server in standalone mode with embedded configurations. ```bash startup.sh -m standalone -p embedded ``` -------------------------------- ### Query Gray Configuration Details using GET Source: https://nacos.io/docs/latest/manual/admin/admin-api Retrieve details of a specific gray configuration. Requires administrator privileges. ```bash curl -X GET 'http://127.0.0.1:8848/nacos/v3/admin/cs/config/gray?namespaceId=public&groupName=DEFAULT_GROUP&dataId=example&grayName=gray' ``` -------------------------------- ### Verify Nacos CLI Installation Source: https://nacos.io/docs/latest/manual/admin/nacos-cli Run this command to verify that Nacos CLI has been installed correctly and is accessible from your terminal. ```bash nacos-cli --help ``` -------------------------------- ### Nacos API Response Example Source: https://nacos.io/docs/latest/guide/user/open-api Example of a successful response from a Nacos API endpoint, showing the structure of returned data. ```json { "code": 0, "message": "success", "data": [ { "clientId": "1664527125645_127.0.0.1_4443", "ip": "10.128.164.35", "port": 0 }, { "clientId": "172.24.144.1:54126#true", "ip": "172.24.144.1", "port": 54126 } ] } ``` ```json { "code": 0, "message": "success", "data": [ { "namespace": "", "namespaceShowName": "public", "namespaceDesc": null, "quota": 200, "configCount": 1, "type": 0 } ] } ``` -------------------------------- ### Select All Instances Source: https://nacos.io/docs/latest/manual/user/go-sdk/usage Returns all instances for a service, regardless of health or status. ```go // SelectAllInstance可以返回全部实例列表,包括healthy=false,enable=false,weight<=0 instances, err := namingClient.SelectAllInstances(vo.SelectAllInstancesParam{ ServiceName: "demo.go", GroupName: "group-a", // 默认值DEFAULT_GROUP Clusters: []string{"cluster-a"}, // 默认值DEFAULT }) ``` -------------------------------- ### Publish Configuration Source: https://nacos.io/docs/latest/quickstart/quick-start-docker Publish a configuration using a `curl` command. This requires an `accessToken` obtained from the login endpoint. This example publishes a configuration with `dataId` `quickstart.test.config`, `groupName` `test`, and content `HelloWorld`. ```APIDOC ## Publish Configuration Publish a configuration using a `curl` command. This requires an `accessToken` obtained from the login endpoint. This example publishes a configuration with `dataId` `quickstart.test.config`, `groupName` `test`, and content `HelloWorld`. ```bash curl -X POST 'http://127.0.0.1:8848/nacos/v3/admin/cs/config?dataId=quickstart.test.config&groupName=test&content=HelloWorld' -H "accessToken:${your_access_token}" ``` ``` -------------------------------- ### AgentSpec Retrieval Response Example Source: https://nacos.io/docs/latest/manual/user/open-api Example of a response when retrieving an AgentSpec. The 'data' field may be empty if no matching AgentSpec is found. ```json { "code": 0, "message": "success", "data": {} } ``` -------------------------------- ### Run the Nacos CoreDNS Plugin Source: https://nacos.io/docs/latest/ecology/use-nacos-with-coredns Command to start the CoreDNS binary with the specified configuration file and port. ```bash $GOPATH/src/coredns/coredns -conf $path_to_corefile -dns.port $dns_port ```