preface
During the development process, we usually configure some parameters to achieve certain functions, such as whether to enable a certain service, alarm email configuration, and so on. It is generally implemented in the form of hard coding, configuration files or databases.
So the question is, how do you do it more gracefully? Welcome to the world of Nacos!
Nacos configuration management
Nacos is an open source project of Alibaba, full name Naming Configuration Service, focusing on Service discovery and Configuration management.
Nacos is dedicated to helping you discover, configure, and manage microservices. Nacos provides an easy-to-use feature set that helps you quickly implement dynamic service discovery, service configuration, service metadata, and traffic management.
Nacos ecological figure
As shown in the Nacos panorama, Nacos seamlessly supports some mainstream open source ecosystems, such as
Spring Cloud
Apache Dubbo and Dubbo Mesh TODO
Kubernetes and CNCF TODO.
Using Nacos simplifies service discovery, configuration management, service governance, and management solutions, making it easier to discover, manage, share, and compose microservices.
Nacos Spring Boot for a quick start
Take spring-boot2.x as an example:
Pom.xml introduces dependencies:
Start the class:
Use cases:
Configuration file import:
You are advised to use the Intranet and configure the firewall
Nacos. Config. Server – addr = 127.0.0.1:8848
For details about server installation and configuration, see:
https://nacos.io/zh-cn/docs/quick-start.html
Home page:
The dataId must be consistent with the system configuration of the key-value pair mode.
Instantiate the database
Nacos Server uses an embedded database by default. You are advised to use the mysql database to store configuration information in the production environment.
Add the configuration to the configuration file application.properties:
spring.datasource.platform=mysql
db.num=1
Db. Url. 0 = JDBC: mysql: / / 127.0.0.1:3306 / nacos? characterEncoding=utf8connectTimeout=1000socketTimeout=3000autoReconnect=true
db.user=root
db.password=root
To create a database, go to the Nacos Server conf folder, find the nacos-mysql. SQL file, and import the created database.
Nacos The default password is Nacos. To change the password, run the following command:
org.springframework.boot
spring-boot-starter-security
Then use code encryption:
summary
Overall, Nacos is pretty convenient, and the configuration center is just one small feature.