当前位置:网站首页>Nacos集群的搭建过程详解
Nacos集群的搭建过程详解
2022-08-05 05:25:00 【用户昵称23】
一、Nacos集群部署架构
在实际开发过程中,如果使用Nacos的话,为了确保高可用,我们一般都会对其进行集群的部署。Nacos规定集群中Nacos节点的数量需要大于等于3个;同时,单机模式下Nacos的数据默认保存在其内嵌数据库中,不方便观察数据存储的基本情况。而且如果集群中启动多个默认配置下的Nacos节点,数据存储是存在一致性问题的。为了解决这个问题,Nacos采用了集中式存储的方式来支持集群化部署,目前只支持MySQL的存储;此外,我们还需要借助Nginx实现负载均衡。这一过程的部署架构图如下所示:
二、切换Nacos的默认数据库
(1)在开始搭建集群之前,我们需要先将Nacos的默认数据库derby切换成mysql。
首先启动本机mysql,创建nacos_config数据库,并在nacos_config数据库下执行nacos-mysql.sql脚本,如下图所示:
执行成功后,查看创建好的数据表:
(2)我的Nacos是直接解压在 /opt 路径下的,找到并修改 /opt/nacos/conf 路径下的application.properties文件,将以下内容直接粘贴到application.properties的最后面(注意db.user和db.password要修改成自己mysql的用户名和密码):
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456
三、修改Nacos的集群配置
(1)同样的在 /opt/nacos/conf目录下,找到并修改cluster.conf 文件,如下图所示:
(2)在 /opt/nacos/bin 目录下,找到并修改 startup.sh 文件,需要修改的地方如下图所示:
① 修改前:
修改后:
② 修改前:
修改后:
修改完成后,在 /opt/nacos/bin 路径下可以使用如下命令,启动对应端口号的nacos节点:
四、配置Nginx实现负载均衡
(1)找到并修改 /usr/local/nginx/conf 路径下的 nginx.conf 文件,需要修改的地方如下图所示(为了演示方便,这里就不再搭建 nginx 的集群了,只以一个 nginx 为例进行说明):
五、测试效果
(1)先启动 nginx,再依次启动3333、4444、5555的 nacos 节点
(2)关闭 linux 本地的防火墙或者开放 linux 上需要被访问的对应端口号
(3)比如我的 linux 的 ip是 192.168.1.103,因此在Windows上访问 192.168.1.103:1111/nacos 即可成功访问nacos的界面(这里是1111是因为刚刚在 nginx 的配置文件中暴露的端口号是1111)。
(4)在 nacos 的界面中新建配置信息:
(5)在 linux 的 mysql 中可以查看刚刚新建的配置信息:
(6)至此,Nacos集群+MySQL集中式存储+Nginx负载均衡就搭建成功了。
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- What should I do if the SSL certificate prompts that it is expired or invalid?
- sql server duplicate values are counted after
- Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images
- System basics - study notes (some command records)
- The use of three parameters of ref, out, and Params in Unity3D
- Cocos Creator Mini Game Case "Stick Soldier"
- wc、grep、tar、vi/vim
- What is the website ICP record?
- 路由器和静态路由的配置
- Billions of IT operations in the market, the product by strength to speak
猜你喜欢
随机推荐
wc, grep, tar, vi/vim
D39_Eulerian Angles and Quaternions
D39_ coordinate transformation
从“双卡双待“到”双通“,vivo率先推动DSDA架构落地
Mina的长连接和短连接
Collection of error records (write down when you encounter them)
Transformer详细解读与预测实例记录
[ingress]-ingress使用tcp端口暴露服务
Into the pre-service, thought they play so flowers
Disk management and file systems
系统基础-学习笔记(一些命令记录)
7 steps to complete cloud monitoring
摆脱极域软件的限制
请问下通过flink sql读取hologres 的两张表的 binlog,然后如何进行join?
Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award
大小屏适配
Introduction to Network Layer Protocols
LeetCode练习及自己理解记录(1)
DisabledDate date picker datePicker
Wechat applet page jump to pass parameters