Zookeeper搭建和集成motan服务

项目集成motan服务在这一篇日志中SpringBoot7 -- 简单集成motan服务治理框架

搭建zookeeper服务器

第一步:

    下载zookeeper.tar.gz,这里我下载的是zookeeper-3.4.9.tar.gz,===== 下载Zookeeper地址

    安装步骤网上一大把,我就不写具体步骤了,链接如下Zookeeper安装

第二步:

    单个的zookeeper按照第一步这样配置即可。

    集群方式第一步也有,但是我需要把我踩过的坑重点画出来,集群下,data目录 下的myid文件必须有,而且和配置的server节点的数字保持一致

server.1=IP1:2888:3888
server.2=IP2:2888:3888
server.3=IP3:2888:3888

myid分别为1,2,3,一定要配置. 

查看三个节点的状态  ./zkServer.sh status

leader


follower



第三步:配置zookeeper的监控工具

    使用exhibitor工具,下载路径点击打开链接,打包成jar,放在服务器的某个目录下

 启动命令

nohup java -jar exhibitor-1.5.6.jar -c file -port 8886 &

然后打开http://服务器IP:8886/exhibitor/v1/ui/index.html就可以查看运行状态了


    

    

第四步:集成motan服务

    在项目中创建motan.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:motan="http://api.weibo.com/schema/motan"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">

<!-- zookeeper -->
<motan:registry regProtocol="zookeeper" name="registry" address="IP1:2181,IP2:2181,IP3:2181"/>

<!-- 服务消费方 -->
<motan:referer id="service1"
               interface="com.xxx.rpc.api.接口"
               group="组" module="模块" version="1.0"
               registry="registry" requestTimeout="5000"/>

<!-- 服务消费方 -->
<bean id="beanId" class="服务提供方的实现类"/>
<!-- RPC服务 -->
<motan:service interface="com.xxx.rpc.api.接口"
               group="组" module="模块" version="1.0" ref="beanId"
               registry="registry" export="服务提供的端口"/>
</beans>

只需要在服务提供方和服务消费方的group和module保持一致即可,zookeeper有选举算法和变更推送等功能,关于zookeeper的详细内容,菜鸟的我正在学习中

猜你喜欢

转载自blog.csdn.net/qq_36781718/article/details/80270767
今日推荐