当前位置:网站首页>Basic concept of Nacos and single machine startup
Basic concept of Nacos and single machine startup
2022-07-22 15:33:00 【Constantly improving Nan】
nacos Basic concept and single machine startup
- 1. What is? nacos?
- 2.Nacos Registry Center
- 3. download nacos
- 4.Nacos Configuration management model
- 5. Easy to use nacos
- 6. adopt @Value Read by annotation Nacos Configure the content
- 7. Place the database connection on Nacos In the configuration content of
- 8. Custom extension DataId
- 9. Configure priorities
1. What is? nacos?
1.nacos Definition : A dynamic service discovery that is easier to build cloud native applications 、 Service configuration and service management platform .
( Registry Center + Configuration center + Service management )
2.nacos Key features include :
Service discovery and service health detection ;
Dynamic configuration services ;
dynamic DNS service ;
Services and metadata management .
2.Nacos Registry Center
Manage all microservices 、 Solve the complex invocation relationship between microservices 、 Difficult to maintain .
1.Nacos discovery
Service registration found :Nacos discovert starter
Service discovery is one of the most critical components in microservice architecture . The service can be automatically registered to Nacos The server can dynamically perceive and refresh the service list of a service instance ,Nacos Discovery Starter Some metadata information of the service instance itself is also included , such as ,host,port, health examination URL, Home page, etc. register to Nacos.
2. Core functions
1. Service registration : When the service starts , The metadata in the service will be automatically registered to Nacos In the service table of the service registry .
2. Service heartbeat : In microservice (Nacos client ) There is a regular heartbeat to continuously notify the registry , Indicates that the service is always available , Prevent being deleted , Default 5s Send a heartbeat .
3. Service synchronization :Nacos Server(Nacos Registry Center ) In clusters , Clusters synchronize service instances with each other , To ensure the consistency of service information .
4. Service discovery :Nacos When the client invokes the service , Will send a rest Request to Nacos Registry Center , Get the list of registered services , And cache it in Nacos Client local , stay Nacos The client locally starts a scheduled task to periodically pull the latest registry information of the server and update it to the local cache .
5. Service health check :Nacos The registry will start a scheduled task to check the health of the registered service instance , For more than 15s Instances that do not receive a heartbeat from the client will healthy Property is set to false, If an instance exceeds 30s No heartbeat received , Delete the instance directly ( If the heartbeat of the deleted instance resumes, it will be re registered ).
3. download nacos
Download the installation package and modify the relevant configuration .
1. stay config Under the document ,application.properties Connect to the database
2. stay bin Under the table of contents startup.cmd When changing cluster startup to stand-alone startup .
take cluster Change it to standalone
4.Nacos Configuration management model
1. config set : In the system , A configuration file is usually a configuration set , A configuration set contains various configuration information of the system . Configuration set ID yes Data ID.
2. Configure grouping : Configuration grouping is the grouping of configuration sets , Different configuration groups can have the same configuration set , stay Nacos When you create a configuration on , If the name of the configuration group is not filled , Then the name of the configuration group is used by default DEFAULT_GROUP.
3. Namespace : It can be used for configuration isolation in different environments .
5. Easy to use nacos
1. stay bin Under the table of contents , start-up nacos
2.http://192.168.237.1:8848/nacos/index.html yes nacos Access address of
3. Login username and password The default is nacos
4. Create a new configuration
5. Write a simple example>6. if application.yml and bootstrap.yml In the same directory :bootstrap.yml Load first application.yml Post load .> establish bootstrap.yaml The configuration file
7. Create a class , Mainly used for testing : Read nacos What's in the configuration file , In order to detect and nacos Whether the connection is successful
8. Result display : Read content successfully
6. adopt @Value Read by annotation Nacos Configure the content
2. Access path :127.0.0.1:8089/configs
utilize @Value() Get by annotation Nacos Configure the content , Dynamic update of configuration is not supported , When the configuration content changes , Update access page , The content obtained has not changed , In this case , Introduced Support dynamic update of configuration .
The above one supports dynamic configuration update , When Nacos The configuration content has changed , Refresh 127.0.0.1:8089/configs after , The data obtained will also change .
7. Place the database connection on Nacos In the configuration content of
Multiple microservices will operate on one database , Nowadays, many micro services are distributed , If you create a database connection on every microservice , When the database needs to be changed , At this time, the maintenance amount is relatively large , therefore , utilize Nacos To manage the database connection , Multiple microservices only need to be introduced in the configuration file Nacos Configuration of .
1. First , Create a new namespace (dev)
2. In namespace dev under , The new configuration
3. Add the corresponding database connection in the new configuration
4. stay bootstrap.yaml To introduce this nacosDemo
8. Custom extension DataId
commonly A microservice Corresponding to one nacos To configure
however , A micro service can also correspond to multiple nacos To configure , Several microservices also have some public data , It can be put in the same nacos To configure .
1. Custom extension DataId
1. stay Nacos Create three configurations
2. stay bootstrap.yaml Add these three configuration files data id and group, It sets up ext-config-demo3.properties For dynamic update
3. stay TestBootStrap.java Test it , Expand data id Whether it is right ? Can I get the contents in the configuration file ?
4. test result
5. summary :
Need to use Nacos In multiple configuration files , It needs to be in bootstrap There are many in it data id, At this point, we use :txt-config[i], Write below this data-id and group.
Above ext-config[2] among , Add a dynamic update :refresh.
The role of dynamic update is mainly reflected in : When modifying nacos When configuring the information in the file , to update 127.0.01:8089/configs, The obtained data will also change accordingly .
2. Custom sharing Data ID Set up
1. It's better to use the one created above Nacos The configuration file
The first group By default default_group, The other two were written by themselves>2. Set custom sharing Data ID, stay config Set below :shared-dataids,refreshable-dataids
3. test result :
4. The results of the analysis :
It can be seen from the above results , Use and share data id When , Only support group by default_group, Does not support other , The others are null.
It is recommended to use custom extensions data id
9. Configure priorities
Spring Cloud Alibaba Nacos Config Three configuration capabilities are provided from Nacos Pull relevant configurations in .
A. adopt spring.cloud.nacos.config.shared-dataids Support multiple shares Data Id Configuration of ;
B. adopt spring.cloud.nacos.config.ext-config[n].data-id The way to support multiple extensions Data Id Configuration of , Multiple Data Id When configuring at the same time , Priority relation : Among them n The bigger it is , The higher the priority .
C. Through internal rules :( Application name spring.application.name、 Extension spring.cloud.nacos.config.file-extension) Automatically generate related Data Id To configure .
When the three methods are used together , Priority is C>B>A.
边栏推荐
- MySQL locking mechanism: MyISAM table lock, InnoDB row lock
- nacos基础概念和单机启动
- [activity registration] stack a buff for your code! Click "tea" to receive the gift
- Values swxxdp calculation in Res
- 上传图片到本机iis服务器,结果以网页地址形式返回,可直接访问
- Architecture design scheme (continuously updating ing)
- seaborn barplot画图总结
- Kubernetes基础部分学习笔记
- Graffiti Wi Fi & ble SoC development slide strip (5) -- burning authorization
- Cloud native ide: the first general and powerful codeless development platform of IVX
猜你喜欢
RuntimeWarning: Glyph 25152 missing from current font. font.set_text(s, 0.0, flags=flags)
Rebound shell carries out suid authorization through ordinary users
JDBC编程
Still asking what to use for interface testing? Universal JMeter creates a performance test data platform
Two people line up to install locally & x360ce simulation handle Tutorial & xpadder handle simulation keyboard and mouse
什么是探索性测试?探索性测试有哪些方法?
Let security move | no matter what industry network architecture, these six tactics win the target
卷妹的面试小抄每日更新Day1
df.describe() 详解+用法+示例
JDBC programming
随机推荐
RuntimeWarning: Glyph 25152 missing from current font. font.set_text(s, 0.0, flags=flags)
plt 画图并保存结果
MySQL exercise 1 knowledge of database
Let security move | no matter what industry network architecture, these six tactics win the target
Bi analytical thinking of business intelligence: cash cycle of manufacturing industry (II)
Tdengine experimental cluster establishment success
Ubuntu常用运维命令
MySQL locking mechanism: MyISAM table lock, InnoDB row lock
Clickhouse related SQL summary: create table, partition / primary key / sorting settings, delete table, delete partition, modify table fields
LeetCode练习1——二叉树剪枝
When configuring Eureka, the status displays the computer name instead of localhost and IPADDR, which is the local IP
Two people line up to install locally & x360ce simulation handle Tutorial & xpadder handle simulation keyboard and mouse
数据库的相关知识
Seaborn barplot drawing summary
92. (leaflet chapter) leaflet situation plotting - acquisition of attack direction
时序数据库
电流探头应该如何选择
Ubuntu common operation and maintenance commands
Redis cache penetration and avalanche
Visual studio pit record