文档章节

JAVA 连接 ZooKeeper之初体验

o
 osc_tauwfamo
发布于 2018/07/17 14:09
字数 3962
阅读 7
收藏 0

「深度学习福利」大神带你进阶工程师,立即查看>>>

Java连接Zookeeper

一、配置zk环境

  • 本人使用的是虚拟机,创建了两台linux服务器(安装过程百度上很多)

  • 准备zk的安装包,zookeeper-3.4.10.tar.gz,可在Apache官网下载,这里我提供了一个百度云的https://pan.baidu.com/s/15icVROSKpgwUzqzpHW6Rbg 密码dgnp

  • 安装过程

    • 环境准备:安装JDK,配置Hosts,配置Hostname、关闭防火墙

    • $ZOOKEEPER = /home/zookeeper_application/zookeeper-3.4.10

    • tar -xvzf zookeeper-3.4.10.tar.gz目录为/home/zookeeper_application/zookeeper-3.4.10

    • cd 到zookeeper-3.4.10,mkdir data 创建data文件夹,cd 到data,touch myid 创建myid文件,vi myid myid存server的id,可以是1,2,3…,必须唯一

    • 创建$ZOOKEEPER/conf/zoo.cfg 修改zoo.cfg,增加如下:

    • dataDir=/home/zookeeper_application/zookeeper-3.4.10/data

      clientPort=2181

      initLimit=10

      syncLimit=5

      tickTime=2000

      server.1=master:2888:3888

      server.2=slave1:2888:3888

    • 其中server.X代表组成整个服务的机器,当服务启动时,会在数据目录下查找这个文件myid,这个文件中存有服务器的号码。

  • 配置/etc/profile:

    • export ZOOKEEPER_HOME=/home/zookeeper_application/zookeeper-3.4.10
    • export PATH=$PATH:/usr/local/jdk1.7/bin:$ZOOKEEPER_HOME/bin
  • 同样配置另外一台服务器,myid为2

  • 启动/状态/停止 在bin目录下 zkServer.sh start|status|stop

java部分

  • 创建zk.properties

    zk.server=192.168.2.111:2181

    zk.authentication_type=digest

    zk.correct_authentication=rightKey

    zk.bad_authentication=worngKey

  • ZkConfig.java


package org.seckill.zk.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
	
/**
 * @author mxn
 * @create 2018-07-16 17:22
 */
public class ZkConfig {

public static final Logger logger = LoggerFactory.getLogger(ZkConfig.class);

public static final String FILE_NAME = "zk.properties";

private String server;
private String authenticationType;
private String correctAuthentication;
private String badAuthentication;

/**
 * 配置文件中的常量.
 */
public static final String zk_server = "zk.server";
public static final String zk_authentication_type = "zk.authentication_type";
public static final String zk_correct_authentication = "zk.correct_authentication";
public static final String zk_bad_authentication = "zk.bad_authentication";

 /**
 * 操作对象.
 */
private static ZkConfig config = new ZkConfig();

private ZkConfig() {
    super();
}

private Properties properties;

/**
 * 获取config对象.
 *
 * @return
 */
public static ZkConfig getConfig() {
    return config;
}

public static void main(String[] args) {
    System.out.println(1);
}


static {
    config.loadPropertiesFromSrc();
}

public void loadPropertiesFromSrc() {
    InputStream in = null;

    try {
        in = ZkConfig.class.getClassLoader().getResourceAsStream(FILE_NAME);
        if (null != in) {
            properties = new Properties();
            try {
                properties.load(in);
                loadProperties(properties);
            } catch (IOException e) {
                throw e;
            }
        } else {
            logger.error(FILE_NAME + "属性文件未能在classpath指定的目录下 " + ZkConfig.class.getClassLoader().getResource("").getPath() + " 找到!");
        }
    } catch (Exception e) {
        logger.error("ZkConfig.getZkConfig error:", e);
    } finally {
        if (null != in) {
            try {
                in.close();
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
}


/**
 * 根据传入的 {@link # load(Properties)}对象设置配置参数
 *
 * @param pro
 */
public void loadProperties(Properties pro) {
    logger.info("开始从属性文件中加载配置项");
    String value = null;

    value = pro.getProperty(zk_server);
    if (!ZkUtil.isEmpty(value)) {
        this.server = value.trim();
        logger.info("配置项:服务器ip==>" + zk_server + "==>" + value + " 已加载");
    }
    value = pro.getProperty(zk_authentication_type);
    if (!ZkUtil.isEmpty(value)) {
        this.authenticationType = value.trim();
        logger.info("配置项:验证类型==>" + zk_authentication_type + " 已加载");
    }
    value = pro.getProperty(zk_correct_authentication);
    if (!ZkUtil.isEmpty(value)) {
        this.correctAuthentication = value.trim();
        logger.info("配置项:正确的密码==>" + zk_correct_authentication + " 已加载");
    }
    value = pro.getProperty(zk_bad_authentication);
    if (!ZkUtil.isEmpty(value)) {
        this.badAuthentication = value.trim();
        logger.info("配置项:错误的密码==>" + zk_bad_authentication + " 已加载");
    }
}


public static Logger getLogger() {
    return logger;
}

public static String getFileName() {
    return FILE_NAME;
}

public String getServer() {
    return server;
}

public void setServer(String server) {
    this.server = server;
}

public String getAuthenticationType() {
    return authenticationType;
}

public void setAuthenticationType(String authenticationType) {
    this.authenticationType = authenticationType;
}

public String getCorrectAuthentication() {
    return correctAuthentication;
}

public void setCorrectAuthentication(String correctAuthentication) {
    this.correctAuthentication = correctAuthentication;
}

public String getBadAuthentication() {
    return badAuthentication;
}

public void setBadAuthentication(String badAuthentication) {
    this.badAuthentication = badAuthentication;
}

public static String getZk_server() {
    return zk_server;
}

public static String getZk_authentication_type() {
    return zk_authentication_type;
}

public static String getZk_correct_authentication() {
    return zk_correct_authentication;
}

public static String getZk_bad_authentication() {
    return zk_bad_authentication;
}

public static void setConfig(ZkConfig config) {
    ZkConfig.config = config;
}
}

  • ZkUtil.java 一个工具类

      package org.seckill.zk.util;
    
      /**
       * @author 12084
       * @create 2018-07-17 9:09
       */
    
      public class ZkUtil {
          /**
           * 判断字符串是否为NULL或空
           *
           * @param s
           *            待判断的字符串数据
           * @return 判断结果 true-是 false-否
           */
          public static boolean isEmpty(String s) {
              return null == s || "".equals(s.trim());
          }
    
      }
    

  • ZkAuth.java package org.seckill.zk;

      	import org.apache.zookeeper.*;
      	import org.apache.zookeeper.data.Stat;
      	import org.seckill.zk.util.ZkConfig;
      	import org.slf4j.Logger;
      	import org.slf4j.LoggerFactory;
    
      	import java.util.concurrent.atomic.AtomicInteger;
    
      	/**
      	 * @author 12084
      	 * @create 2018-07-16 15:59
      	 */
    
      	public class ZkAuth implements Watcher {
    
          public static final Logger logger = LoggerFactory.getLogger(ZkAuth.class);
    
    
          final static String PATH = "/auth_test";
    
          final static String PATH_DEL = "/auth_test/del_node";
    
          static ZooKeeper zk = null;
    
          AtomicInteger seq = new AtomicInteger();
    
    
          public void process(WatchedEvent event) {
              try {
                  Thread.sleep(200);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              if (event == null) {
                  return;
              }
              //连接状态
              Event.KeeperState keeperState = event.getState();
              //事件类型
              Event.EventType eventType = event.getType();
    
              String logPrefix = "【Watcher-" + seq.incrementAndGet() + "】";
    
              logger.info(logPrefix + "收到Watcher通知");
              logger.info(logPrefix + "连接状态:\t" + keeperState.toString());
              logger.info(logPrefix + "事件类型:\t" + eventType.toString());
    
              if (Event.KeeperState.SyncConnected == keeperState) {
                  //成功连接上ZK服务器
                  if (Event.EventType.None == eventType) {
                      logger.info(logPrefix + "成功连接上ZK服务器");
                  }
              } else if (Event.KeeperState.Disconnected == keeperState) {
                  logger.info(logPrefix + "与ZK服务器断开连接");
              } else if (Event.KeeperState.AuthFailed == keeperState) {
                  logger.info(logPrefix + "权限检查失败");
              } else if (Event.KeeperState.Expired == keeperState) {
                  logger.info(logPrefix + "会话失效");
              }
              logger.info("--------------------------------------------");
          }
    
          /**
           * 创建ZK连接
           *
           * @param connectString  ZK服务器地址列表
           * @param sessionTimeout Session超时时间
           */
          public void createConnection(String connectString, int sessionTimeout) {
              releaseConnection();
    
              try {
                  zk = new ZooKeeper(connectString, sessionTimeout, this);
                  //授权
                  zk.addAuthInfo(ZkConfig.getConfig().getAuthenticationType(), ZkConfig.getConfig().getCorrectAuthentication().getBytes());
    
    
                  logger.info("开始连接ZK服务器....");
                  while (zk.getState() != ZooKeeper.States.CONNECTED) {
                      Thread.sleep(3000);
                  }
    
    
              } catch (Exception e) {
                  e.printStackTrace();
              }
    
          }
    
          /**
           * 关闭ZK连接
           */
          public void releaseConnection() {
              if (zk != null) {
                  try {
                      zk.close();
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
    
    
          /**
           * 获取数据:不采用密码
           */
          static void getDataByNoAuthentication() {
              String prefix = "[不使用任何授权信息]";
              logger.info(prefix + "获取数据:" + PATH);
              try {
                  ZooKeeper noZk = new ZooKeeper(ZkConfig.getConfig().getServer(), 2000, null);
                  Thread.sleep(4000);
                  logger.info(prefix + "成功获取数据:" + noZk.getData(PATH, false, null));
              } catch (Exception e) {
                  logger.error(prefix + "获取数据失败,原因:" + e.getMessage());
              }
          }
    
          /**
           * 获取数据:采用错误的密码
           */
          static void getDataByBadAuthentication() {
              String prefix = "[使用错误的授权信息]";
    
              try {
                  ZooKeeper badzk = new ZooKeeper(ZkConfig.getConfig().getServer(), 2000, null);
                  //授权
                  Thread.sleep(4000);
                  badzk.addAuthInfo(ZkConfig.getConfig().getAuthenticationType(), ZkConfig.getConfig().getBadAuthentication().getBytes());
                  logger.info(prefix + "获取数据:" + PATH);
                  logger.info(prefix + "成功获取数据:" + badzk.getData(PATH, false, null));
              } catch (Exception e) {
                  logger.error(prefix + "获取数据失败,原因:" + e.getMessage());
              }
          }
    
          /**
           * 采用正确的密码
           */
          static void getDataByCorrectAuthentication() {
              String prefix = "[使用正确的授权信息]";
              try {
                  logger.info(prefix + "获取数据:" + PATH);
                  logger.warn(prefix + "成功获取数据:" + new String(zk.getData(PATH, false, null)));
              } catch (Exception e) {
                  logger.error(prefix + "获取数据失败,原因:" + e.getMessage());
              }
          }
    
    
          /**
           * 更新数据:不采用密码
           */
          static void updateDataByNoAuthentication() {
              String prefix = "[不使用任何授权信息]";
              logger.info(prefix + "更新数据:" + PATH);
              try {
                  ZooKeeper nozk = new ZooKeeper(ZkConfig.getConfig().getServer(), 2000, null);
                  Thread.sleep(4000);
                  Stat stat = nozk.exists(PATH, false);
                  if (stat != null) {
                      nozk.setData(PATH, prefix.getBytes(), -1);
                      logger.info(prefix + "更新成功");
                  }
              } catch (Exception e) {
                  logger.error(prefix + "更新失败,原因是:" + e.getMessage());
              }
          }
    
          /**
           * 更新数据:采用错误的密码
           */
          static void updateDataByBadAuthentication() {
              String prefix = "[使用错误的授权信息]";
              logger.info(prefix + "更新数据:" + PATH);
              try {
                  ZooKeeper badzk = new ZooKeeper(ZkConfig.getConfig().getServer(), 2000, null);
                  //授权
                  badzk.addAuthInfo(ZkConfig.getConfig().getAuthenticationType(), ZkConfig.getConfig().getCorrectAuthentication().getBytes());
    
                  Stat exists = badzk.exists(PATH, false);
                  if (exists != null) {
                      badzk.setData(PATH, prefix.getBytes(), -1);
                      logger.info(prefix + "更新成功");
                  }
              } catch (Exception e) {
                  logger.error(prefix + "更新失败,原因是:" + e.getMessage());
              }
    
          }
    
          /**
           * 更新数据:采用正确的密码
           */
          static void updateDataByCorrectAuthentication() {
              String prefix = "[使用正确的授权信息]";
    
              logger.info(prefix + "更新数据:" + PATH);
              try {
                  Stat stat = zk.exists(PATH, false);
                  if (stat != null) {
                      zk.setData(PATH, prefix.getBytes(), -1);
                      logger.info(prefix + "更新成功");
                  }
              } catch (Exception e) {
                  logger.error(prefix + "更新失败,原因是:" + e.getMessage());
              }
          }
    
          static void deleteParent() throws Exception {
              Stat stat = zk.exists(PATH_DEL, false);
              if (stat != null) {
                  zk.delete(PATH_DEL, -1);
                  zk.delete(PATH, -1);
                  return;
              }
              Stat stat2 = zk.exists(PATH, false);
              if (stat2 != null) {
                  zk.delete(PATH, -1);
              }
          }
    
    
          public static void main(String[] args) {
    
              ZkAuth zkAuth = null;
              try {
                  zkAuth = new ZkAuth();
                  zkAuth.createConnection(ZkConfig.getConfig().getServer(), 5000);
    
                  deleteParent();
    
                  zk.create(PATH, "init content".getBytes(), ZooDefs.Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
    
      			//            zk.create(PATH_DEL, "will be deleted!".getBytes(), ZooDefs.Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
    
                  logger.info("客户端开始访问-----------------------------------------------");
                  //获取数据
                  getDataByNoAuthentication();
                  getDataByBadAuthentication();
                  getDataByCorrectAuthentication();
    
    
    
              } catch (Exception e) {
                  e.printStackTrace();
              } finally {
                  //释放连接
                  zkAuth.releaseConnection();
              }
          }
      }
    

  • 运行结果
  • 启动两台linux服务器
    • 启动zk

      • 另外一台服务器同样操作
    • 运行java代码

    • 运行日志:

    • Connected to the target VM, address: '127.0.0.1:52280', transport: 'socket' SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/Maven/repo/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/Maven/repo/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. 13:56:20,355 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy] 13:56:20,356 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml] 13:56:20,370 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/D:/workspace/maven/seckill/target/classes/logback.xml] 13:56:20,527 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 13:56:20,531 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT] 13:56:20,559 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 13:56:20,617 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG 13:56:20,617 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT] 13:56:20,618 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder] 13:56:20,620 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@17c386de - Registering current configuration as safe fallback point 13:56:20.626 [main] INFO org.seckill.zk.util.ZkConfig - 开始从属性文件中加载配置项 13:56:20.634 [main] INFO org.seckill.zk.util.ZkConfig - 配置项:服务器ip==>zk.server==>192.168.2.111:2181 已加载 13:56:20.634 [main] INFO org.seckill.zk.util.ZkConfig - 配置项:验证类型==>zk.authentication_type 已加载 13:56:20.634 [main] INFO org.seckill.zk.util.ZkConfig - 配置项:正确的密码==>zk.correct_authentication 已加载 13:56:20.634 [main] INFO org.seckill.zk.util.ZkConfig - 配置项:错误的密码==>zk.bad_authentication 已加载 13:56:20.645 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT 13:56:20.645 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:host.name=windows10.microdone.cn 13:56:20.645 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:java.version=1.8.0_11 13:56:20.646 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:java.vendor=Oracle Corporation 13:56:20.646 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:java.home=C:\Program Files\Java\jdk1.8.0_11\jre ar;D:\Maven\repo\org\slf4j\slf4j-api\1.7.12\slf4j-api-1.7.12.jar;D:\Maven\repo\ch\qos\logback\logback-core\1.1.1\logback-core-1.1.1.jar;D:\Maven\repo\ch\qos\logback\logback-classic\1.1.1\logback-classic-1.1.1.jar;D:\Maven\repo\mysql\mysql-connector-java\5.1.35\mysql-connector-java-5.1.35.jar;D:\Maven\repo\c3p0\c3p0\0.9.1.2\c3p0-0.9.1.2.jar;D:\Maven\repo\org\mybatis\mybatis\3.3.0\mybatis-3.3.0.jar;D:\Maven\repo\org\mybatis\mybatis-spring\1.2.3\mybatis-spring-1.2.3.jar;D:\Maven\repo\taglibs\standard\1.1.2\standard-1.1.2.jar;D:\Maven\repo\jstl\jstl\1.2\jstl-1.2.jar;D:\Maven\repo\com\fasterxml\jackson\core\jackson-databind\2.5.4\jackson-databind-2.5.4.jar;D:\Maven\repo\com\fasterxml\jackson\core\jackson-annotations\2.5.0\jackson-annotations-2.5.0.jar;D:\Maven\repo\com\fasterxml\jackson\core\jackson-core\2.5.4\jackson-core-2.5.4.jar;D:\Maven\repo\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;D:\Maven\repo\org\springframework\spring-core\4.1.7.RELEASE\spring-core-4.1.7.RELEASE.jar;D:\Maven\repo\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\Maven\repo\org\springframework\spring-beans\4.1.7.RELEASE\spring-beans-4.1.7.RELEASE.jar;D:\Maven\repo\org\springframework\spring-context\4.1.7.RELEASE\spring-context-4.1.7.RELEASE.jar;D:\Maven\repo\org\springframework\spring-aop\4.1.7.RELEASE\spring-aop-4.1.7.RELEASE.jar;D:\Maven\repo\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\Maven\repo\org\springframework\spring-expression\4.1.7.RELEASE\spring-expression-4.1.7.RELEASE.jar;D:\Maven\repo\org\springframework\spring-jdbc\4.1.7.RELEASE\spring-jdbc-4.1.7.RELEASE.jar;D:\Maven\repo\org\springframework\spring-tx\4.1.7.RELEASE\spring-tx-4.1.7.RELEASE.jar;D:\Maven\repo\org\springframework\spring-web\4.1.7.RELEASE\spring-web-4.1.7.RELEASE.jar;D:\Maven\repo\org\springframework\spring-webmvc\4.1.7.RELEASE\spring-webmvc-4.1.7.RELEASE.jar;D:\Maven\repo\org\springframework\spring-test\4.1.7.RELEASE\spring-test-4.1.7.RELEASE.jar;D:\Maven\repo\redis\clients\jedis\2.7.3\jedis-2.7.3.jar;D:\Maven\repo\org\apache\commons\commons-pool2\2.3\commons-pool2-2.3.jar;D:\Maven\repo\com\dyuproject\protostuff\protostuff-core\1.0.8\protostuff-core-1.0.8.jar;D:\Maven\repo\com\dyuproject\protostuff\protostuff-api\1.0.8\protostuff-api-1.0.8.jar;D:\Maven\repo\com\dyuproject\protostuff\protostuff-runtime\1.0.8\protostuff-runtime-1.0.8.jar;D:\Maven\repo\com\dyuproject\protostuff\protostuff-collectionschema\1.0.8\protostuff-collectionschema-1.0.8.jar;D:\Maven\repo\commons-collections\commons-collections\3.2\commons-collections-3.2.jar;D:\Maven\repo\org\apache\zookeeper\zookeeper\3.4.6\zookeeper-3.4.6.jar;D:\Maven\repo\org\slf4j\slf4j-log4j12\1.6.1\slf4j-log4j12-1.6.1.jar;D:\Maven\repo\log4j\log4j\1.2.16\log4j-1.2.16.jar;D:\Maven\repo\io\netty\netty\3.7.0.Final\netty-3.7.0.Final.jar;D:\Maven\repo\jline\jline\0.9.94\jline-0.9.94.jar;D:\install\Idea\IntelliJ IDEA 2018.1.1\lib\idea_rt.jar;C:\Users\12084\AppData\Local\Temp\capture1jars\debugger-agent.jar 13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:java.library.path=C:\Program Files\Java\jdk1.8.0_11\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\TortoiseSVN\bin;C:\Program Files\SlikSvn\bin;D:\Maven\apache-maven-3.3.9\bin;D:\install\MySQL\MySQL Server 5.1\bin;C:\Program Files\Java\jdk1.8.0_11\bin;D:\Git\Git\cmd;C:\WINDOWS\System32\OpenSSH;C:\Users\12084\AppData\Local\Microsoft\WindowsApps;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;;. 13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:java.io.tmpdir=C:\Users\12084\AppData\Local\Temp
      13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:java.compiler=<NA> 13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:os.name=Windows 8.1 13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:os.arch=amd64 13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:os.version=6.3 13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:user.name=12084 13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:user.home=C:\Users\12084 13:56:20.648 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:user.dir=D:\workspace\maven\seckill 13:56:20.649 [main] INFO org.apache.zookeeper.ZooKeeper - Initiating client connection, connectString=192.168.2.111:2181 sessionTimeout=5000 watcher=org.seckill.zk.ZkAuth@65d6b83b 13:56:20.653 [main] DEBUG org.apache.zookeeper.ClientCnxn - zookeeper.disableAutoWatchReset is false 13:56:20.680 [main] INFO org.seckill.zk.ZkAuth - 开始连接ZK服务器.... 13:56:20.687 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server 192.168.2.111/192.168.2.111:2181. Will not attempt to authenticate using SASL (unknown error) 13:56:20.688 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to 192.168.2.111/192.168.2.111:2181, initiating session 13:56:20.689 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Session establishment request sent on 192.168.2.111/192.168.2.111:2181 13:56:20.701 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Session establishment complete on server 192.168.2.111/192.168.2.111:2181, sessionid = 0x164a88267680000, negotiated timeout = 5000 13:56:20.732 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got auth sessionid:0x164a88267680000 13:56:20.732 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got auth sessionid:0x164a88267680000 13:56:20.910 [main-EventThread] INFO org.seckill.zk.ZkAuth - 【Watcher-1】收到Watcher通知 13:56:20.911 [main-EventThread] INFO org.seckill.zk.ZkAuth - 【Watcher-1】连接状态: SyncConnected 13:56:20.911 [main-EventThread] INFO org.seckill.zk.ZkAuth - 【Watcher-1】事件类型: None 13:56:20.911 [main-EventThread] INFO org.seckill.zk.ZkAuth - 【Watcher-1】成功连接上ZK服务器 13:56:20.911 [main-EventThread] INFO org.seckill.zk.ZkAuth - -------------------------------------------- 13:56:22.372 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680000 after 0ms 13:56:23.690 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply sessionid:0x164a88267680000, packet:: clientPath:null serverPath:null finished:false header:: 1,3 replyHeader:: 1,12884901891,-101 request:: '/auth_test/del_node,F response::
      13:56:23.690 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680000 after 7ms 13:56:23.693 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply sessionid:0x164a88267680000, packet:: clientPath:null serverPath:null finished:false header:: 2,3 replyHeader:: 2,12884901891,0 request:: '/auth_test,F response:: s{8589934652,8589934652,1531821556532,1531821556532,0,0,0,0,12,0,8589934652} 13:56:23.701 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply sessionid:0x164a88267680000, packet:: clientPath:null serverPath:null finished:false header:: 3,2 replyHeader:: 3,12884901892,0 request:: '/auth_test,-1 response:: null 13:56:23.714 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply sessionid:0x164a88267680000, packet:: clientPath:null serverPath:null finished:false header:: 4,1 replyHeader:: 4,12884901893,0 request:: '/auth_test,#696e697420636f6e74656e74,v{s{31,s{'auth,'}}},0 response:: '/auth_test 13:56:23.714 [main] INFO org.seckill.zk.ZkAuth - 客户端开始访问----------------------------------------------- 13:56:23.715 [main] INFO org.seckill.zk.ZkAuth - [不使用任何授权信息]获取数据:/auth_test 13:56:23.715 [main] INFO org.apache.zookeeper.ZooKeeper - Initiating client connection, connectString=192.168.2.111:2181 sessionTimeout=2000 watcher=null 13:56:23.716 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server 192.168.2.111/192.168.2.111:2181. Will not attempt to authenticate using SASL (unknown error) 13:56:23.717 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to 192.168.2.111/192.168.2.111:2181, initiating session 13:56:23.717 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Session establishment request sent on 192.168.2.111/192.168.2.111:2181 13:56:23.721 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Session establishment complete on server 192.168.2.111/192.168.2.111:2181, sessionid = 0x164a88267680001, negotiated timeout = 4000 13:56:23.730 [main-EventThread] ERROR org.apache.zookeeper.ClientCnxn - Error while calling watcher java.lang.NullPointerException: null at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:522) [zookeeper-3.4.6.jar:3.4.6-1569965] at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:498) [zookeeper-3.4.6.jar:3.4.6-1569965] 13:56:25.051 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680001 after 0ms 13:56:25.372 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680000 after 0ms 13:56:26.385 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680001 after 1ms 13:56:27.040 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680000 after 0ms 13:56:27.718 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680001 after 1ms 13:56:27.723 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply sessionid:0x164a88267680001, packet:: clientPath:null serverPath:null finished:false header:: 1,4 replyHeader:: 1,12884901894,-102 request:: '/auth_test,F response::
      13:56:27.734 [main] ERROR org.seckill.zk.ZkAuth - [不使用任何授权信息]获取数据失败,原因:KeeperErrorCode = NoAuth for /auth_test 13:56:27.735 [main] INFO org.apache.zookeeper.ZooKeeper - Initiating client connection, connectString=192.168.2.111:2181 sessionTimeout=2000 watcher=null 13:56:27.736 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server 192.168.2.111/192.168.2.111:2181. Will not attempt to authenticate using SASL (unknown error) 13:56:27.737 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to 192.168.2.111/192.168.2.111:2181, initiating session 13:56:27.737 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Session establishment request sent on 192.168.2.111/192.168.2.111:2181 13:56:27.753 [main-SendThread(192.168.2.111:2181)] INFO org.apache.zookeeper.ClientCnxn - Session establishment complete on server 192.168.2.111/192.168.2.111:2181, sessionid = 0x164a88267680002, negotiated timeout = 4000 13:56:27.754 [main-EventThread] ERROR org.apache.zookeeper.ClientCnxn - Error while calling watcher java.lang.NullPointerException: null at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:522) [zookeeper-3.4.6.jar:3.4.6-1569965] at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:498) [zookeeper-3.4.6.jar:3.4.6-1569965] 13:56:28.708 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680000 after 0ms 13:56:29.052 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680001 after 0ms 13:56:29.071 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680002 after 1ms 13:56:30.375 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680000 after 0ms 13:56:30.385 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680001 after 0ms 13:56:30.403 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680002 after 0ms 13:56:31.719 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680001 after 0ms 13:56:31.736 [main] INFO org.seckill.zk.ZkAuth - [使用错误的授权信息]获取数据:/auth_test 13:56:31.737 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got auth sessionid:0x164a88267680002 13:56:31.737 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680002 after 1ms 13:56:31.738 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply sessionid:0x164a88267680002, packet:: clientPath:null serverPath:null finished:false header:: 1,4 replyHeader:: 1,12884901895,-102 request:: '/auth_test,F response::
      13:56:31.738 [main] ERROR org.seckill.zk.ZkAuth - [使用错误的授权信息]获取数据失败,原因:KeeperErrorCode = NoAuth for /auth_test 13:56:31.738 [main] INFO org.seckill.zk.ZkAuth - [使用正确的授权信息]获取数据:/auth_test 13:56:31.754 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply sessionid:0x164a88267680000, packet:: clientPath:null serverPath:null finished:false header:: 5,4 replyHeader:: 5,12884901895,0 request:: '/auth_test,F response:: #696e697420636f6e74656e74,s{12884901893,12884901893,1531835724052,1531835724052,0,0,0,0,12,0,12884901893} 13:56:31.754 [main] WARN org.seckill.zk.ZkAuth - [使用正确的授权信息]成功获取数据:init content 13:56:31.754 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x164a88267680000 after 15ms 13:56:31.754 [main] DEBUG org.apache.zookeeper.ZooKeeper - Closing session: 0x164a88267680000 13:56:31.755 [main] DEBUG org.apache.zookeeper.ClientCnxn - Closing client for session: 0x164a88267680000 Disconnected from the target VM, address: '127.0.0.1:52280', transport: 'socket' 13:56:31.835 [main-SendThread(192.168.2.111:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply sessionid:0x164a88267680000, packet:: clientPath:null serverPath:null finished:false header:: 6,-11 replyHeader:: 6,12884901896,0 request:: null response:: null 13:56:31.836 [main] DEBUG org.apache.zookeeper.ClientCnxn - Disconnecting client for session: 0x164a88267680000 13:56:31.836 [main] INFO org.apache.zookeeper.ZooKeeper - Session: 0x164a88267680000 closed 13:56:31.836 [main-EventThread] INFO org.apache.zookeeper.ClientCnxn - EventThread shut down

      Process finished with exit code 0


  • 详情 13:56:20.626 [main] INFO org.seckill.zk.util.ZkConfig - 开始从属性文件中加载配置项

13:56:20.634 [main] INFO org.seckill.zk.util.ZkConfig - 配置项:服务器ip==>zk.server==>192.168.2.111:2181 已加载

13:56:20.634 [main] INFO org.seckill.zk.util.ZkConfig - 配置项:验证类型==>zk.authentication_type 已加载

13:56:20.634 [main] INFO org.seckill.zk.util.ZkConfig - 配置项:正确的密码==>zk.correct_authentication 已加载

13:56:20.634 [main] INFO org.seckill.zk.util.ZkConfig - 配置项:错误的密码==>zk.bad_authentication 已加载

13:56:20.680 [main] INFO org.seckill.zk.ZkAuth - 开始连接ZK服务器....

13:56:20.910 [main-EventThread] INFO org.seckill.zk.ZkAuth - 【Watcher-1】收到Watcher通知

13:56:20.911 [main-EventThread] INFO org.seckill.zk.ZkAuth - 【Watcher-1】连接状态: SyncConnected

13:56:20.911 [main-EventThread] INFO org.seckill.zk.ZkAuth - 【Watcher-1】事件类型: None

13:56:20.911 [main-EventThread] INFO org.seckill.zk.ZkAuth - 【Watcher-1】成功连接上ZK服务器

13:56:23.714 [main] INFO org.seckill.zk.ZkAuth - 客户端开始访问-----------------------------------------------

13:56:23.715 [main] INFO org.seckill.zk.ZkAuth - [不使用任何授权信息]获取数据:/auth_test

13:56:27.734 [main] ERROR org.seckill.zk.ZkAuth - [不使用任何授权信息]获取数据失败,原因:KeeperErrorCode = NoAuth for /auth_test

13:56:31.738 [main] ERROR org.seckill.zk.ZkAuth - [使用错误的授权信息]获取数据失败,原因:KeeperErrorCode = NoAuth for /auth_test

13:56:31.754 [main] WARN org.seckill.zk.ZkAuth - [使用正确的授权信息]成功获取数据:init content

o
粉丝 0
博文 500
码字总数 0
作品 0
私信 提问
加载中
请先登录后再评论。
Netty那点事(三)Channel与Pipeline

Channel是理解和使用Netty的核心。Channel的涉及内容较多,这里我使用由浅入深的介绍方法。在这篇文章中,我们主要介绍Channel部分中Pipeline实现机制。为了避免枯燥,借用一下《盗梦空间》的...

黄亿华
2013/11/24
2W
22
我的架构演化笔记 功能1: 基本的用户注册

“咚咚”,一阵急促的敲门声, 我从睡梦中惊醒,我靠,这才几点,谁这么早, 开门一看,原来我的小表弟放暑假了,来南京玩,顺便说跟我后面学习一个网站是怎么做出来的。 于是有了下面的一段...

强子哥哥
2014/05/31
976
3
Nutch学习笔记4-Nutch 1.7 的 索引篇 ElasticSearch

上一篇讲解了爬取和分析的流程,很重要的收获就是: 解析过程中,会根据页面的ContentType获得一系列的注册解析器, 依次调用每个解析器,当其中一个解析成功后就返回,否则继续执行下一个解...

强子哥哥
2014/06/26
712
0
5分钟 maven3 快速入门指南

前提条件 你首先需要了解如何在电脑上安装软件。如果你不知道如何做到这一点,请询问你办公室,学校里的人,或花钱找人来解释这个给你。 不建议给Maven的服务邮箱来发邮件寻求支持。 安装Mav...

fanl1982
2014/01/23
1.2W
7
研究虚拟机--Jikes RVM

Jikes研究虚拟机(Jikes Research Virtual Machine,简称Jikes RVM)是一种成熟的用于执行Java程序的虚拟机,其早期版本与当前版本分别在通用公共许可证(CPL)与Eclipse公共许可证(EPL)下开...

匿名
2013/02/13
1.1K
0

没有更多内容

加载失败,请刷新页面

加载更多

在视图控制器之间传递数据 - Passing Data between View Controllers

问题: I'm new to iOS and Objective-C and the whole MVC paradigm and I'm stuck with the following: 我是iOS和Objective-C以及整个MVC范例的新手,但我坚持以下几点: I have a view th......

fyin1314
33分钟前
6
0
Elasticsearch中mapping值得注意的一些小细节

简介 在Elasticsearch中mapping有很多可以配置的地方,但是使用多了就会发现,一般情况有关mapping最常用、也最实用的就简单的几个需要注意的地方。 下面就简单的介绍一下关于这些mapping中值...

trayvon
36分钟前
0
0
趣味编程-大鱼吃小鱼(5-7岁)

上一节老师教小朋友们编写了摘星星的游戏,今天跟着了老师学一下大鱼吃小鱼这个游戏吧!拿上你们的平板,跟着老师一起来做吧。 防止失联,点个“在看”!多多转发分享是老师录制视频的动力哦...

rainbow0124
今天
10
0
大集合!写作辅助工具

↑公众号关注 “Graph-AI” 专注于 图机器学习 大集合!论文写作辅助工具 这里收集论文写作过程中的辅助工具,比如包括Latex、画图、图表、语法、词语搭配、文献查找\下载\整理、翻译等。 会...

chengsen
08/01
0
0
SSL指纹的自定义功能-VMLogin 中文版防关联指纹浏览器在1.2.6.7 版本更新中加入

VMLogin 中文版指纹浏览器 在本次1.2.6.7 版本更新中加入了SSL指纹的自定义功能。 VMLogin 中文版浏览器:https://www.vmlogin.cc/ 主要可以设置 密码套件 的个数和顺序,这样能可以对抗一些...

VMlogin中文版防关联浏览器
48分钟前
13
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部