I learned the start-up in the stand-alone mode earlier. The deployment of nacos in the production environment must use cluster mode to ensure high availability. For the cluster deployment of official documents, it is recommended to use vip domain name mode, put all service lists under one vip, and then hang them under one domain name.

Three deployment modes

It is officially recommended that there are three ways to deploy a nacos cluster. The differences between the three deployment ways in the access form are as follows:,

http://ip1:port/openAPI direct connection ip mode, which can be used only after the ip is modified when the machine is hung

http://VIP:port/openAPI is used to mount VIP mode, which can be connected directly to VIP. The real ip of server is hung below, which is not readable

http://nacos.com:port/openAPI domain name VIP mode, good readability, easy to change ip, recommended mode

It is officially recommended that at least three or more nodes implement the cluster mode.

Modify start port

The default port used for program startup is 8848. We can modify the port, open application.properties in the conf file, and modify the startup port.

Now, I will demonstrate the use of the single machine pseudo cluster mode, so I will deploy the three instances by modifying the ports: 8848, 8858, and 8868.

Configure cluster profile

In the conf directory of nacos / directory, configure the file cluster.conf. Please configure each line as ip:port. (please configure 3 or more nodes)

# ip:port
58.18.17.155:8848
58.18.17.155:8858
58.18.17.155:8868

Configure MySQL database

It is recommended to use at least the active standby mode or the highly available database for production.

Initialize MySQL database

The source file of SQL statement is Nacos mysql.sql under the directory of distribution/conf /. The corresponding database is initialized locally.

Add database configuration

The configuration file is in application.properties under the conf directory of nacos. Add the following configuration

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

db.num is the number of database instances. If there are multiple database instances, specify different database links through db.url.0 and db.url.1.

Start server

By default, there is no parameter mode, i.e. cluster mode. The startup command is sh startup.sh

Shut down the server and execute sh shutdown.sh directly

Configure Nginx service

Modify conf/nginx.conf configuration

upstream nacos {
    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;
    }
}

Configure domain name test.nacos.com to bind VIP

Service registration and configuration

Service registration

curl -X PUT 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080

Service discovery

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

Release configuration

curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=helloWorld

Get configuration

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

Cluster management

After the three nodes are started normally, you can log in to each web interface to view the nodes 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=

Scan code pays attention to public number: architecture evolution theory, get first-hand technical information and original articles.

Yue Yue
Published 20 original articles, won praise 3, 10000 visitors+