This series is a series of practical tutorials of Spring Cloud microservice. Before Introduction to Spring Cloud Eureka (I) detailed explanation of service registry Talked about Spring Cloud Eureka. Let's talk about Alibaba's open source Nacos today~
1, What is Nacos?
Let's 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 committed to discovering, configuring and managing microservices. Nacos provides a set of easy-to-use feature sets to help you quickly realize dynamic service discovery, service configuration, service metadata and traffic management.
In short, Nacos includes micro service configuration management + service registration, discovery and other monitoring. Microservices also include the microservice implementation of Spring Cloud.
The characteristics of Nacos mainly include the following:
- Service discovery and service health monitoring
- Dynamic configuration service
- Dynamic DNS Service
- Service and metadata management
The official figure 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:
Current stable version: 2.0.3
2.1 environmental preparation
Nacos depends on the Java environment, so if you build and run Nacos from the source code, you need to configure the following:
- JDK 1.8+
- Maven 3.2+
- 64 bit OS supports Linux/Unix/Mac/Windows, and Linux/Unix/Mac is recommended
If you deploy locally, you don't need to build from the source code, you just need to download the compiled compressed package and JDK 1.8 + environment
2.2 download the compiled compressed package
stay https://github.com/alibaba/na... In the address, download the nacos-server-2.0.3.zip package. Then execute the decompression command:
In this way, the project directory of Nacos will appear in the directory
2.3 pre startup configuration
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 files in the directory need to be known:
- application.properties configuration file
- Nacos MySQL.sql database MySQL database table information file
1 / create the database nacos and execute nacos mysql.sql
In this test, MySQL is used as data storage, so you need to create a new database nacos in MySQL. The command is as follows:
CREATE DATABASE nacos
Then perform the operations of creating tables and inserting default data into 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 operation and use of Nacos
Take the Mac as an example, start the following command:
cd nacos/bin sh startup.sh -m standalone
standalone stands for stand-alone mode and 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
How to view the Nacos log? It can be seen from the above that the log output is in the nacos/logs directory. View the start.out log file and 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 indicates that the deployment is successful. It is easy for the computer to run Nacos. Open the browser directly and enter the address:
The account and password are all nacos by default, as shown in the figure
How to close it?
The console will respond:
The nacosServer(4317) is running... Send shutdown request to nacosServer(4317) OK
3, Nacos summary
This article mainly describes the use scenarios of Nacos and Nacos, and then deploy Nacos locally to reach the available state. If you need server deployment, remember not to use stand-alone mode. Nacos is mainly the configuration center and service registry of microservices.
The following series of articles will combine the details of Spring Cloud micro service practice Nacos.
Author: bricklayer (public name "programmer bricklayer") source: https://www.bysocket.com Welcome to reprint, and please keep this statement. thank you!