当前位置:网站首页>[Nacos cloud native] the first step of reading the source code is to start Nacos locally
[Nacos cloud native] the first step of reading the source code is to start Nacos locally
2022-07-05 12:51:00 【Shizhenzhen's grocery store】
Preface
Before we read Nacos Before source code , We have to understand Nacos do , And how to use it , This makes it easier for us to understand the source code ;
see Nacos Official documents of , We know Naocs It has the following characteristics :
- Configuration center
- Service registration and discovery
- …
Nacos It provides us with a management interface , To facilitate the configuration of data ; Let's take the whole Nacos The source code is cloned , Local boot ; Familiarize yourself with how to use it
start-up Nacos project
1. clone Nacos Source code
git clone https://github.com/alibaba/nacos.git
Import to Idea in
2. To configure Mysql data source
Nacos Built in embedded derby database , But it is only suitable for development testing , It's not good for us to observe the data ; So let's change the database to Mysql
In the use of Mysql Before , You need to create nacos_config The database of sql File in module distribution
Medium conf/nacos-mysql.sql
; Execute this file ;
In the module nacos/distribution
Add Mysql Configuration file for
## The database for mysql
spring.datasource.platform=mysql
## Database number Because there may be multiple data sources configured Master-slave
db.num=1
db.url.0=jdbc:mysql://XX.XX.XXX.XX:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user.0=name
db.password.0=password
3. Package and publish the project
Execute package command
mvn -Prelease-nacos clean install -U -Dmaven.test.skip=true
Pack up , Execute startup script
sh distribution/target/nacos-server-{version}/nacos/bin/startup.sh -m standalone
here -m standalon
e Stand alone mode start , Other optional parameters are :
-f [config/naming]
Boot mode Only one module can be started ,config: Configuration center ; naming: Service registration and discovery , When not set, all modules will start-s Followed by the service package name ; The default value is
nacos-server
You can specify the startup Jar Package name ;
Check if the start is successful
After successful startup , You can access the management background
http://localhost:8848/nacos/index.html The password of the login account is : nacos
The management background after login
If you add parameters when you just start -f config
Now all we see is Configuration Management and Namespace Two menu bars
For detailed explanation of use, please refer to the official documents Console manual
Nacos Configuration center database table structure description
tenant_info Tenant information table ( The namespace table )
Nacos be based on Namespace Help users logically isolate multiple namespaces , This can help users better manage tests 、 Advance 、 Production and other multi environment services and configurations , Let each environment have the same configuration ( Such as database data source ) You can define different values .
The data in this namespace is the existence table tenant_info
in
tenant_info
Field | remarks |
---|---|
id | The primary key increases automatically |
kp | Set value 1 |
tenant_id | Namespace id, It's a UUID character string |
tenant_name | Namespace name |
tenant_desc | Namespace description |
create_source | founder |
gmt_create | Creation time |
gmt_modified | Modification time |
(kp
,tenant_id
) Make up a unique constraint
config_info Configuration information table
All configured data is stored in this table ;
Field | describe |
---|---|
id | Since the primary key |
data_id | data ID |
group_id | Group ID, Default DEFAULT_GROUP |
content | Configure the content , It's a longtext type |
md5 | content Of md5 |
tenant_id | Tenant ID, Corresponding tenant_ino Medium tenant_id |
app_name | ascription App name |
type | json、properties、text、xml And so on |
gmt_create | Creation time |
gmt_modified | Modification time |
c_desc | describe |
config_info_beta Gray configuration information
Nacos Grayscale publishing function in , If you click grayscale Publishing , And fill in the grayscale publishing server Ip; Information will be stored here ;
Field | describe |
---|---|
id | The primary key increases automatically |
data_id | data id |
group_id | Group id |
app_name | apply name |
content | Configure the content |
beta_ips | Machines requiring grayscale Publishing , If ip In this , The configuration information will be obtained |
md5 | content Of md5 |
tenant_id | Tenant ID, Different namespaces |
gmt_create | Creation time |
gmt_modified | Modification time |
(data_id
,group_id
,tenant_id
) Make up a unique constraint
config_tags_relation tag A relational table
Each configuration file can be marked with tag label ; This table records the configuration file and tag Binding relationship of
Field | describe |
---|---|
id | Primary key . |
tag_name | The tag name |
tag_type | Label type |
data_id | data id |
group_id | Group id |
tenant_id | Tenant ID, Different namespaces |
nid | The primary key grows by itself |
(id
,tag_name
,tag_type
) Make up a unique constraint
his_config_info Historical configuration table
Nacos The historical configuration will be recorded , Used to facilitate rollback configuration ; By default, it exceeds 30 The record of days will be deleted ;
Field | describe |
---|---|
id | id |
nid | Primary key , Self increasing |
data_id | data id |
group_id | Group id |
app_name | apply name |
content | Configure the content |
md5 | content Of md5 |
tenant_id | Tenant ID, Different namespaces |
gmt_create | Creation time |
gmt_modified | Modification time |
op_type | I、U、D Operation type , Add, replace and delete |
How to debug locally Jar Package start source code
Due to the above startup mode , We may not be able to do local Debug; But we can turn it on at startup Debug port , Through remote monitoring Debug Port to carry on Debug;
Let's modify the startup script first , Open the debug port to modify
file distribution/target/nacos-server-{version}/nacos/bin/startup.sh
# Add debug port 6666 The debug port can be set at will
JAVA_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=6666,server=y,suspend=n"
echo "$JAVA ${JAVA_DEBUG_OPTS} ${JAVA_OPT} " > ${
BASE_DIR}/logs/start.out 2>&1 &
nohup $JAVA ${
JAVA_DEBUG_OPTS} ${
JAVA_OPT} nacos.nacos >> ${
BASE_DIR}/logs/start.out 2>&1 &
Restart
Stop the project first sh distribution/target/nacos-server-{version}/nacos/bin/shutdown.sh
And then restart it sh distribution/target/nacos-server-1.1.3/nacos/bin/startup.sh -m standalone
Successful launch , Check whether the debug port is open
There is already one 6666 The port of LISTEN It's in ;
Configuration debugging
stay Idea Create a new one in remote start-up ;
Start debugging
Start debugging ; Make a breakpoint , Then manage the back-end operations ; Look at the effect
Debugging successful
The project started , The debugging is also successful ; Then we can easily start reading the source code !
边栏推荐
- Kotlin函数
- Comprehensive upgrade of Taobao short video photosynthetic platform
- JDBC -- extract JDBC tool classes
- ZABBIX monitors mongodb templates and configuration operations
- Language model
- 【云原生】Nacos中的事件发布与订阅--观察者模式
- Simply take stock reading notes (2/8)
- GPON technical standard analysis I
- 太方便了,钉钉上就可完成代码发布审批啦!
- Docker configures redis and redis clusters
猜你喜欢
Migrate data from Mysql to neo4j database
UNIX socket advanced learning diary - advanced i/o functions
Hexadecimal conversion summary
Keras implements verification code identification
I met Tencent in the morning and took out 38K, which showed me the basic smallpox
初识Linkerd项目
石臻臻的2021总结和2022展望 | 文末彩蛋
【云原生】Nacos中的事件发布与订阅--观察者模式
Kotlin variable
JDBC exercise - query data encapsulated into object return & simple login demo
随机推荐
Four common problems of e-commerce sellers' refund and cash return, with solutions
Resnet+attention project complete code learning
UNIX socket advanced learning diary - advanced i/o functions
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
开发者,云原生数据库是未来吗?
【云原生】Nacos-TaskManager 任务管理的使用
SAP 自开发记录用户登录日志等信息
JSON parsing error special character processing (really speechless... Troubleshooting for a long time)
【云原生】Nacos中的事件发布与订阅--观察者模式
ZABBIX agent2 monitors mongodb nodes, clusters and templates (official blog)
自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
GNN(pytorch-geometric)
Reshape the power of multi cloud products with VMware innovation
前几年外包干了四年,秋招感觉人生就这样了..
从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
实战模拟│JWT 登录认证
Simply take stock reading notes (2/8)
Laravel文档阅读笔记-mews/captcha的使用(验证码功能)
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
HiEngine:可媲美本地的云原生内存数据库引擎