The prefaceAttention:

Nacos, which requires both the JDK and Maven environment, will report errors requiring Tomcat if there is no Maven environment and will need to configure the mysql database: import SQL into the conf file and modify application.properties

Nacos relies on the Java environment to run. If you are building and running Nacos from code and need to configure the Maven environment for this, make sure it is installed in the following versions of the environment:

  1. 64-bit OS: Supports Linux, Unix, Mac, and Windows. Linux, Unix, and Mac are recommended.
  2. 64-bit JDK 1.8+; Download & configure.
  3. Maven 3.2 x +; Download & configure.

Download the source code from Github

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

// change the $version to your actual path
cd distribution/target/nacos-server-$version/nacos/bin
Copy the code

If you don’t have a ladder, you can download the Linux package, import it, and then decompress it

Gz -c directory Run the following command: centos CD nacos CD bin sh startup.sh -m standalone Run the ubuntu CD nacos CD bin bash command Sh -m standalone Run the win startup. CMD -m standalone commandCopy the code

Setup of the configuration center

1: Enable the configuration center

Two: Create a configuration file

The name of the Data Id is your project name-context-config file type

In nacos-server, create a new configuration where Data ID is defined as follows: ${prefix}-${spring.profiles.active}.${file-extension} prefix defaults to the value of spring.application.name, But can be by spring configuration items. Cloud. Nacos. Config. The prefix to configuration. Spring.profiles. Active is the profile corresponding to the current environment. You can configure it by running the configuration item spring.profiles. File - exetension as the configuration of content data format, can be configured a spring. Cloud. Nacos. Config. The file - the extension to the configuration. Currently, only properties and YAML types are supported. Note: When spring.profiles. Active is empty, the corresponding connection - will also not exist and the dataId concatenation format will change to prefix.{prefix}.prefix.{file-extension}Copy the code

Three: Use (dynamically update configuration files)

Look at the bootstrapt.application configuration file,

The namespace

Namespace ID

The registered address

Click publish to dynamically update the configuration file bootstrapt.application

Nacos SpringCloud integration

Import dependencies:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.32..RELEASE</version> </parent> <! <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.21..RELEASE</version> </dependency> <! <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>2.21..RELEASE</version>
</dependency>
Copy the code

Bootstapt. yml file configuration:

   Note: write to as needed bootstapt.yml Because this file was loaded first   

spring:
  application:
    name: feiyu-gatway
  cloud:
    nacos:
      discovery: Service registration and discovery
        server-addr: 127.0. 01.: 8848
        namespace: 00ed4f35-eadd-4cfb-a266-d0dc41be5415
      config:    Dynamic service configuration
        server-addr: 127.0. 01.: 8848 # Service address
        file-extension: yml # Dynamic file configuration type
        namespace: 00ed4f35-eadd-4cfb-a266-d0dc41be5415 # Namespace ID
  profiles: 
    active: dev # Namespace
Copy the code

File configuration needs to be added — if an error is reported

@Bean
public IClientConfig iClientConfig(a) {
    return new DefaultClientConfigImpl();
}
Copy the code