【知识库】--Use Zookeeper Cluster Server with Java(150)
来源:互联网 发布:那个房产软件好 编辑:程序博客网 时间:2024/05/16 12:55
单机模拟集群
#定义配置文件如下 :三个端口 clientPort=2182 clientPort=2183 clientPort=2184 三个数据目录 dataDir=/home/zoo/z2/data dataDir=/home/zoo/z3/data dataDir=/home/zoo/z4/data# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial# synchronization phase can takeinitLimit=10# The number of ticks that can pass between# sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just# example sakes.dataDir=/home/zoo/z2/data# the port at which the clients will connectclientPort=2182# 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=1server.2=127.0.0.1:3333:3334server.3=127.0.0.1:4444:4445server.4=127.0.0.1:5555:5556
启动命令
zookeeper-3.4.9/bin/zkServer.sh start z2/z2.cfg zookeeper-3.4.9/bin/zkServer.sh start z3/z3.cfg zookeeper-3.4.9/bin/zkServer.sh start z4/z4.cfg
Java交互
public class Master implements Watcher { ZooKeeper zk; String hostPort; public Master(String hostPort) { this.hostPort = hostPort; } void startZK() throws Exception { zk = new ZooKeeper(hostPort, 15000, this); } void stopZK() throws Exception { zk.close(); } public List<String> getChildrenByPath(String path) throws KeeperException, InterruptedException { return zk.getChildren(path, true); } public String addPath(String path, byte[] content) throws KeeperException, InterruptedException { return zk.create(path, content, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } public String getDataByPath(String path) throws KeeperException, InterruptedException { return new String(zk.getData(path, true, new Stat())); } @Override public void process(WatchedEvent event) { System.out.println(event); } public static void main(String[] args) throws Exception { Master m = new Master("10.86.41.28:2182,10.86.41.28:2183,10.86.41.28:2184"); m.startZK(); //创建节点 // String s = m.addPath("/RR", "zww".getBytes()); // System.out.println("++++++++++" + s); Thread.sleep(600); //获取children节点集合 List<String> root2 = m.getChildrenByPath("/RR");//监听 System.out.println("========2----" + JSON.toJSONString(root2)); //获取节点下的数据 System.out.println("========3----" + m.getDataByPath("/RR")); Thread.sleep(600000);//wait for a bit m.stopZK(); }}
0 0
- 【知识库】--Use Zookeeper Cluster Server with Java(150)
- 【知识库 】--Coordinating Actors In Java Use Akka(150)
- Directory Server 6 HA with Sun Cluster
- 知识库--ZooKeeper + Sessions(59)
- Java知识库
- java知识库
- wps cluster with ihs installation - SQL Server 2005
- SQL Server cluster failover fails with Error Code: 0x80071398
- 知识库--ZooKeeper Basics(59)
- 知识库--ZooKeeper + Versions(59)
- 知识库--ZooKeeper+Architecture(59)
- 知识库--Server + Service(61)
- how to use Wordnet with Java?
- Use IBM Cloudscape with WebSphere Application Server Community Edition
- how to use ffmpeg with media wowza server (mpeg-ts)
- 知识库--Zookeeper API Overview(59)
- 知识库--Zookeeper different modes for znodes(59)
- 知识库--ZooKeeper + Watches and Notifications(59)
- POJ 3273 Monthly Expense
- Android 子线程发送handle更新UI遇到This message is already in use解决方法
- ubuntu下的tftp上传和下载操作方法
- java菜鸟的回炉之旅之一心态篇
- windows下 MySQL 服务查找不到的解决方法
- 【知识库】--Use Zookeeper Cluster Server with Java(150)
- A控制器presente到B,B再present到C,C再present到D,D回到到A的方法
- POJ 3518 Prime Gap
- 【MIT 公开课】Computer Science and Programing Lession 8
- WIN8 搭建FTP服务器
- Npoi操作Excel
- vim快速删除或复制字符串
- 阿里云centos 7安装mysql出现conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64错误
- MyBatis资料整理