0


windows安装Zookeeper

1.zookeeper下载

zookeeper下载地址http://archive.apache.org/dist/zookeeper/

在这里插入图片描述
在这里插入图片描述
下载后解压到自己想要的位置,zookeeper是免安装的。这时我们安装好了进行下面配置

  • 在zookeeper目录下创建datalog两个文件夹,可以先备份一份zoo_sample.cfg,再把conf目录下的zoo_sample.cfg改名成zoo.cfg,并修改zoo.cfg的dataDir目录

在这里插入图片描述
在这里插入图片描述

  • zoo.cfg文件修改内容
# 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=/tmp/zookeeper
#修改内容
dataDir=D:\\zookeeper-3.4.13\\data 
dataLogDir=D:\\zookeeper-3.4.13\\log 
# 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

2.环境变量配置

需要配置一下环境变量才可以运行zookeeper(基于Windows已经配置过JAVA_HOME并且配置正确)

  • 新增环境变量:ZOOKEEPER_HOME
  • 变量值: D:\zookeeper-3.4.13(变量值要根据zookeeper的放置位置)

在这里插入图片描述

  • 再在系统变量path最后添加:%ZOOKEEPER_HOME%\bin;%ZOOKEEPER_HOME%\conf; 并保存就可以了

在这里插入图片描述

3.验证是否安装成功

点击bin目录下的zkServer.cmd 这时候出现下面的提示就说明配置成功了。

在这里插入图片描述
注意 :这个窗口不要关闭!让注册中心服务一直运行。

在这里插入图片描述

4.项目dubbo配置

依赖引入

<!--dubbo--><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo</artifactId><version>2.7.7</version><exclusions><exclusion><groupId>io.netty</groupId><artifactId>netty-all</artifactId></exclusion></exclusions></dependency><dependency><groupId>io.netty</groupId><artifactId>netty-all</artifactId><version>4.1.50.Final</version></dependency><!--zookeeper--><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.14</version><exclusions><exclusion><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId></exclusion><exclusion><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></exclusion><exclusion><groupId>io.netty</groupId><artifactId>netty</artifactId></exclusion><exclusion><groupId>log4j</groupId><artifactId>log4j</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-recipes</artifactId><version>4.2.0</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.3.5.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId></dependency>

消费者和提供者的配置

在这里插入图片描述
在这里插入图片描述

消费者application.properties文件配置

# zookeeper
#配置dubbo端口号
dubbo.protocol.port=27280 
dubbo.config.location=classpath:dubbo-consumer.xml
dubbo.registry.address=127.0.0.1:2181
dubbo.application.name=consumer

dubbo-consumer.xml文件

<?xml version="1.0" encoding="UTF-8"?><beansxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xmlns="http://www.springframework.org/schema/beans"xsi:schemaLocation=" http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://code.alibabatech.com/schema/dubbo
                            http://code.alibabatech.com/schema/dubbo/dubbo.xsd"><dubbo:applicationname="${dubbo.application.name}"/><dubbo:registryprotocol="zookeeper"address="${dubbo.registry.address}"timeout="60000"/><dubbo:protocolname="dubbo"port="${dubbo.protocol.port}"/><!-- 用户接口 --><dubbo:referenceinterface="com.api.user.UserService"id="userService"timeout="50000"check="false"/></beans>

提供者application.properties文件配置

# zookeeper
dubbo.protocol.port=27281
dubbo.config.location=classpath:dubbo-provider.xml
dubbo.registry.address=127.0.0.1:2181
dubbo.application.name=provider

dubbo-provider.xml

<?xml version="1.0" encoding="UTF-8"?><beansxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xmlns="http://www.springframework.org/schema/beans"xsi:schemaLocation=" http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://code.alibabatech.com/schema/dubbo
                            http://code.alibabatech.com/schema/dubbo/dubbo.xsd"><dubbo:applicationname="${dubbo.application.name}"/><dubbo:registryprotocol="zookeeper"address="${dubbo.registry.address}"timeout="60000"/><dubbo:protocolname="dubbo"port="${dubbo.protocol.port}"/><!--商品接口(模块下实现)--><dubbo:serviceinterface="com.api.goods.GoodsService"ref="goodsService"timeout="50000"/><!--远程调用别的模块--><dubbo:referenceinterface="com.api.user.UserService"id="userService"timeout="50000"check="false"/></beans>

本文转载自: https://blog.csdn.net/m0_46300599/article/details/128077026
版权归原作者 满天都是银河系 所有, 如有侵权,请联系我们删除。

“windows安装Zookeeper”的评论:

还没有评论