当前位置:网站首页>Nacos service configuration and persistence configuration
Nacos service configuration and persistence configuration
2022-07-01 09:12:00 【The soul of bridge building】
Catalog

One 、Nacos The service registry has been improved
| Service registration and discovery framework | CAP Model | Console management | Community activity |
|---|---|---|---|
| Eureka | AP | Support | low (2.x Version closed source ) |
| Zookeeper | CP | I won't support it | in |
| Consul | CP | Support | high |
| Nacos | AP | Support | high |
CAP Model
- Uniformity (Consistency): The instance of the same request at the same time returns the same result , All data should be consistent (Strong Consistency)
- Usability (Availability): The read and write requests of all instances can get correct responses within a certain period of time
- Partition tolerance (Partition tolerance): In the network exception ( The cable is broken 、 Equipment failure 、 Downtime ) Under the circumstances , The system can still provide normal service
The above three characteristics are CAP principle ( also called CAP Theorem ), But the three characteristics cannot be satisfied at the same time , Therefore, the design of distributed system should consider meeting P( Partition tolerance ) On the premise of C( Uniformity ) still A( Usability ), namely :CP or AP.
Two 、Nacos Service configuration center
1. Add dependency
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2021.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2021.1</version>
</dependency>
2. To configure application.yaml
spring:
profiles:
active: dev # Represents the development environment
3. To configure bootstrap.yaml
# nacos To configure
server:
port: 3377
spring:
application:
name: nacos-config-client
cloud:
nacos:
discovery: # register
server-addr:
localhost: 8848 #Nacos Address of service registration center
config: # Open configuration center
server-addr:
localhost: 8848 #Nacos As the configuration center address
file-extension: yaml # Appoint yaml Format configuration
# Official format
# ${prefix}-${spring.profiles.active}.${file-extension}
# ${spring.application.name}-${spring.profiles.active}.${file-extension}
# The actual format
# nacos-config-client-dev.yaml
4. Platform creation configuration rules


5. The business layer writes
@RestController
@RefreshScope // Support Nacos Dynamic refresh function
public class ConfigClientController {
@Value("${config.info}")
private String configInfo;
@GetMapping("/config/info")
public String getConfigInfo(){
return configInfo;
}
}
6. Access to get configuration content
7. Nacos Dynamic refresh (@RefreshScope annotation )
Notes introduced by the business layer @RefreshScope Support Nacos Dynamic refresh function
3、 ... and 、 Switch between different environments
1. DateId programme
First, follow the previous steps , Create two configurations on the platform (dev and test)
Restart project , Test whether to switch to test Configuration of the environment
2. Group programme
Group The default grouping is
DEFAULT_GROUP, So we need to divide into two groups : One group isdev Development Group, One group istest Test groupView the configuration list , Check if the configuration is successful
changeapplication.yamlandbootstrap.yamlThe configuration file , test info Under the test:
revisit , Check whether the switch is successful
3. Namespace Space programme
newly build test and dev Two namespaces
Modify the configuration file
The manual in test Create three new groups under namespace
Access test
Four 、Nacos Persistent configuration
1. derby database
Nacos Embedded database will be provided by default in derby, So we create one at a time Nacos The instance will have one derby, When there is more than one Nacos Node time , There will be consistency issues , therefore Nacos Support unified management of external databases MySql.
2. Switch MySql database
① Create database
Create... In the database nacos_config library CREATE DATABASE nacos_config;
② Execute... In the database navos-mysql.sql Script

The following table will appear in the Library :

③ modify application.properties file
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://11.162.196.16:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&serverTimezone=UTC
db.user=nacos_devtest
db.password=youdontknow


④ test
start-up nacos
The new configuration
Look at the local database , Data exists , Description switch mysql Database success !
边栏推荐
- Input标签的type设置为number,去掉上下箭头
- 【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()
- 如何一站式高效管理固定资产?
- Shell脚本-位置参数(命令行参数)
- Log4j 日志框架
- Yidian Yidong helps enterprises to efficiently manage equipment and improve equipment utilization
- 树结构---二叉树2非递归遍历
- Principle and application of single chip microcomputer timer, serial communication and interrupt system
- Bird recognition app
- [video game training] real topic of 2013 video game of infrared optical communication device
猜你喜欢

Football and basketball game score live broadcast platform source code /app development and construction project

Personal decoration notes

Nacos - service discovery

jeecg 重启报40001

2.2 【pytorch】torchvision.transforms

Pain points and solutions of equipment management in large factories

nacos服务配置和持久化配置

如何解决固定资产管理和盘点的难题?

Principles of Microcomputer - Introduction

What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
随机推荐
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DHT11 +NodeJs本地服务+ MySQL数据库
The jar package embedded with SQLite database is deployed by changing directories on the same machine, and the newly added database records are gone
I use flask to write the website "one"
Shell脚本-read命令:读取从键盘输入的数据
Why is the Ltd independent station a Web3.0 website!
Programming with C language: calculate with formula: e ≈ 1+1/1+ 1/2! …+ 1/n!, Accuracy is 10-6
nacos簡易實現負載均衡
如何高效拉齐团队认知
Preparing for the Blue Bridge Cup -- bit operation
Shell脚本-case in语句
nacos简易实现负载均衡
2.3 【kaggle数据集 - dog breed 举例】数据预处理、重写Dataset、DataLoader读取数据
3D打印Arduino 四轴飞行器
Promise异步编程
Embedded Engineer Interview Question 3 Hardware
Shell script case in and regular expressions
Daily practice of C language - day 80: currency change
[pytorch learning] torch device
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DS18B20 temperature sensor +nodejs local service + MySQL database
【电赛训练】红外光通信装置 2013年电赛真题








View the configuration list , Check if the configuration is successful 










