Nacos service introduction and installation

Introduction to Nacos

Service Discovery Product Comparison

Currently, there are many service discovery centers on the market: Nacos, Eureka, Consul, and Zookeeper.

Compare items Nacos Eureka Consul Zookeeper
Conformance Protocol Support AP and CP models AP model CP model CP model
health examination TCP/HTTP/MYSQL/Client Beat Client Beat TCP/HTTP/gRPC/Cmd Keep Alive
load balancing strategy 权重/metadata/Selector Ribbon Fabio -
Avalanche protection have have without without
Automatically log out of the instance support support not support support
access agreement HTTP/DNS HTTP HTTP/DNS TCP
Monitoring support support support support support
Multiple data centers support support support not support
Sync across registries support not support support not support
SpringCloud integration support support support not support
Dubbo integration support not support not support support
k8s integration support not support support not support

From the above comparison, we can see that Nacos, as a service discovery center, has more functional support items, and in the long run Nacos will support the combination of SpringCLoud + Kubernetes in future versions to fill the gap between the two. Under the two systems The same set of service discovery and configuration management solutions can be used, which will greatly simplify the cost of use and maintenance. In addition, Nacos plans to implement Service Mesh, which is also the trend of future microservice development.

Definition of Nacos

insert image description here

Nacos is an open source product of Alibaba. It is a comprehensive solution for service discovery, configuration management, and service governance in the microservice architecture.

The official introduction is as follows:

Nacos is dedicated to helping you discover, configure and manage microservices. Nacos provides a set of easy-to-use features to help you achieve dynamic service discovery, service configuration management, service and traffic management. Nacos helps you build, deliver and manage microservice platforms more agilely and easily.
Nacos is a service infrastructure for building a "service"-centric modern application architecture.

Official website address: https://nacos.io

Nacos Features

Nacos mainly provides the following four functions:

  1. Service Discovery and Service Health Check

Nacos makes it easier for services to register and discover other services through DNS or HTTP interfaces, and Nacos also provides real-time health checks of services to prevent sending requests to unhealthy hosts or service instances.

  1. Dynamic Configuration Management

Dynamic configuration services allow you to manage the configuration of all services in a centralized and dynamic manner across all environments. Nacos eliminates redeployment of applications when updating configuration, which makes configuration changes more efficient and flexible.

  1. Dynamic DNS Service

Nacos provides service discovery capabilities based on the DNS protocol, which aims to support service discovery in heterogeneous languages, and to expose endpoints of services registered on Nacos in the form of domain names, allowing third-party applications to easily consult and discover.

  1. Service and metadata management

Nacos allows you to manage all services and metadata in the data center from the perspective of microservice platform construction, including management service description, life cycle, service static dependency analysis, service health status, service traffic management, routing and security policies .

Here 1, 3, and 4 illustrate the functional characteristics of service discovery.

Install Nacos Server

Environmental preparation

Nacos relies on the Java environment to run. If you are building and running Nacos from code, you also need to configure a Maven environment for this, make sure to install and use it in the following version environment:

\1. 64 bit OS, support Linux/Unix/Mac/Windows, Linux/Unix/Mac is recommended.

\2. 64 bitJDK 1.8+; download & configure .

\3. Maven 3.2.x+; download & configure .

Download source code or installation package

Download source code from Github

git clone https://github.com/alibaba/nacos.git
cd nacos/
mvn ‐Prelease ‐nacos clean install ‐U
ls ‐al distribution/target/
// change the $version to your actual path
cd distribution/target/nacos ‐server ‐$version/nacos/bin

Download and compile the compressed package

You can download the package from the latest stable release , this tutorial uses the nacos-server-1.1.3 version.

Download address: https://github.com/alibaba/nacos/releases

Scroll to the bottom of the page:
insert image description here

Unzip after download:

unzip nacos ‐server ‐$version.zip 
或者
tar ‐xvf nacos ‐server ‐$version.tar.gz
cd nacos/bin

start the server

The default port of nacos is 8848, and it is necessary to ensure that the default port of 8848 is not occupied by other processes.

Go to the bin directory of the installer:

Linux/Unix/Mac startup method:

Startup command (standalone means running in stand-alone mode, not in cluster mode):

sh startup.sh -m standalone

If you are using ubuntu system, or if you run the script and get an error message [[symbol not found, you can try to run as follows:

bash startup.sh -m standalone

Windows startup method:

Start command:
Note: The path must be in English, I tried Chinese and failed to start

cmd startup.cmd 

Or double-click startup.cmd to run the file.

Successful operation interface:
insert image description here

The startup is successful, you can visit http://127.0.0.1:8848/nacos through the browser , and open the following nacos console login page:

insert image description here
Use the default username: nacos and the default password: nacos to log in to open the main page.

insert image description here

External mysql database support

In stand-alone mode, nacos uses an embedded database to store data by default. If you want to use external mysql to store nacos data, you need to perform the following steps:

1. Install the database, version requirements: 5.6.5+, mysql 8 below
2. Initialize the mysql database, create a new database nacos_config, database initialization file: ${nacoshome}/conf/nacos-mysql.sql(This file is in the decompressed file conf directory)

insert image description here

3. Modify the ${nacoshome}/conf/application.properties file to add support for mysql data source configuration (currently only mysql is supported), and add the url, username and password of the mysql data source.
insert image description here

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true 
db.user=root
db.password=yourpassword

insert image description here

Guess you like

Origin blog.csdn.net/weixin_45525272/article/details/123564008