当前位置:网站首页>Nacos cluster construction and MySQL persistence configuration
Nacos cluster construction and MySQL persistence configuration
2022-04-23 18:38:00 【Hua Weiyun】
@toc
This article is very important , Because the production environment is used for high availability nacos colony , For single node service registration, you can follow the official website configuration , But clustering is a must .
1、Nacos Cluster deployment architecture
Most production environments use cluster mode to ensure high availability .
nacos The cluster architecture is as follows :
nacos Three deployment modes are supported :
- Click mode : For testing and click trial .
- Cluster pattern : For the production environment , Ensure high availability .
- Multi cluster mode : For multi data center scenarios .
Therefore, when open source, it is recommended that users put all service lists into one vip below , Then hang it under a domain name
http://ip1:port/openAPI Direct connection ip Pattern , The hook of the machine needs to be modified ip Can be used .
http://SLB:port/openAPI mount SLB Pattern ( Intranet SLB, Do not expose to the public network , To avoid safety risks ), Direct connection SLB that will do , Hang down server real ip, Poor readability .
http://nacos.com:port/openAPI domain name + SLB Pattern ( Intranet SLB, Do not expose to the public network , To avoid safety risks ), Good readability , And change ip convenient , Recommended modeMake complaints about it here. , Alibaba's documents are not very complete , Maybe there are too many big guys in Ali , Think we can understand the picture above , If you see the above architecture diagram, you can immediately translate it into the following , That means you really understand .
The above architecture diagram does not specify SLB What is it? , In fact, the above architecture diagram is translated into the following one. Does it look familiar .
2、Nacos Persistent configuration explanation
because Nacos The default is embedded database derby, This is not convenient for us to use tools to detect in real time , So here we use mysql Persistence nacos Configuration of .
derby Switch to mysql Steps for :
-
Go first conf Find... Under the folder nacos-mysql.sql This script , Then execute the script in your own database , The effect after execution is as follows :
-
Go ahead and revise conf Under the folder application.properties file , Add database configuration file :
Examples are as follows :
3、Linux edition Nacos+MySQL Production environment configuration
3.1 Cluster planning
Prepare three nacos node
- nacos01 node :192.168.159.33:3333
- nacos02 node :192.168.159.33:4444
- nacos03 node :192.168.159.33:5555
Prepare one nginx
Prepare one mysql:192.168.159.33:3306
namely 1 individual nginx+3 individual nacos node +1 individual mysql Low configuration cluster .
And here for simplicity ,nginx and mysql No cluster is used , The effect is the same .
Yes, of course , If you think it is unreasonable for all three nodes to be built in the same virtual machine , Then you can also start three virtual machines , Then revise ip that will do .
3.2 nacos Of linux Version installed
Download address :https://github.com/alibaba/nacos/releases/tag/1.4.1
What I use here is 1.4.1 edition ,
After downloading, you can decompress it directly .
Directory as follows :
3.3 linux On the server mysql Database configuration
take conf Under the folder nacos-mysql.sql Script in mysql In the implementation of .
View the results after execution
3.4 Copy three copies nacos file
Here we use nacos01、nacos02、nacos03, Just for testing , Please configure on different nodes in the production environment .
3.5 modify application.properties
modify /conf Under the folder application.properties file , increase mysql Persistent configuration .
nacos01、nacos02、nacos03 The following modifications need to be made in :
spring.datasource.platform=mysqldb.num=1db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?useUnicode=true&characterEncoding=utf-8&useSSL=falsedb.user=rootdb.password=123456
3.6 modify cluster.conf
stay nacos01 Modify in the folder /conf Under the folder cluster.conf
There is no initial , Only one cluster.conf.example,
We carry out orders cp cluster.conf.example cluster.conf
that will do .
And then execute vim cluster.conf
Command to edit the file
Add the following configuration :
192.168.159.33:3333192.168.159.33:4444192.168.159.33:5555
Now only nacos01, We copy the file directly to nacos02 and nacos03 In the corresponding folder .
Execute the following command :
cp cluster.conf /usr/local/nacos02/conf/ cp cluster.conf /usr/local/nacos03/conf/
3.7 Modify the port number of three nodes
Modify the of three nodes respectively /conf Under the folder application.properties file .
take nacos01、nacos02、nacos03 The port numbers of are modified to 3333、4444、5555
nacos01:
vim /usr/local/nacos01/conf/application.properties
nacos02:
vim /usr/local/nacos02/conf/application.properties
nacos03:
vim /usr/local/nacos03/conf/application.properties
3.8 Start three nacos node
Enter the... Of the three nodes respectively /bin Execute the following command under the file
startup.sh
You can see from the picture above , All in cluster mode (cluster) Starting up .
Visit the console of three nodes to check whether it is successful :
http://192.168.159.33:3333/nacos
http://192.168.159.33:4444/nacos
http://192.168.159.33:5555/nacos
3.9 Use nginx Load balancing
modify nginx Configuration file for
vim nginx.conf
Add the following configuration :
Configuration here means to make nginx monitor 1111 port ( You let it monitor 80 Ports are also OK )
start-up nginx
cd sbin./nginx -c /usr/local/nginx/conf/nginx.conf
3.10 Cluster testing
End here ,1 individual nginx+3 individual nacos Registry Center +1 individual mysql The configuration of is completed .
test Nginx visit nacos:http://192.168.159.33:1111/nacos
Create a new configuration test :
Check whether all three nodes have this configuration ,
nacos01:
nacos02:
nacos03:
see linux In the server mysql Whether there is one more record
3.11 Microservice registration test
Microservices cloudalibaba-provider-payment9002 Start registration nacos colony
modify application.yml Of documents nacos Registered address: :192.168.159.33:1111, Be careful , This is a nginx Listen to the address , After load balancing, it is handed over to 192.1168.159.33:3333、192.1168.159.33:4444、192.1168.159.33:5555 One of the three nodes handles .
After starting the micro service , Go to nacos Console to see if the registration is successful .
Here we are , The cluster construction and persistence configuration are all introduced , Here you can put nginx and mysql It is also built with clusters , Realize the real high availability cluster .
== Be careful : Here, if you simulate with a single virtual machine , Memory should be in 3G That's all .==
版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231836021874.html
边栏推荐
- Iptables - L executes slowly
- 深入理解 Golang 中的 new 和 make 是什么, 差异在哪?
- Ucosiii transplantation and use, reference punctual atom
- ESP32 LVGL8. 1 - anim animation (anim 16)
- ESP32 LVGL8. 1 - input devices (input devices 18)
- Notepad + + replaces tabs with spaces
- K210串口通信
- ctfshow-web362(SSTI)
- 机器学习理论之(8):模型集成 Ensemble Learning
- 使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
猜你喜欢
os_authent_prefix
Setting up keil environment of GD single chip microcomputer
WIN1 remote "this may be due to credssp encryption Oracle correction" solution
os_ authent_ Prefix
玻璃体中的硫酸软骨素
logstash 7. There is a time problem in X. the difference between @ timestamp and local time is 8 hours
WiFi ap6212 driver transplantation and debugging analysis technical notes
[mathematical modeling] - analytic hierarchy process (AHP)
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
随机推荐
Nacos集群搭建和mysql持久化配置
QT notes on qmap container freeing memory
Daily CISSP certification common mistakes (April 12, 2022)
昇腾 AI 开发者创享日全国巡回首站在西安成功举行
How to restore MySQL database after win10 system is reinstalled (mysql-8.0.26-winx64. Zip)
MVVM模型
Software test summary
14 py games source code share the second bullet
Loop path
Imx6 debugging LVDS screen technical notes
Introduction to quantexa CDI syneo platform
SQL database syntax learning notes
CISSP certified daily knowledge points (April 11, 2022)
机器学习实战 -朴素贝叶斯
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
【数学建模】—— 层次分析法(AHP)
Daily CISSP certification common mistakes (April 11, 2022)
Usage of functions decode() and replace() in SQL
Test questions of daily safety network (February 2024)
玻璃体中的硫酸软骨素