After learning about the startup in single-machine mode, nacOS must be deployed in a production environment using cluster mode for high availability. In the official document, you are advised to use the VIP+ domain name mode for cluster deployment. Put all service lists under one VIP and then hang them under one domain name.

There are three deployment modes

Officially recommended, nacOS clusters generally have three modes, and the differences of the three deployment modes in access forms are as follows:

http://ip1:port/openAPI Directly connected TO the IP address mode. For machine mounting, you need to change the IP address to use http://VIP:port/openAPI to mount the VIP mode. Directly connected to the VIP mode, the real IP address of the server is mounted below. Nacos.com: Port /openAPI domain + VIP mode, readable, and easy to change IP, recommended mode

Officials recommend at least three or more nodes to implement the cluster mode.

Modifying the Boot Port

The default port used for application startup is 8848. You can change the port by opening the application.properties file in the conf file.

The example uses the single-machine pseudo-cluster mode, so the three instances are deployed by modifying the ports: 8848, 8858, and 8868.

Configure the cluster configuration file

In the conf directory of nacos/, set the cluster.conf file to IP :port in each line. (Please configure 3 or more nodes)

# ip:port
58.18.17.155:8848
58.18.17.155:8858
58.18.17.155:8868
Copy the code

Configuring the MySQL Database

You are advised to use at least active/standby mode or use a high availability database.

Initialize the MySQL database

SQL statement source file nacos-mysql. SQL in the distribution/conf/ directory to initialize the corresponding database locally.

Adding a Database Configuration

Add the following configuration to the application. Properties directory in the conf directory of nacOS

The db. The num = 1 db. Url. 0 = JDBC: mysql: / / 58.18.17.155:3306 / nacos_config? characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root

Copy the code

Db. num is the number of database instances. If multiple database instances pass db.url.0, db.url.1….. Specify different database links.

Start the server

The cluster mode is used by default. Run the sh startup.sh command to start the startup

To shutdown the server, run sh shutdown.sh

Configure the Nginx service

Modify the conf/nginx.conf configuration

Upstream {server 58.18.17.155:8848; Server 58.18.17.155:8858; Server 58.18.17.155:8868; } server { listen 80; server_name test.nacos.com; location / { proxy_pass http://nacos; }}Copy the code

The test.nacos.com domain name is bound to VIP

Service registration and configuration

The service registry

curl -X PUT 'http://127.0.0.1:8848/nacos/v1/ns/instance? ServiceName = nacos. Naming. ServiceName&ip = 20.18.7.10 & port = 8080Copy the code

Service discovery

curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instances? serviceName=nacos.naming.serviceNameCopy the code

Release configuration

curl -X POST "Http://127.0.0.1:8848/nacos/v1/cs/configs? dataId=nacos.cfg.dataId&group=test&content=helloWorldCopy the code

Access to the configuration

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

Cluster management

After the three nodes are started properly, you can log in to the web UI to view the node and health status of the cluster.

http://58.18.17.155:8848/nacos/#/clusterManagement? dataId=&group=&appName=&namespace=&serverId=

http://58.18.17.155:8858/nacos/#/clusterManagement? dataId=&group=&appName=&namespace=&serverId=

http://58.18.17.155:8868/nacos/#/clusterManagement? dataId=&group=&appName=&namespace=&serverId=
Copy the code

Scan our public account: Architecture evolution for first-hand technical information and original articles