• Zookeeper搭建集群方法


    /path/to/zookeeper/conf/zoo1.cfg

    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/tmp/zk2/data
    dataLogDir=/tmp/zk2/log
    clientPort=2182
    server.1=localhost:2888:3888
    server.2=localhost:2899:3899
    server.3=localhost:2877:3877

    ip:master通信接口:master挂了选举接口


    echo 1 > /tmp/zk1/data/myid
    echo 2 > /tmp/zk2/data/myid
    echo 3 > /tmp/zk3/data/myid


    bin/zkServer.sh start conf/zoo1.cfg
    bin/zkServer.sh start conf/zoo2.cfg
    bin/zkServer.sh start conf/zoo3.cfg

    bin/zkServer.sh status conf/zoo3.cfg

    bin/zkServer.sh status conf/zoo3.cfg

    使用客户端进行连接

     bin/zkCli.sh -timeout 5000 -server localhost:2183

     三个机器如果挂了两个 程序就会失败了

    根据实际情况得出了结论

    netstat -apn|grep 端口 ,可以查看对应的进程号

     service 和systemctl区别

    3  查看系统运行时路径的log

    /root/soft/zookeeper/apache-zookeeper-3.5.5-bin/logs 日志路径
    zookeeper-root-server-VM_0_10_centos.out

    可以通过如下文字进行修改,只改两个配置文件即可

     https://www.cnblogs.com/mengHeJiuQIan/p/11169476.html

    4 zookeeper 集群搭建后链接整合springboot用的时 actuor

    实例代码

    import org.apache.curator.framework.CuratorFramework;
    import org.apache.curator.framework.CuratorFrameworkFactory;
    import org.apache.curator.retry.ExponentialBackoffRetry;
    import org.apache.zookeeper.CreateMode;
    import org.apache.zookeeper.ZooDefs;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;
    
    @Component
    public class ZkService {
    
        public void init(){
            CuratorFramework client = CuratorFrameworkFactory.builder().connectString("aaaa:2181,aaaa:2182,aaaa:2183")
                    .sessionTimeoutMs(10000).namespace("admin").retryPolicy(new ExponentialBackoffRetry(1000,5))
                     .build();
            client.start();
            try {
                if(client.checkExists().forPath("/savestore")==null){
                    client.create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT)
                            .withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE).forPath("/savestore");
                }
                System.out.println("已经成功初始化了");
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-framework</artifactId>
                <version>4.0.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>3.4.11</version>
            </dependency>
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-recipes</artifactId>
                <version>4.0.0</version>
            </dependency>
  • 相关阅读:
    使用Spring RestTemplate 发送 List<MultipartFile>,上传多个文件
    二分查找的非递归实现
    图的深度优先遍历和广度优先遍历
    快速排序学习
    szwl面试记录
    Mycat对Mysql进行分库分表
    Java使用队列解决约瑟夫问题
    pa_hzzx面试总结
    Linux pam 后门纪录root用户密码以及自己设置root密码登录root
    JSP线程安全
  • 原文地址:https://www.cnblogs.com/genestart/p/11217415.html
Copyright © 2020-2023  润新知