Dubbo-Zookeeper注册中心;监控中心
一、ZooKeeper注册中心
对于服务提供方,它需要发布服务,而且由于应用系统的复杂性,服务的数量、类型也 不断膨胀;对于服务消费方,它最关心如何获取到它所需要的服务,而面对复杂的应用系统,需要管理大量的服务调用。
而且,对于服务提供方和服务消费方来说,他们还有可能兼具这两种角色,即需要提供服务,有需要消费服务。 通过将服务统一管理起来,可以有效地优化内部应用对服务发布使用的流程和管理。服务注册中心可以通过特定协议来完成服务对外的统一
Dubbo 提供的注册中心有如下几种类型可供选:
Multicast 注册中心:组播方式
Redis 注册中心:使用 Redis 作为注册中心
Simple 注册中心:就是一个 dubbo 服务。作为注册中心。提供查找服务的功能。
Zookeeper 注册中心:使用 Zookeeper 作为注册中心
Dubbo推荐使用 Zookeeper 注册中心
Zookeeper是Apache下一个高性能的,分布式的,开放源码的分布式应用程序协调服务。简称 zk
ZooKeeper主要服务于分布式系统,可以用ZooKeeper来做:统一配置管理、统一命名服务、分布式锁、集群管理
ZooKeeper官网
Apache ZooKeeper
注:
Zookeeper 运行需要 java 环境
(一)Windows下安装ZooKeeper
1、zookeeper官网 https://zookeeper.apache.org/index.html
https://zookeeper.apache.org/releases.html#download
2、下载之后解压到目标路径即可
(二)zoo.cfg配置文件
1、进入conf目录下,复制 zoo_sample.cfg文件,并将其改名为 zoo.cfg
2、修改zoo.cfg 配置文件
配置文件主要参数如下:
#ZK中的时间配置最小但域,其他时间配置以整数倍tickTime计算
tickTime=2000
#Leader允许Follower启动时在initLimit时间内完成数据同步,单位:tickTime
initLimit=10
#Leader发送心跳包给集群中所有Follower,若Follower在syncLimit时间内没有响应,那么Leader就认为该follower已经挂掉了,单位:tickTime
syncLimit=5
#配置ZK的数据目录
dataDir=/usr/local/zookeeper/data
#用于接收客户端请求的端口号
clientPort=2181
#配置ZK的日志目录
dataLogDir=/usr/local/zookeeper/logs
#ZK集群节点配置,端口号2888用于集群节点之间数据通信,端口号3888用于集群中Leader选举
server.1=192.168.123.100:2888:3888
server.2=192.168.123.101:2888:3888
进入到 bin 目录下,点击 zkServer.cmd
或者 在 bin 目录下 输入 “cmd”命令
看到绑定成功即可
使用ZooKeeper示例
1、创建maven Java模块
IDEA下执行install命令,打成jar包
2、创建 maven web 服务提供者
pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.mycompany</groupId><artifactId>dubbo-3-zk-userservice-provider</artifactId><version>1.0.0</version><packaging>war</packaging><dependencies><!--Spring依赖--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.1.4.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.1.4.RELEASE</version></dependency><!--dubbo依赖--><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.6.2</version></dependency><!--接口工程依赖--><dependency><groupId>com.mycompany.dubbo</groupId><artifactId>dubbo-3-zk-interface</artifactId><version>1.0.0</version></dependency><!-- zookeeper依赖 --><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>4.3.0</version></dependency></dependencies><build><plugins><!--JDK1.8编译插件--><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>
</project>
dubbo-zk-userservice-provider.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"><!-- 服务提供者声明名称:必须保证服务名称的唯一性(dubbo内部使用的唯一标识符)--><dubbo:application name="dubbo-3-zk-userservice-provider" /><!-- 访问服务协议的名称以及端口号,dubbo官方推荐使用dubbo协议,端口号默认20880name:指定协议名称port:指定协议的端口号(默认为20880)--><dubbo:protocol name="dubbo" port="20880"/><!-- 使用zookeeper注册中心指定注册中心地址和端口号--><!--使用本机中的 zookeeper注册中心--><dubbo:registry address="zookeeper://localhost:2181" /><!--使用linux系统中的zookeeper服务-->
<!-- <dubbo:registry address="zookeeper://192.168.133.128:2181"/>--><!-- 暴露服务接口dubbo:serviceinterface:暴露服务接口的全限定类名ref:接口引用的实现类在spring容器中的标识registry:如果不使用注册中心,值为:N/A--><dubbo:service interface="com.mycompany.dubbo.service.UserService" ref="userService" /><!-- 将接口实现类加载到spring容器 --><bean id="userService" class="com.mycompany.dubbo.service.impl.UserServiceImpl" /></beans>
如果有多个服务提供者
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"><!-- 服务提供者声明名称:必须保证服务名称的唯一性(dubbo内部使用的唯一标识符)--><dubbo:application name="dubbo-3-zk-userservice-provider" /><!-- 访问服务协议的名称以及端口号,dubbo官方推荐使用dubbo协议,端口号默认20880name:指定协议名称port:指定协议的端口号(默认为20880)--><dubbo:protocol name="dubbo" port="20880"/><!-- 使用zookeeper注册中心指定注册中心地址和端口号--><!--使用本机中的 zookeeper注册中心--><dubbo:registry address="zookeeper://localhost:2181" /><!--使用linux系统中的zookeeper服务-->
<!-- <dubbo:registry address="zookeeper://192.168.133.128:2181"/>--><!-- 暴露服务接口dubbo:serviceinterface:暴露服务接口的全限定类名ref:接口引用的实现类在spring容器中的标识registry:如果不使用注册中心,值为:N/A--><dubbo:service interface="com.mycompany.dubbo.service.UserService" ref="userService" version="1.0.0" timeout="15000"/><dubbo:service interface="com.mycompany.dubbo.service.UserService" ref="userService2" version="2.0.0" /><!-- 将接口实现类加载到spring容器 --><bean id="userService" class="com.mycompany.dubbo.service.impl.UserServiceImpl" /><bean id="userService2" class="com.mycompany.dubbo.service.impl.UserServiceImpl2" /></beans>
web.xml
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:dubbo-zk-userservice-provider.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
3、创建maven web 消费者
pom.xml
<groupId>com.mycompany.dubbo</groupId><artifactId>dubbo-3-zk-consumer</artifactId><version>1.0.0</version><packaging>war</packaging><dependencies><!--Spring依赖--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.1.4.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.1.4.RELEASE</version></dependency><!--dubbo依赖--><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.6.2</version></dependency><!--接口工程依赖--><dependency><groupId>com.mycompany.dubbo</groupId><artifactId>dubbo-3-zk-interface</artifactId><version>1.0.0</version></dependency><!-- zookeeper依赖 --><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>4.3.0</version></dependency></dependencies><build><plugins><!--JDK1.8编译插件--><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>
UserController
@Controller
public class UserController {@Autowiredprivate UserService userService;@RequestMapping(value = "/userDetail")public String userDetail(Model model,Integer id){//根据用户标识获取用户详情User user = userService.queryUserById(id);//获取用户总人数Integer allUserCount = userService.queryAllUserCount();model.addAttribute("user",user);model.addAttribute("allUserCount",allUserCount);return "userDetail";}
}
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--扫描组件--><context:component-scan base-package="com.mycompany.dubbo.controller"/><!--配置注解驱动--><mvc:annotation-driven/><!--视图解析器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/"/><property name="suffix" value=".jsp"/></bean>
</beans>
dubbo-zk-consumer.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"><!--声明dubbo服务消费者名称:保证唯一性--><dubbo:application name="dubbo-3-zk-consumer"/><!--指定注册中心--><dubbo:registry address="zookeeper://localhost:2181"/><!--使用linux系统中的zookeeper服务-->
<!-- <dubbo:registry address="zookeeper://192.168.133.128:2181"/>--><!--引用远程接口服务--><dubbo:reference id="userService" interface="com.mycompany.dubbo.service.UserService"/></beans>
如果有多个消费者
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"><!--声明dubbo服务消费者名称:保证唯一性--><dubbo:application name="dubbo-4-zk-multi-consumer"/><!--指定注册中心--><dubbo:registry address="zookeeper://localhost:2181"/><!--使用linux系统中的zookeeper服务-->
<!-- <dubbo:registry address="zookeeper://192.168.133.128:2181"/>--><!--引用远程接口服务--><dubbo:reference id="userService" interface="com.mycompany.dubbo.service.UserService" version="1.0.0" /><dubbo:reference id="userService2" interface="com.mycompany.dubbo.service.UserService" version="2.0.0" /></beans>
web.xml
<servlet><servlet-name>dispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml,classpath:dubbo-zk-consumer.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
配置Tomcat访问
二、监控中心
dubbo 的使用,其实只需要有注册中心,消费者,提供者这三个就可以使用了,但是并不能看到有哪些消费者和提供者,为了更好的调试,发现问题,解决问题,因此引入dubbo-admin
通过 dubbo-admin 可以对消费者和提供者进行管理。可以在 dubbo 应用部署做动态的调整,服务的管理。
1、下载监控中心,https://github.com/alibaba/dubbo
2、通过IDEA将其打包war
3、把 dubbo-admin.war 文件拷贝到 tomcat 的 webapps
4、通过压缩工具打开dubbo-admin-2.5.10.war包 应用的 WEB-INF/dubbo-properties 文件,内容如下
5、在浏览器地址栏输入 http://localhost:8080/dubbo-admin ;访问监控中心-控制台
Dubbo-Zookeeper注册中心;监控中心相关推荐
- 微服务 注册中心的作用_微服务架构Dubbo之注册中心(Zookeeper)
注册中心简介 在微服务架构中,注册中心是核心的基础服务之一.在微服务架构流行之前,注册中心就已经开始出现在分布式架构的系统中.Dubbo是一个在国内比较流行的分布式框架,被大量的中小型互联网公司所采用 ...
- (十二)springmvc+mybatis+dubbo+zookeeper分布式架构 整合 - zookeeper注册中心安装
今天我们来学习基于zookeeper注册中心的安装. 注册中心 1.建议使用dubbo-2.3.3以上版本的使用zookeeper注册中心客户端 2.Zookeeper是Apache Hadoop的子 ...
- Dubbo 集成 ZooKeeper 注册中心实现服务调用
Dubbo 是基于Java的开源的RPC的分布式服务框架,目前是 Apache 项目. 推荐使用 ZooKeeper 做注册中心,当然也可以支持 Redis, Multicast 和Simple. D ...
- 淘宝SOA框架dubbo学习(2)--搭建Zookeeper注册中心服务
2019独角兽企业重金招聘Python工程师标准>>> 继上一篇博文, 淘宝SOA框架dubbo学习(1) http://my.oschina.net/hanshubo/blog/3 ...
- 后台服务系统之搭建ZooKeeper注册中心
dubbo支持多种注册中心,推荐使用ZooKeeper. http://dubbo.apache.org/zh-cn/docs/user/references/registry/zookeeper.h ...
- 微服务系列之ZooKeeper注册中心和Nacos注册中心Nacos和Zookeeper对比
一.ZooKeeper注册中心 Zookeeper 是 Apache Hadoop 的子项目,是一个树型的目录服务,支持变更推送,适合作为 Dubbo 服务的注册中心,工业强度较高,可用于生产环境,推 ...
- linux 查看zookeeper目录,查看zookeeper注册中心是否有注册服务
查看zookeeper注册中心是否有注册服务可以在服务器上看,也可以在dubboadmin看哦~ 1.在服务器上看: 1)查找zookeeper的目录: find / -name zookeeper ...
- 亲!你的专属Dubbo启动注册中心,请注意查收!
现在来说一下dubbo注册中心的大致结构,请看下图: Java学习笔记开源框架--dubbo启动之注册中心(Registry) 服务注册 对于服务提供方,它需要发布服务,而且由于应用系统的复杂性,服务 ...
- 3.spring cloud + zookeeper注册中心 + Feign调用案例
3.spring cloud + zookeeper注册中心 + Feign调用案例 3.1.pom.xml定义 <?xml version="1.0" encoding=& ...
- Spring Cloud 系列之 ZooKeeper 注册中心
什么是注册中心 服务注册中心是服务实现服务化管理的核心组件,类似于目录服务的作用,主要用来存储服务信息,譬如提供者 url 串.路由信息等.服务注册中心是微服务架构中最基础的设施之一. 注册中心可以说 ...
最新文章
- CodeProject 文章概览:ASP.NET 模板相关内容
- 实战Cacti网络监控(1)——基础安装配置
- 用final修饰的HashMap,到底可不可以修改??
- 连载:阿里巴巴大数据实践—数据服务
- php xml 四种,xml中常见的四种解析方式是什么?
- 没有终结点在侦听可以接受消息的_【大卫聊股】2019.05.05 周末重要消息分析及下周一走势预判...
- #1130 - Host 'localhost' is not allowed to connect to this MySQL server
- python 姿势估计_Python中的实时头姿势估计
- (可再看)深度学习学习笔记(1)
- mysql 删除数据后myd_关于mysql 删除数据后(.MYD,MYI)物理空间未释放
- Quartus18.1安装USB Blaster驱动蓝屏
- 项目实训(十三)安装pun,pun的基础使用和概念
- 1960-征战的Loy
- Warning: Accessing non-existent property ‘cat‘ of module exports inside circular dependency
- 数据库的四种隔离级别及对应解决的脏读、不可重复读、幻读问题
- Android 更改menu的背景颜色和字体颜色
- python游戏联机_CoderZh首款Python联机对战游戏 - NancyTetris1.0倾情发布(一)
- nslookup 查邮件服务器地址
- [转]一个纸杯的测试用例
- JDK8新特性(三):集合之 Stream 流式操作
热门文章
- mysql数据库select语句用法_mysql数据库select查询语句简单用法
- 【爬虫】利用Python爬虫爬取小麦苗itpub博客的所有文章的连接地址并写入Excel中(2)...
- SpringBoot Hanlp的集成
- WebView打开第三方APP
- 前端开发vue技术栈程序员的vs code插件分享
- PC端 UC浏览器页面显示该站点安全证书的吊销不可用
- ThinkPad S5 升级安装Windows10后 连上网络后系统假死
- 锐龙r9 5900hx相当于英特尔的什么 r9 5900hx属于什么档次
- 美国的学位制度以及各学位的英文简写
- UEFI下的Gmac驱动实现