菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
22
0

Dubbo分布式学习

原创
05/13 14:22
阅读数 77081

1.1.1Dubbo的简单介绍

  1.1.1.1什么是PRC

  RPC【Remote Procedure Call】是指远程过程调用,是一种进程间通信方式,他是一种技术的思想,而不是规范。它允许程序调用另一个地址空间(通常是共享网络的另一台机器上)的过程或函数,而不用程序员显式编码这个远程调用的细节。即程序员无论是调用本地的还是远程的函数,本质上编写的调用代码基本相同。

  

RPC两个核心模块:通讯,序列化。

1.1.2Dubbo的核心概念

  1.1.2.1Dubbo简介

  pache Dubbo (incubating) |ˈdʌbəʊ| 是一款高性能、轻量级的开源Java RPC框架,它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务自动注册和发现。

  1.1.2.2Dubbo基本概念

  服务提供者(Provider:暴露服务的服务提供方,服务提供者在启动时,向注册中心注册自己提供的服务。

  服务消费者(Consumer: 调用远程服务的服务消费方,服务消费者在启动时,向注册中心订阅自己所需的服务,服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。

  注册中心(Registry:注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者

  监控中心(Monitor:服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心

  •  调用关系说明:
  •  服务容器负责启动,加载,运行服务提供者。
  •  服务提供者在启动时,向注册中心注册自己提供的服务。
  •  服务消费者在启动时,向注册中心订阅自己所需的服务。
  •  注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。
  •  服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。
  •  服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。

1.1.3,zookeeper单机版安装过程

  1.1.3.1 先将Zookeeper进行文件解压[前提条件是linux装了jdk和maven]

 

  1.1.3.2 修改zoo.cfg文件

    进入目录,在conf目录下将zoo_sample.cfg复制一份改名为zoo.cfg文件,修改为如下内容[dataDir和dataLogDir]

 1 # The number of milliseconds of each tick
 2 tickTime=2000
 3 # The number of ticks that the initial
 4 # synchronization phase can take
 5 initLimit=10
 6 # The number of ticks that can pass between
 7 # sending a request and getting an acknowledgement
 8 syncLimit=5
 9 # the directory where the snapshot is stored.
10 # do not use /tmp for storage, /tmp here is just
11 # example sakes.
12 dataDir=/usr/local/src/zookeeper/apache-zookeeper-3.6.0-bin/dataDir/data    #配置zookeeper Datadir路径
13 dataLogDir=/usr/local/src/zookeeper/apache-zookeeper-3.6.0-bin/dataDir/log      #配置zookeeper的日志
14 # the port at which the clients will connect
15 clientPort=2181
16 admin.serverPort=2282
17 # the maximum number of client connections.
18 # increase this if you need to handle more clients
19 #maxClientCnxns=60
20 #
21 # Be sure to read the maintenance section of the
22 # administrator guide before turning on autopurge.
23 #
24 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
25 #
26 # The number of snapshots to retain in dataDir
27 #autopurge.snapRetainCount=3
28 # Purge task interval in hours
29 # Set to "0" to disable auto purge feature
30 #autopurge.purgeInterval=1
31 
32 ## Metrics Providers
33 #
34 # https://prometheus.io Metrics Exporter
35 #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
36 #metricsProvider.httpPort=7000
37 #metricsProvider.exportJvmInfo=true

  1.1.3.3 配置zookeeper全局环境  命令:vi /etc/profile

#zookeeper的安装
export ZOOKEEPER=/usr/local/src/zookeeper/apache-zookeeper-3.6.0-bin/
export PATH=$PATH:$ZOOKEEPER/bin

  1.1.3.4启动zookeeper  因为配置了环境 命令哪里都能写  命令:zkServer.sh start  成功如图

1.1.4 配置Dubbo-Admin    

  1.1.4.1下载Dubbo-Admin  

    百度网盘地址:链接:https://pan.baidu.com/s/1OeYCayz0iTKdy4KkHpdQUQ 提取码:s0g9
    GIT地址地址: 链接:https://github.com/alibaba/dubbo  --GIT下载安装另行百度

  1.1.4.2修改Dubbo-Admin配置 

    进入dubbo-admin-0.0.1-SNAPSHOT.jar的BOOT-INF\classes目录修改application.properties就修改dubbo.registry.address=本地zookeeperip 其他不动

 1 #
 2 # Licensed to the Apache Software Foundation (ASF) under one or more
 3 # contributor license agreements.  See the NOTICE file distributed with
 4 # this work for additional information regarding copyright ownership.
 5 # The ASF licenses this file to You under the Apache License, Version 2.0
 6 # (the "License"); you may not use this file except in compliance with
 7 # the License.  You may obtain a copy of the License at
 8 #
 9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 
18 server.port=7001
19 spring.velocity.cache=false
20 spring.velocity.charset=UTF-8
21 spring.velocity.layout-url=/templates/default.vm
22 spring.messages.fallback-to-system-locale=false
23 spring.messages.basename=i18n/message
24 spring.root.password=root
25 spring.guest.password=guest
26 
27 dubbo.registry.address=zookeeper://192.168.92.111:2181

  1.1.4.3启动Dubbo-Admin

    进入dubbo-admin-0.0.1-SNAPSHOT.jar所在文件目录,执行cmd命令:java -jar dubbo-admin-0.0.1-SNAPSHOT.jar    

  1.1.4.4访问Dubbo-Admin   默认账户:root 密码root  

1.1.5 Dubbo高可用

  1.1.5.1 zookeeper宕机是否还能直连dubbo的问题

    现象:zookeeper注册中心宕机,还可以消费dubbo暴露的服务。
      原因:  
      健壮性

      • 监控中心宕掉不影响使用,只是丢失部分采样数据
      • 数据库宕掉后,注册中心仍能通过缓存提供服务列表查询,但不能注册新服务
      • 注册中心对等集群,任意一台宕掉后,将自动切换到另一台
      • 注册中心全部宕掉后,服务提供者和服务消费者仍能通过本地缓存通讯
      • 服务提供者无状态,任意一台宕掉后,不影响使用
      • 服务提供者全部宕掉后,服务消费者应用将无法使用,并无限次重连等待服务提供者恢复

  1.1.5.2 集群下dubbo负载均衡配置 [建议详细百度下负载均衡机制]

在集群负载均衡时,Dubbo 提供了多种均衡策略,缺省为 random 随机调用,负载均衡策略。

 

 

Random LoadBalance

随机,按权重设置随机概率。

在一个截面上碰撞的概率高,但调用量越大分布越均匀,而且按概率使用权重后也比较均匀,有利于动态调整提供者权重。

RoundRobin LoadBalance

轮循,按公约后的权重设置轮循比率。

存在慢的提供者累积请求的问题,比如:第二台机器很慢,但没挂,当请求调到第二台时就卡在那,久而久之,所有请求都卡在调到第二台上。

LeastActive LoadBalance

最少活跃调用数,相同活跃数的随机,活跃数指调用前后计数差。

使慢的提供者收到更少请求,因为越慢的提供者的调用前后计数差会越大。

ConsistentHash LoadBalance

一致性 Hash,相同参数的请求总是发到同一提供者。

当某一台提供者挂时,原本发往该提供者的请求,基于虚拟节点,平摊到其它提供者,不会引起剧烈变动。算法参见:http://en.wikipedia.org/wiki/Consistent_hashing

缺省只对第一个参数 Hash,如果要修改,请配置 <dubbo:parameter key="hash.arguments" value="0,1" />

缺省用 160 份虚拟节点,如果要修改,请配置 <dubbo:parameter key="hash.nodes" value="320" />

发表评论

0/200
22 点赞
0 评论
收藏