1

我似乎对 Zookeeper 有一个非常烦人的问题。我已经设法创建和编译我自己的身份验证提供程序。此提供程序在配置中设置如下:

authProvider.1=io.whatever.zookeeper.auth.ChefZkAuth

我已经设法在根 znode 上设置了 ACL,现在我在没有身份验证的情况下看不到集群上的任何内容,这就是我想要的。我的问题是,当我尝试进行身份验证时,我得到:

2013-06-19 19:38:50,928 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@863] - got auth packet /127.0.0.1:45518
2013-06-19 19:38:50,934 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ChefZkAuth@21] -  >>>>>>>>>>>>>>>>>> /127.0.0.1 is connecting...
2013-06-19 19:38:50,934 [myid:] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@873] - Caught runtime exception from AuthenticationProvider: chef due to java.lang.UnsupportedOperationException
2013-06-19 19:38:50,935 [myid:] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@883] - Authentication failed for scheme: chef

因此,似乎正在调用我的提供程序。但无论出于何种原因,Zookeeper 在启动时都没有加载它。这是 Zookeeper 在启动时告诉我的:

radek@radek-virtual-machine:/opt/zookeeper/current/bin$ ./zkServer.sh start-foreground
JMX enabled by default
Using config: /opt/zookeeper/current/bin/../conf/zoo.cfg
2013-06-19 19:53:24,421 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading configuration from: /opt/zookeeper/current/bin/../conf/zoo.cfg
2013-06-19 19:53:24,428 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2013-06-19 19:53:24,429 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2013-06-19 19:53:24,430 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2013-06-19 19:53:24,430 [myid:] - WARN  [main:QuorumPeerMain@113] - Either no config or no quorum defined in config, running  in standalone mode
2013-06-19 19:53:24,452 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading configuration from: /opt/zookeeper/current/bin/../conf/zoo.cfg
2013-06-19 19:53:24,463 [myid:] - INFO  [main:ZooKeeperServerMain@95] - Starting server
2013-06-19 19:53:24,511 [myid:] - INFO  [main:Environment@100] - Server environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT
2013-06-19 19:53:24,512 [myid:] - INFO  [main:Environment@100] - Server environment:host.name=radek-virtual-machine
2013-06-19 19:53:24,513 [myid:] - INFO  [main:Environment@100] - Server environment:java.version=1.7.0_21
2013-06-19 19:53:24,513 [myid:] - INFO  [main:Environment@100] - Server environment:java.vendor=Oracle Corporation
2013-06-19 19:53:24,514 [myid:] - INFO  [main:Environment@100] - Server environment:java.home=/usr/lib/jvm/java-7-openjdk-amd64/jre
2013-06-19 19:53:24,515 [myid:] - INFO  [main:Environment@100] - Server environment:java.class.path=/opt/zookeeper/current/bin/../build/classes:/opt/zookeeper/current/bin/../build/lib/*.jar:/opt/zookeeper/current/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper/current/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper/current/bin/../lib/netty-3.2.2.Final.jar:/opt/zookeeper/current/bin/../lib/log4j-1.2.15.jar:/opt/zookeeper/current/bin/../lib/jline-0.9.94.jar:/opt/zookeeper/current/bin/../lib/ChefZkAuth-1.0-SNAPSHOT.jar:/opt/zookeeper/current/bin/../zookeeper-3.4.5.jar:/opt/zookeeper/current/bin/../src/java/lib/*.jar:/opt/zookeeper/current/bin/../conf:
2013-06-19 19:53:24,515 [myid:] - INFO  [main:Environment@100] - Server environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib
2013-06-19 19:53:24,516 [myid:] - INFO  [main:Environment@100] - Server environment:java.io.tmpdir=/tmp
2013-06-19 19:53:24,520 [myid:] - INFO  [main:Environment@100] - Server environment:java.compiler=<NA>
2013-06-19 19:53:24,521 [myid:] - INFO  [main:Environment@100] - Server environment:os.name=Linux
2013-06-19 19:53:24,521 [myid:] - INFO  [main:Environment@100] - Server environment:os.arch=amd64
2013-06-19 19:53:24,522 [myid:] - INFO  [main:Environment@100] - Server environment:os.version=3.8.0-19-generic
2013-06-19 19:53:24,523 [myid:] - INFO  [main:Environment@100] - Server environment:user.name=radek
2013-06-19 19:53:24,524 [myid:] - INFO  [main:Environment@100] - Server environment:user.home=/home/radek
2013-06-19 19:53:24,525 [myid:] - INFO  [main:Environment@100] - Server environment:user.dir=/opt/zookeeper/zookeeper-3.4.5/bin
2013-06-19 19:53:24,548 [myid:] - INFO  [main:ZooKeeperServer@726] - tickTime set to 1000
2013-06-19 19:53:24,550 [myid:] - INFO  [main:ZooKeeperServer@735] - minSessionTimeout set to -1
2013-06-19 19:53:24,551 [myid:] - INFO  [main:ZooKeeperServer@744] - maxSessionTimeout set to -1
2013-06-19 19:53:24,636 [myid:] - INFO  [main:Login@293] - successfully logged in.
2013-06-19 19:53:24,654 [myid:] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:2181
2013-06-19 19:53:24,692 [myid:] - INFO  [main:FileSnap@83] - Reading snapshot /tmp/zookeeper/version-2/snapshot.14
2013-06-19 19:53:24,720 [myid:] - INFO  [main:FileTxnSnapLog@240] - Snapshotting: 0x14 to /tmp/zookeeper/version-2/snapshot.14
2013-06-19 19:53:26,689 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /127.0.0.1:45648
2013-06-19 19:53:26,789 [myid:] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@793] - Connection request from old client /127.0.0.1:45648; will be dropped if server is in r-o mode
2013-06-19 19:53:26,791 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@832] - Client attempting to renew session 0x13f5d7d94460003 at /127.0.0.1:45648
2013-06-19 19:53:26,797 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@595] - Established session 0x13f5d7d94460003 with negotiated timeout 10000 for client /127.0.0.1:45648

这是我的提供者:

package io.whatever.zookeeper.auth;

import org.apache.log4j.Logger;
import org.apache.zookeeper.data.Id;
import org.apache.zookeeper.server.ServerCnxn;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.server.auth.AuthenticationProvider;

public class ChefZkAuth implements AuthenticationProvider {

    private static Logger LOGGER = Logger.getLogger(ChefZkAuth.class);

    public String getScheme() {
        return "chef";
    }

    public KeeperException.Code
    handleAuthentication(ServerCnxn cnxn, byte[] authData)
    {
        String id = cnxn.getRemoteSocketAddress().getAddress().toString();
        LOGGER.info(" >>>>>>>>>>>>>>>>>> " + id + " is connecting...");
        cnxn.getAuthInfo().add(new Id(getScheme(), id));
        return KeeperException.Code.OK;
    }

    public boolean matches(String id, String aclExpr) {
        return true;
    }

    public boolean isAuthenticated() {
        return true;
    }

    public boolean isValid(String id) {
        return true;
    }
}

ChefZkAuth-1.0-SNAPSHOT.jar在类路径中。它在身份验证过程中被使用,但未注册。

我究竟做错了什么?服务器启动期间未加载提供程序的原因是什么?我正在使用 Zookeeper 3.4.5。

4

1 回答 1

0

当我从提供者中删除此行时,似乎我到了某个地方:

cnxn.getAuthInfo().add(new Id(getScheme(), id));

它开始工作。我认为这足以满足我的需要。

于 2013-06-19T18:53:40.570 回答