原文链接:https://www.javaspring.net/nacos/nacos-cluster-building

Continue to talk about the Nacos build of the production environment, through the previous 《Spring Cloud Alibaba basic tutorial: Nacos data persistence》 We already know the storage principle of Nacos for configuration information. When the cluster is built, you must use centralized storage, such as MySQL storage. Next, follow the previous article and continue to the next step. Through this article, we will complete the construction of the Nacos production environment.

1.Cluster Building

According to the official documentation, Nacos's cluster architecture is roughly as shown below (the MySQL that centralizes storing information is omitted):

Here we will introduce the details of each step of our construction step by step.

1.1.MySQL data source configuration

For the modification of the data source, the reason has been explained in the previous article Nacos Data Persistence. If you don't understand it, you can read this first and come back here.

Initialize and configure the MySQL data source before configuring the cluster. Mainly divided into the following two steps:

  • Step1: Initialize the MySQL database, the database initialization file: nacos-mysql.sql, can be obtained under the conf directory under the Nacos package.
  • Step 2: Modify the conf/application.properties file, add support for MySQL data source configuration, add (currently only mysql) data source url, username and password. Configuration examples are as follows:
spring.datasource.platform=mysql

db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=

More introduction and thinking, see the previous article "Nacos Data Persistence"

1.2.Cluster Configuration

There is a cluster.conf.example in Nacos's conf directory. You can remove the example extension and use that directly, or create a cluster.conf file separately, then open and configure the Nacos instance address to be deployed later.

This document uses three Nacos servers on different local endpoints as an example. You can configure the following:

127.0.0.1:8841
127.0.0.1:8842
127.0.0.1:8843

Note: The examples here are for local learning testing only, and the actual production environment must be deployed on different nodes in order to be highly available. In addition, the Nacos cluster requires 3 or more nodes and ensures that the three nodes are mutually accessible.

1.3.Launching an instance

After completing the above configuration, we can start to launch the Nacos instance on each node to form a Nacos cluster to use.

Since our test learning uses the local startup multi-instance in this article, there will be some differences with the real production deployment, so here are two cases to explain how to start each Nacos instance.

Local test

In this article, in the cluster configuration, we set up three Nacos instances are local, but different ports, so we need to modify the different port numbers when starting Nacos.

Here is a way to easily start three local instances of Nacos. We can copy the startup.sh script in the bin directory three times to start Nacos instances of three different ports, in order to make it easy to distinguish For the startup script of the instance, we can add the port number to the naming of the script, for example:

  • startup-8841.sh
  • startup-8842.sh
  • startup-8843.sh

Then, modify the parameters in the three scripts separately, as shown in the red part of the following figure (the port number is assigned according to the above script name):

Here we use the -Dserver.port method, in the start command, specify a specific port number for Nacos, in order to start three different Nacos instances on the machine to form a cluster.

After modifying the three script configurations, you can start the Nacos cluster locally by executing the following commands:

sh startup-8841.sh
sh startup-8842.sh
sh startup-8843.sh

Production Environment

In the actual production environment deployment, because each instance is distributed on different nodes, we can directly use the default startup script (unless you need to modify some JVM parameters, etc.). You only need to execute the sh startup.sh command in the bin directory of each node's Nacos.

2.Proxy Configuration

After the Nacos cluster is launched, we need to provide a unified portal for us to maintain and access the Spring Cloud application, as shown in the architecture diagram. To put it simply, we need to make an access point for the three Nacos instances launched above that can be load balanced for them. There are many ways to implement this. Here is a simple example of using Nginx.

In the http section of the Nginx configuration file, we can add the following configuration:

In this way, when we visit: http://localhost:8080/nacos/, it will be load-balanced proxy to the three Nacos instances we started before. Here we do not have a specific strategy for configuring upstream. By default, we use a linear rotation training method. If necessary, we can also configure a more complex distribution strategy. This part is the use of Nginx, and will not be described here.

Here is a question I encountered when trying to build. If you have encountered it, I hope the following instructions can help you solve the problem.

The error message is as follows:

2019-02-20 16:20:53,216 INFO The host [nacos_server] is not valid
Note: further occurrences of request parsing errors will be logged at DEBUG level. java.lang.IllegalArgumentException: The character [_] is never valid in a domain name.
at org.apache.tomcat.util.http.parser.HttpParser$DomainParseState.next(HttpParser.java:926)
at org.apache.tomcat.util.http.parser.HttpParser.readHostDomainName(HttpParser.java:822)
at org.apache.tomcat.util.http.parser.Host.parse(Host.java:71)
at org.apache.tomcat.util.http.parser.Host.parse(Host.java:45)
at org.apache.coyote.AbstractProcessor.parseHost(AbstractProcessor.java:288)
at org.apache.coyote.http11.Http11Processor.prepareRequest(Http11Processor.java:809)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:384)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

The main reason is that nacos_server was used as the name when configuring upstream, and the _ symbol does not appear in the domain name in the Tomcat version used by Nacos, so the screenshot above gives the upstream The name is nacosserver and the _ symbol is removed.

At this point, Nacos's cluster building is complete! We can access Nacos through the proxy address of Nginx configuration: http://localhost:8080/nacos/, which can also be configured in the Spring Cloud application as the access address of the registry and configuration center. The reader can use the code example at the end of the article to modify the original Nacos address to start, to see if the configuration information can be obtained to verify the success of the cluster setup. You can also deliberately close an instance to verify that the Nacos cluster is still working.

3.Think Deeply

Under the guidance of Nacos's official documentation, Nacos's cluster construction is generally very smooth, and there is not much difficulty. But one question worth considering is similar to the thinking about data persistence in the previous article. As a registry and configuration center, is Nacos' architecture too bloated? In addition to Nacos itself, there is a need to rely on more middleware to complete the entire production environment. Compared to other middleware that can be used for service discovery and configuration, it is not so advantageous. Especially for small teams, such complexity and cost investment are also considered when selecting a model.

4.Sample Code

The client code for the article. You can view the alibaba-nacos-config-client project in the following repository:

原文链接:https://www.javaspring.net/nacos/nacos-cluster-building

转载,请保留原文地址,谢谢 ~

Nacos Cluster Building的更多相关文章

  1. Easy and cheap cluster building on AWS backup

    https://grapeot.me/easy-and-cheap-cluster-building-on-aws.html Thu 17 July 2014 , by Yan Wang | 2 Co ...

  2. 从源码看Nacos的设计

    目录 客户端与集群的交互 数据同步 实例信息同步 服务集群信息 关于priv-raft协议 Nacos集群在k8s中的实践 这片博文来源于我在公司部门内的分享,我隐去了和公司项目相关的部分,重新整理, ...

  3. NACOS升级操作

    Server端 0.8.0及以上版本: 解压安装包后替换{nacos.home}/target/nacos-server.jar 删除{nacos.home}/plugins/cmdb/及{nacos ...

  4. nacos-docker安装nacos并配置数据库

    拉取nacos/nacos-server镜像 docker pull nacos/nacos-server 配置数据库(MySQL) 创建存储nacos配置的数据库 create database n ...

  5. MySQL优化面试

    原则:尽量使用整型表示字符串 存储IP INET_ATON(str),address to number INET_NTOA(number),number to address MySQL内部的枚举类 ...

  6. SkyWorking基础:6.2版本安装部署

    就在今天,SkyWorking发布了6.2版本. 概述 什么是SkyWorking SkyWalking是观察性分析平台和应用性能管理系统. 提供分布式追踪.服务网格遥测分析.度量聚合和可视化一体化解 ...

  7. MySQL优化/面试,看这一篇就够了

    原文链接:http://www.zhenganwen.top/articles/2018/12/25/1565048860202.html 作者:Anwen~链接:https://www.nowcod ...

  8. mysql 优化知识点

    附录: https://www.nowcoder.com/discuss/150059?type=0&order=0&pos=13&page=0 本文概要 概述 为什么要优化 ...

  9. 3万字总结,Mysql优化之精髓

    本文知识点较多,篇幅较长,请耐心学习 MySQL已经成为时下关系型数据库产品的中坚力量,备受互联网大厂的青睐,出门面试想进BAT,想拿高工资,不会点MySQL优化知识,拿offer的成功率会大大下降. ...

随机推荐

  1. 华为云 AI 实战营计划,带你迈上 AI 之路

    当今,AI的开发人才需求呈现极大的供需不平衡.所有开发者都关心,要如何从一名开发者晋升为AI开发者?AI开发能力,是主要的进入障碍.不用慌,华为云推出了 <华为云ModelArts-Lab AI ...

  2. 区块链学习笔记:D04 区块链在各行业领域的应用(二)

    这节课主要是政务领域.版权存证领域.能源领域的应用案例介绍 1.房屋租赁联盟链 特点:真实可信.透明补贴.便于追溯.公共监督 节点:房屋运营节点.房管局节点.社保局节点.财政局节点.教育部门节点(多节 ...

  3. mysql——中文数字排序的实现(FIELD)

    今天遇到一个需求,要求排序输出网格信息,但是数据是第三方对接插入的,并没有给我们排好顺序.所以只能自己动手了. 下图是原数据: 我们需要将其升序输出.使用mysql中的函数FIELD.语法如下: SE ...

  4. 简单实现jquery轮播图

    首先需要定义个切换图片的funcation ##### 1.找到图片所在li,将其显示出来,并缩放1.1倍 ##### 2.其他兄弟li,渐变隐藏,并还原至原大小比例 ##### 3.将底部的圆点列表 ...

  5. IDEA插件开发(一)一个简单的表单demo

  6. 使用SQL计算宝宝每次吃奶的时间间隔

    需求:媳妇儿最近担心宝宝的吃奶时间不够规律,网上说是正常平均3小时喂奶一次,让我记录下每次的吃奶时间,分析下实际是否偏差很大,好在下次去医院复查时反馈给医生. 此外,还要注意有时候哭闹要吃奶,而实际只 ...

  7. mac 开关机

    last | grep reboot (查看开机时间记录) last | grep shutdown (查看关机时间记录)

  8. [TimLinux] Python 装饰器

    1. 装饰器 一种语法格式,用于替换另外一个编码风格,一种语法糖,通过语法结构明确标识出这样一种语法. 自动在被装饰对象尾部执行代码(不使用装饰器语法时,需要明确写明的代码) 被装饰对象可以为函数.类 ...

  9. 2019ICPC 上海网络赛 G题 Substring(哈希)

    题意: 给了一个母串S, 每次循环给了一个模板串,问模板串在母 串中“匹配”了多少次?“匹配”的意思就是首字母和尾字母一样, 中间字母顺序可以换. 题解: 字符串hash.我们将询问字符串的首尾特殊h ...

  10. 【玩转SpringBoot】给自动配置来个整体大揭秘

    上一篇文章中提到的条件注解,只是自动配置整体解决方案中的一个环节而已,可以说是管中窥豹. 本文就逐步擦除迷雾,让整体浮现出来,这样就会有一个宏观的认识. 除了写代码之外,还能干点什么? 提到“配置”这 ...