zookeeper 部署

官网:

https://zookeeper.apache.org/

download

 

 

 

 

 

 

 

 

 

 

 

 

 下载完成后 赋值文件到centos  /opt/software

 

 

单机部署

解压到/opt/module

 tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz -C /opt/module

重命名文件包zookeeper3.7.1

 mv apache-zookeeper-3.7.1-bin/ zookeeper3.7.1

修改配置文件 zoo_sample.cfg (先创建zkData文件夹 mkdir zdData)

 

修改 zoo_sample.cfg 为 zoo.cfg

mv zoo_sample.cfg zoo.cfg

启动服务

 

bin/zkServer.sh start

注意:参数start前面没有 杠-

 

 

启动客户端

[root@192 bin]# ./zkCli.sh

 

集群部署

 

修改zookeeper的配置文件 zoo.cfg
增加配置:
server.MYID=HOSTNAME:PORT_BETWEEN_SERVER_CLIENT:PORT_REELECTION
MYID:zkData/myid的内容
HOSTNAME:/etc/hosts 中映射的主机名
PORT_BETWEEN_SERVER_CLIENT:Leader与Follower 之间通信的端口
PORT_REELECTION:重新选举的PORT

zoo.cfg增加如下配置

server.2=machine136:2888:3888
server.3=machine137:2888:3888
server.4=machine138:2888:3888

配置完成 一定关闭防火墙!一定关闭防火墙!一定关闭防火墙!

systemctl stop firewalld

 

 使用 curlator 包实现进程锁测试

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>zookeeper</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>19</maven.compiler.source>
        <maven.compiler.target>19</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.7.1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>


        <!-- curator -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>5.4.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.curator/curator-framework -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>5.4.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.curator/curator-test -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-test</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.curator/curator-client -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-client</artifactId>
            <version>5.4.0</version>
        </dependency>

    </dependencies>
</project>


 

 IDEA 参数传入设置方法

 

 

 

 

参考

视频资源:

分布式锁curator

https://www.bilibili.com/video/BV1to4y1C7gw?t=527.4&p=28

集群部署

https://www.bilibili.com/video/BV1to4y1C7gw?t=3.7&p=9

https://blog.csdn.net/weixin_44247784/article/details/125957936

(82条消息) 尚硅谷zookeeper入门笔记_尚硅谷zookeeper笔记_FF_y的博客-CSDN博客

 

posted on 2023-02-11 21:56  hztech  阅读(16)  评论(0编辑  收藏  举报

导航