• 代码下载:https://download.csdn.net/download/typ1805/10485048
  • 微服务架构成了当下的技术热点,实现微服务是要付出很大成本的,但也许是因为微服务的优点太过于吸引人,以至于大部分开发者都将它当成未来的发展趋势。

微服务架构的演进过程

  • dubbo的用户手册中介绍了服务化架构的进化过程,如下图:
    springboot+dubbo+myBatis实现微服务集成

微服务的技术关注点

  • 要实现一个微服务的架构,我们需要关注的技术点包括:服务注册、发现、负载均衡和健康检查,前端路由(网关),容错,服务框架的选择,动态配置管理等模块。这些模块可以组成一个简化的微服务架构图如下:
    springboot+dubbo+myBatis实现微服务集成

使用dubbo+zookeeper实现简化的微服务架构

    第一步:zookeeper集群的部署
使用zookeeper作为dubbo的注册中心,部署起来并不麻烦。为了保持注册中心的高可用性,在生产环境下我们需要配置多个zookeeper协同运行。在集群模式下,zookeeper会基于Paxos算法从集群中选择一台作为leader,其他机器作为follower,注册中心的数据都以leader为准。一台zk机器成为leader的条件是超过这台机器是可用的,且被超过半数的机器选举为leader。基于这种实现方式,我们选择zk集群的数量时最好为奇数个,最少为3个,这样只要有超过半数的zk机器存活那注册中心就是可用的。
注:如果我们选择2台机器作为zk的集群,那只要有一台zk挂掉,另一台机器就无法得到超过半数的选票,那么这个zk集群就直接失效了。因此选2台机器作为zk集群的稳定性在理论上不如一台机器作为注册中心的稳定性。

以3台机器作为zk集群为例,每台zk的具体部署方式为:

1、下载安装包并解压到安装目录,zookeeper安装包的下载地址为:http://www.apache.org/dist/zookeeper/
2、进入解压目录的conf文件夹,配置zookeeper启动的基本参数。
在conf文件夹下有一个 zoo_sample.cfg的文件,是zk启动的配置样例,zookeeper进程在启动的时候会找zoo.cfg文件作为默认的配置文件,所以我们复制一个名称为zoo.cfg的文件,并编辑其中的配置信息如下:
springboot+dubbo+myBatis实现微服务集成
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=D:/zookeeper-3.4.12/data
dataLogDir=D:/zookeeper-3.4.12/logs
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

# zookeeper集群的部署
# server.A=B:C:D
#  A为数字,标识这条配置为第几个zk服务器,即机器id
#  B为host名,标识这个服务器的主机地址
#  C和D为zk集群的成员用于选举leader时的通讯端口
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
View Code

相关文章:

  • 2023-04-02
  • 2021-07-11
  • 2022-12-23
  • 2022-01-15
  • 2021-10-21
  • 2021-04-13
  • 2020-12-30
猜你喜欢
  • 2021-09-28
  • 2021-07-28
  • 2019-01-03
  • 2021-12-29
  • 2021-08-24
  • 2021-07-05
  • 2021-08-29
相关资源
相似解决方案