In Nacos’s single node, the standalone mode we started with, the configured data is stored by default in an embedded database called Derby.

If we are going to build a cluster, we must not use an embedded database, otherwise the data will not be shared. When building the cluster, we need to connect the Nacos to Mysql for data storage.

The cluster mode is the same as our usual capacity expansion. It can be forwarded to multiple nodes through Nginx, and a domain name can be hung at the front, as shown below:

Usually if we just start 3 instances locally for the experience, there is no need to actually have 3 servers, so let’s build the cluster locally.

Copy the decompression package of Nacos into 3 parts, as follows:

  • nacos
  • nacos1
  • nacos2

Go to the conf directory of nacOS and edit the application.properties file to add the database configuration

# select Mysql as the data source
spring.datasource.platform=mysql

Number of database instancesdb.num=1 db.url.0=jdbc:mysql://localhost:3306/nacos? characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456
Copy the code

The only thing that needs to be changed is the server.port in the application. Properties file. Therefore, we need to modify the ports of the other two instances, such as changing nacos1 to 8847 and nacos2 to 8846.

After the database configuration information is ready, we need to initialize the corresponding database and table. The database script in the conf directory nacos-mysql. SQL can be executed.

The last step is to configure the cluster node information. The configuration file is in the conf directory cluster.conf.example and we rename it to cluster.conf.

Conf file and add information about the three nodes in the format of IP:PORT.

127.0.0.1:8848
127.0.0.1:8847
127.0.0.1:8846
Copy the code

To start the startup, go to the bin directory and run the./startup.sh command. The cluster mode is used by default and no parameters are required.

Nginx installation and configuration, this article will not explain, you can not try to try, the core configuration is as follows:

Upstream {server 127.0.0.1:8848; Server 127.0.0.1:8847; Server 127.0.0.1:8846; }Copy the code

In general, nacOS cluster setup method is quite simple, there is nothing special to pay attention to, the best way to access the domain name, in addition to the database if the production environment, also need to consider high availability, or at least have a master slave.

Guess what you want to see:

Ali Nacos first experience

Ali Nacos- Configuration – Multi-environment

Nacos does the most frequently asked questions in the configuration center