This series is a series of practical tutorials on Spring Cloud microservices. talked about Spring Cloud Eureka in "Introduction to Spring Cloud Eureka (1) Detailed Explanation of Service Registration Center" 161acc5f531034. Let’s talk about Alibaba’s open source Nacos today~
1. What is Nacos?
First understand that Spring Cloud Eureka is based on Netflix Eureka (Netflix is an open source software implemented in Java). Service governance (Eureka) includes service registration, service discovery, service detection and monitoring, etc.
Nacos is dedicated to discovering, configuring, and managing microservices. Nacos provides a set of simple and easy-to-use feature sets to help you quickly realize dynamic service discovery, service configuration, service metadata and traffic management.
In short, Nacos includes configuration management of microservices + monitoring of service registration and discovery. Microservices also include Spring Cloud's microservice implementation.
The key features of Nacos include the following:
- Service discovery and service health monitoring
- Dynamic configuration service
- Dynamic DNS service
- Services and metadata management
- and many more
The official picture is as follows:
2. How to deploy and use Nacos locally
You can download the latest stable version from the Nacos Release version list on github. address:
https://github.com/alibaba/nacos/releases
Current stable version: 2.0.3
2.1 Environmental preparation
Nacos relies on the Java environment, so if you build and run Nacos from source code, you need to configure the following:
- JDK 1.8+
- Maven 3.2+
- 64 bit OS supports Linux/Unix/Mac/Windows, Linux/Unix/Mac is recommended
If you deploy locally, you don’t need to build from source code, you only need to download the compiled compressed package and JDK 1.8+ environment.
2.2 Download the compiled compressed package
In the https://github.com/alibaba/nacos/releases address, download the nacos-server-2.0.3.zip compressed package. Then execute the decompression command:
unzip nacos-server-2.0.3.zip
Nacos project directory will appear in the directory
2.3 Configuration before startup
The directory structure is as follows:
nacos % ls -l
total 48
-rw-r--r--@ 1 qq staff 16583 3 18 2021 LICENSE
-rw-r--r--@ 1 qq staff 1305 5 14 2020 NOTICE
drwxr-xr-x@ 8 qq staff 256 12 3 14:25 bin
drwxr-xr-x@ 9 qq staff 288 7 27 14:18 conf
drwxr-xr-x 6 qq staff 192 12 3 14:43 data
drwxr-xr-x 35 qq staff 1120 12 3 14:25 logs
drwxr-xr-x@ 3 qq staff 96 7 28 19:28 target
Enter the conf directory, the directory structure is as follows:
conf % ls -l
total 176
-rw-r--r--@ 1 qq staff 1224 6 18 10:39 1.4.0-ipv6_support-update.sql
-rw-r--r--@ 1 qq staff 9752 12 3 14:41 application.properties
-rw-r--r--@ 1 qq staff 9506 7 27 14:18 application.properties.example
-rw-r--r--@ 1 qq staff 670 3 18 2021 cluster.conf.example
-rw-r--r--@ 1 qq staff 31156 7 15 19:19 nacos-logback.xml
-rw-r--r--@ 1 qq staff 10660 6 18 10:39 nacos-mysql.sql
-rw-r--r--@ 1 qq staff 8795 6 18 10:39 schema.sql
For this deployment, two of the files in the directory need to be known:
- application.properties configuration file
- nacos-mysql.sql database MySQL database table information file
1/ Create database nacos and execute nacos-mysql.sql
This test uses MySQL as the data storage, you need to create a new database nacos in MySQL, the command is as follows:
CREATE DATABASE nacos
Then perform table creation and insert default data operations in the database, see the nacos-mysql.sql file for details.
2/ Modify the application.properties configuration file
Then open the application.properties configuration file and change the corresponding place to the following:
#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=admin
db.password.0=123456
2.4 Run and use Nacos
Take the Mac native machine as an example, start the following command:
cd nacos/bin
sh startup.sh -m standalone
Standalone represents stand-alone mode operation, non-cluster mode
The console can see the following information:
nacos is starting with standalone
nacos is starting,you can check the /Users/qq/project/nacos/logs/start.out
Then how to view the Nacos log, from the above it can be seen that the log output is in the nacos/logs directory, and to view the start.out log file, execute the following command:
tail -200f /Users/qq/project/nacos/logs/start.out
The console can see the following information:
,--.
,--.'|
,--,: : | Nacos 2.0.3
,`--.'`| ' : ,---. Running in stand alone mode, All function modules
| : : | | ' ,'\ .--.--. Port: 8848
: | \ | : ,--.--. ,---. / / | / / ' Pid: 2452
| : ' '; | / \ / \. ; ,. :| : /`./ Console: http://xxxx:8848/nacos/index.html
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
| | | \ | \__\/: . .. ' / ' | .; : \ \ `. https://nacos.io
' : | ; .' ," .--.; |' ; :__| : | `----. \
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
' : | ; : .' \ : : `----' '--'. /
; |.' | , .-./\ \ / `--'---'
'---' `--`---' `----'
...
2021-12-04 15:25:18,201 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'
This shows that the deployment is successful, and it is very simple to run Nacos on the computer. Open the browser directly and enter the address:
http://localhost:8848/nacos/index.html
The default account and password are nacos, as shown in the figure
How to close it?
Close command:
sh shutdown.sh
The console will respond:
The nacosServer(4317) is running...
Send shutdown request to nacosServer(4317) OK
Three, Nacos summary
This article mainly describes the usage scenarios of Nacos and Nacos, and then deploys Nacos locally to reach a usable state. If you need server deployment, remember that you can't stand-alone mode. Nacos is mainly the configuration center and service registration center of microservices.
The follow-up series of articles will combine the details of Spring Cloud microservices to practice Nacos.
Author: Masons (public name "Programmer Masons") Source: https://www.bysocket.com Welcome to reprint, and please keep this statement. Thanks!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。