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"?>
<beans xmlns: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:application name="${dubbo.application.name}"/>
    <dubbo:registry protocol="zookeeper" address="${dubbo.registry.address}" timeout="60000"/>
    <dubbo:protocol name="dubbo" port="${dubbo.protocol.port}"/>
    <!-- 用户接口 -->
    <dubbo:reference interface="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"?>
<beans xmlns: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:application name="${dubbo.application.name}"/>
    <dubbo:registry protocol="zookeeper" address="${dubbo.registry.address}" timeout="60000"/>
    <dubbo:protocol name="dubbo" port="${dubbo.protocol.port}"/>
    <!--商品接口(模块下实现)-->
    <dubbo:service interface="com.api.goods.GoodsService" ref="goodsService" timeout="50000"/>
	<!--远程调用别的模块-->
     <dubbo:reference interface="com.api.user.UserService" id="userService" timeout="50000" check="false"/>
</beans>
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值