




已阅读5页,还剩49页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一:zookeeper的下载及配置:一:zookeeper下载:下载地址:/apache/zookeeper/zookeeper-3.4.6/点击zookeeper-3.4.6.tar.gz 下载即可!二:zookeeper配置:Zookeeper下载后的目录,如图:1)配置路径:/conf目录下面的 zoo_sample.cfg复制并修改为zoo.cfg此处名称必须是zoo.cfg 否则启动文件找不到会出现闪退现象。tickTime:Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。initLimit:集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。syncLimit:集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。dataDir:Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。dataLogDir:Zookeeper保存日志文件的目录。clientPort:客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。=代码如下=# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/data# the port at which the clients will connectclientPort=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.# /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即可。2)路径修改# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=C:/Users/issuser/Desktop/service1/datadataLogDir=C:/Users/issuser/Desktop/service1/log# the port at which the clients will connectclientPort=2183# 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.# /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二:创建项目一:做服务端:1)创建一个web 项目:DubboZookeeper 作为服务端。2)定义一个实体类:Userpublic class User Overridepublic String toString() return User name= + name + , age= + age + , sex= + sex + ;private String name;private int age;private String sex;public String getName() return name;public void setName(String name) = name;public int getAge() return age;public void setAge(int age) this.age = age;public String getSex() return sex;public void setSex(String sex) this.sex = sex;3)定义一个service接口:DemoServicepublic interface DemoService String sayHello(String name); public List getUsers(); 4)定义一个service接口的实现类,DemoServiceImpl public class DemoServiceImpl implements DemoService Overridepublic String sayHello(String name) return Hello + name; Overridepublic List getUsers() List list = new ArrayList();User u1 = new User();u1.setName(jack);u1.setAge(20);u1.setSex(男);User u2 = new User();u2.setName(tom);u2.setAge(21);u2.setSex(女);User u3 = new User();u3.setName(rose);u3.setAge(19);u3.setSex(女);list.add(u1);list.add(u2);list.add(u3);return list;5)创建一个dao的测试类Provider:(使用JUnit测试)public class Provider Beforepublic void setUp() throws Exception Testpublic void testMain() throws IOException ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String applicationContext.xml );context.start();System.in.read();/ 按任意键退出 6)创建XML配置文件:applicationContext.xml(注意:此处的路径必须是项目的路径,能ctrl+鼠标点进去) Dubbo服务配置!- 使用zookeeper注册中心暴露服务地址 - 7)引用的jar包:二:做客户端:1)创建新项目:DubboTest2)创建测试类Consumer :(用JUnit测试)public class Consumer Beforepublic void setUp() throws Exception Testpublic void testMain() throws IOException ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String applicationContext.xml ); context.start(); DemoService demoService = (DemoService) context.getBean(demoService); String hello = demoService.sayHello(tom); System.out.println(Thread.currentThread().getName() + hello); System.in.read(); 3)创建客户端的xml测试访问dubbo:applicationContext.xml !- - 4)注意此处的 要与服务端的 路径要一致!5)与服务端的一样,要使用jar包:Zookeeper正常启动的样子会显示端口号,此处端口号为2181不启动zookeeper后台报错信息:正常连接后,后台信息:Zookeeper的信息:强制关闭服务后的zookeeper信息Zookeeper集群只要集群上大多数的Zookeeper服务启动了,那么总的zookeeper服务将是可用的。推荐集群中部署奇数个节点,由于zookeeper挂掉一半的机器集群就不可用,所以部署4台和3台的集群都是在挂掉2台后集群不可用单个zookeeper的包结构:集群需要修改的东西:为了好区分我将zookeeper-3.4.6改名为server1 (结构图如下)新建两个文件夹: data 与 log data 文件夹存放数据log 文件夹存放日志在data文件夹下,新建myid 文件(注意:无后缀名)myid 文件里写的数字 要与zoo.cfg中配置的数字一直。下面有详细图解:此处的myid我写的是数字1配置zoo.cfg 文件1. 如单个zookeeper服务一样,需要配置zoo.cfg文件!文件在conf 文件夹下2.3. 到此,一个zookeeper的集群配置完成了,想测试集群就复制多份!此处我复制了三份!4. 为了好区分,我给改了三个名字!其余的两份,需要修改的是zoo.cfg中的路径!多个zookeeper需要修改的地方zoo.cfg 文件:myid文件:项目中的配置多个zookeeper路径perties中 配置:dubbo.registry.address=zookeeper:/61:2181?backup=62:2181,63:2181或者spring-dubbo.xml中配置:Zookeeper集群启动截图:依次启动启动server1服务启动server2服务启动server3服务服务server3启动后server1服务显示:服务server3启动后server2服务显示:启动服务端项目zookeeper启动后:启动服务项目后,zookeeper状态:服务项目启动后,控制台打印:启动客户端项目启动服务端后,zookeeper的状态:启动客户端后,zookeeper的状态:启动客户端项目后,控制台打印:将zookeeper的一个服务停掉将端口号为2182的zookeeper服务关掉:客户端项目后台显示:服务端项目后台显示:将zookeeper的第二个服务停掉第三个服务信息打印:服务端项目,后台信息显示:客户端项目,后台信息显示:结论zookeeper服务总数2n个,关掉n-1个服务,项目是可以正常运行的!但挂掉一半以上,项目是启动不起来的!Linux查看状态命令Duboo注解接口类项目:DubboServiceInterface仅仅是一个接口类项目!接口是普通接口!注意:将接口类项目打包成jar分别放入服务端项目跟客户端项目!服务端项目:DubboServiceProvider实现类fooserviceImpl.javapackage com.alibaba.dubbo.demo.imp;import com.alibaba.dubbo.config.annotation.Service;import com.alibaba.dubbo.demo.DemoService;Service(version=1.0)public class FooServiceImpl implements DemoService Overridepublic String sayHello(String name) return Hello + name; web.xml 配置扫描内容 DubboServiceProviderspringorg.springframework.web.servlet.DispatcherServlet1spring* org.springframework.web.context.ContextLoaderListener contextConfigLocationclasspath*:applicationContext.xmlapplicationContext.xml 配置 !- - !- -测试类Providerpackage com.alibaba.dubbo.test;import java.io.IOException;import org.junit.Before;import org.junit.Test;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Provider Beforepublic void setUp() throws Exception Testpublic void testMain() throws IOException ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String applicationContext.xml );context.start();System.in.read();/ 按任意键退出 lib下的jar
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025资料员之资料员基础知识通关考试题库附完整答案详解【历年真题】
- 2025漯河职业技术学院传统康复治疗技术期末试题预测试卷含完整答案详解(必刷)
- 中班音乐欣赏教案
- 消防安全员模拟测试及答案
- 人教版8年级数学下册《一次函数》专题测评试题(解析卷)
- 强化训练-人教版8年级数学上册《全等三角形》综合训练试题(含详细解析)
- 2024年工程硕士练习题带答案详解(综合题)
- 2024自考专业(护理)考前冲刺试卷附答案详解【能力提升】
- 2025年中医执业医师检测卷含答案详解【夺分金卷】
- 2024施工员练习题附参考答案详解(综合题)
- 部编版小学一年级上册语文带拼音阅读练习题26篇
- 无机及分析化学第2章-化学热力学基础1
- GB/T 2930.1-2017草种子检验规程扦样
- 会计学原理模拟试题一套
- 第一章-宗教社会学的发展和主要理论范式课件
- 国内外新能源现状及发展趋势课件
- 临床常见护理技术操作常见并发症的预防与处理课件
- 高速公路改扩建桥梁拼宽施工技术及质量控制
- 双台110kV主变短路电流计算书
- 你不懂咖啡课件
- 危险物品储存安全隐患排查整治表
评论
0/150
提交评论