Alibaba Nacos service discovery component cluster deployment

Learned earlier start in stand-alone mode, the production environment must be deployed nacos using cluster model cluster to ensure high availability. Cluster deployment official document recommended VIP domain model, the list of all services into a vip below, then hang on to a domain name below.

Three deployment mode

Official recommendation, nacos clusters are generally three ways, distinguish three deployments in the form of access as follows,

http: // ip1: port / openAPI direct mode ip, ip hang the machine needs to be modified before use

http: // VIP: port / openAPI mount VIP mode, can be directly connected vip, hanging below the real server ip, poor readability

http://nacos.com:port/openAPI domain VIP mode, readable, and easy to change ip, the recommended mode

The official suggested at least three or three nodes to achieve the cluster model.

Modify the startup port

The program starts the default port is occupied by 8848, we can modify the port, open application.properties the conf file, modify the start port.

Now demonstrate the use of stand-alone pseudo-cluster model, so to deploy these three instances by modifying the way the port, the port are: 8848,8858,8868.

Configuring the cluster configuration file

In nacos unzipped directory nacos / conf directory, configuration files cluster.conf, per line configured ip: port. (3 configure three or more nodes)

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

Configure MySQL database

Production using the recommended at least standby mode, or employs a highly available database.

MySQL database initialization

sql statement in the source file nacos-mysql.sql the distribution / conf / directory in the local initialization of the corresponding database.

Adding database configuration

Profile application.properties conf directory 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 number of instances of the database if there are multiple database instances by db.url.0, db.url.1 ..... specify a different database link.

Start the server

The default mode is no argument, that cluster mode, the start command:sh startup.sh

Shut down the server, can be executed directlysh shutdown.sh

Nginx configuration 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;
    }
}

Configuring VIP binding domain test.nacos.com

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 three nodes are normal startup, you can log various web interface to view each cluster node, the health status:

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=

No scan code of public attention: architecture evolution, to obtain first-hand information technology and original articles

Published 20 original articles · won praise 3 · views 10000 +

Guess you like

Origin blog.csdn.net/leread/article/details/104055138