微服务注册管理中心的未来之星:Nacos

   日期:2020-10-04     浏览:298    评论:0    
核心提示:1.为什么Nacos?Nacos是一款微服务的注册和配置管理中心开源软件,是阿里巴巴贡献给开源社区的,其遵循Apache 2.0的开源协议,可以免费的使用于商业环境,而且阿里云上已经全面支持。其Github地址https://github.com/alibaba/nacos ,目前此开源项目已经有14.4k个星星了,已经非常厉害了!相对于Eureka,其不仅仅是微服务的注册中心,还能同时担任配置管理中心,界面也非常的友好。琦彦大神在其博客《微服务:注册中心ZooKeeper、Eureka、Cons

1.为什么Nacos?

Nacos是一款微服务的注册和配置管理中心开源软件,是阿里巴巴贡献给开源社区的,其遵循Apache 2.0的开源协议,可以免费的使用于商业环境,而且阿里云上已经全面支持。

其Github地址https://github.com/alibaba/nacos ,目前此开源项目已经有14.4k个星星了,已经非常厉害了!

相对于Eureka,其不仅仅是微服务的注册中心,还能同时担任配置管理中心,界面也非常的友好。琦彦大神在其博客《微服务:注册中心ZooKeeper、Eureka、Consul 、Nacos对比》 一文中对这些注册中心进行了详细的对比,对比的标准就是分布式系统设计当中的2个黄金定律:

  • CAP
1. 一致性(Consistency) (所有节点在同一时间具有相同的数据)
2. 可用性(Availability) (保证每个请求不管成功或者失败都有响应)
3. 分隔容忍(Partition tolerance) (系统中任意信息的丢失或失败不会
影响系统的继续运作)

具体的CAP理论,网上的资料很多就不在赘述。

  • BASE
    eBay的架构师Dan Pritchett源于对大规模分布式系统的实践总结,在ACM上发表文章提出BASE理论,BASE理论是对CAP理论的延伸,核心思想是即使无法做到强一致性(Strong Consistency,CAP的一致性就是强一致性),但应用可以采用适合的方式达到最终一致性(Eventual Consitency)。
    具体信息,大家可以参考《分布式系统的BASE理论》

琦彦大神在其博客《微服务:注册中心ZooKeeper、Eureka、Consul 、Nacos对比》 一文中,对这些注册中心的对比简单明了。可以用下面的一张表格表示。

从上面的表格中以及Nacos自身的官方文档 可以知道,其不仅支持SpringCloud全家桶中的SpringCloud的RESTful Service, 更支持K8S,gPRC,而且和阿里自己的一套微服务实现框架Dubbo也能无缝集成。

说了这么多,下面就一探其真容。其基本架构如下:

其主要组件是Nacos 服务器和Nacos的控制台。截至2020年10月2日,其最新的版本的是1.3.2,可以到此地址下载

注:因为Github上面下载Nacos的安装包的速度比较慢,笔者把最新的上传到了CSDN,零CSDN积分供大家下载,CSDN下载地址https://download.csdn.net/download/chancein007/12909981

2. Nacos 安装

Nacos的安装还是比较简单的,如果是单机版本的安装更简单。下载一个最新版本的Nacos,其默认支持Windows和Linux, 以Windows为例子。比如,笔者下载并解压缩到了E:\bigdata\nacos-server-1.3.2\nacos\bin,直接进入这个目录,输入下面的命令:

startup.cmd -m standalone

注意:一定要加启动模式,默认情况下是集群模式启动。启动的Log如下:

E:\bigdata\nacos-server-1.3.2\nacos\bin>startup.cmd -m standalone
"nacos is starting with standalone"

         ,--.
       ,--.'| ,--,: : | Nacos 1.3.2 ,`--.'`| ' :                       ,---.               Running in stand alone mode, All function modules
|   :  :  | |                      ' ,'\   .--.--.    Port: 8848
:   |   \ | :  ,--.--.     ,---.  /   /   | /  /    ' Pid: 13112 | : '  '; | / \ / \. ; ,. :| : /`./ Console: http://192.168.79.1:8848/nacos/index.html ' ' ;. ;.--. .-. | / / '' | |: :| : ;_ | | | \ | \__\/: . .. ' / ' | .; : \ \ `. https://nacos.io '   : |  ; .' ," .--.; |'   ; :__|   :    |  `----. \ | | '`--' / / ,. |'   | '.'|\   \  /  /  /`--' / ' : | ; : .' \ : : `----' '--'. / ; |.'     |  ,     .-./\   \  /            `--'---' '---' `--`---' `----' 2020-10-03 00:15:00,292 INFO Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$c7035815] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2020-10-03 00:15:00,437 INFO Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2020-10-03 00:15:00,445 INFO Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@7674b62c' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2020-10-03 00:15:00,450 INFO Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$ebd7fac7] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2020-10-03 00:15:00,462 INFO Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2020-10-03 00:15:01,578 INFO Tomcat initialized with port(s): 8848 (http)

2020-10-03 00:15:01,827 INFO Root WebApplicationContext: initialization completed in 8794 ms

2020-10-03 00:15:17,800 INFO Initializing ExecutorService 'applicationTaskExecutor'

2020-10-03 00:15:18,092 INFO Adding welcome page: class path resource [static/index.html]

2020-10-03 00:15:18,954 INFO Creating filter chain: Ant [pattern='*.css,*.js,*.html,*.map,*.svg,*.png,*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
### The auth system to use, currently only 'nacos' is supported:
nacos.core.auth.system.type=nacos
### If turn on auth system:
nacos.core.auth.enabled=false
### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=18000
### The default token:
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true
#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

注意:修改上面的文件后,需要实现自己创建一张nacos的数据库表,并执行其conf文件夹下的nacos-mysql.sql数据库脚本,比如笔者本机:E:\bigdata\nacos-server-1.3.2\nacos\conf\nacos-mysql.sql

执行完SQL语句后,其会有下面的表格出现:

笔者添加一个用户devops,这个时候,我们在数据库里面就能看到这个新添加的用户了。

3. Nacos与SpringCloud的集成

在其官方网站 提供了详细的步骤。
而且其官方网站也提供了一个Github的代码的地址。

4. 总结

本文主要和大家一起回顾了一下,为什么选择Nacos产品作为注册中心,因为其不仅仅提供了注册中心的功能,也提供了配置管理中心的功能,而且其产品也在生产环境中得到验证。其管理界面的功能也做的非常的好,还自带权限管理功能。笔者强烈推荐大家,可以在自己的项目尝试用一下~

参考文献:
https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html
https://blog.csdn.net/fly910905/article/details/100023415
http://www.hollischuang.com/archives/672

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服