linux中zookeeper的安装

本文介绍了在Linux系统中安装Zookeeper的步骤,包括检查JDK安装、上传并解压Zookeeper软件包、配置Zookeeper的data目录、修改zoo.cfg配置文件、启动和管理Zookeeper服务。同时强调了需要关闭Linux防火墙以确保服务正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

工具:zookeeper-3.4.5.tar.gz以及jdk-7u55
下载:https://download.youkuaiyun.com/download/ly_linyuan/10377506

1.java-version 首先查看是否已经安装过jdk,若未安装则先安装jdk
这里写图片描述
2.使用ftp工具或者sftp模式上传zookeeper-3.4.5.tar.gz文件

3.tar zxf zookeeper-3.4.6.tar.gz 解压zookeeper文件,进入zookeeper目录创建data文件:
cd zokeeper-3.4.6
mkdir data
这里写图片描述

4.进入conf目录,将目录zoo_sample.cfg改名zoo.cfg
cd conf
mv zoo_sample.cfg zoo.cfg

6.编辑zoo.cfg文件,将dataDri=/tmp/zookeeper 改为我们自己的当前目录/root/zookeeper-3.4.6/data
vim zoo.cfg
修改(dataDir=/root/zookeeper-3.4.6/data)
这里写图片描述

7.开启注册中心,
cd bin 进入bin目录
./zkServer.sh start 开启注册中心
./zkServer.sh status 查看状态
./zkServer.sh stop 关闭注册中心
注意要关闭linux的防火墙
这里写图片描述

实例:
1.在工程中引入jar包

<dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.netty</groupId>
                <artifactId>netty</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.zookeeper</groupId>
        <artifactId>zookeeper</artifactId>
    </dependency>
    <dependency>
        <groupId>com.github.sgroschupf</groupId>
        <artifactId>zkclient</artifactId>
    </dependency>

2.在spring的配置文件中添加dubbo的约束,然后使用dubbo:service发布服务。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
**xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"** xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
**http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd**
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

<context:component-scan base-package="com.ly.service"></context:component-scan>

<!-- 使用dubbo发布服务 -->
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="lymall-manager" />
<dubbo:registry protocol="zookeeper"
    address="192.168.64.129:2181" />
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.ly.service.GoodService" ref="goodServiceImpl" />

</beans>

3.引用服务,在springmvc的配置文件中添加服务的引用

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
    http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

<context:component-scan base-package="com.ly.controller" />
<mvc:annotation-driven />
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>

<!-- 引用dubbo服务 -->
<dubbo:application name="lymall-manager-web"/>
<dubbo:registry protocol="zookeeper" address="192.168.25.154:2181"/>    
<dubbo:reference interface="com.ly.service.GoodService" id="goodService" />

</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值