Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用Java驱动程序连接到Cassandra时出现AuthenticationException_Cassandra - Fatal编程技术网

尝试使用Java驱动程序连接到Cassandra时出现AuthenticationException

尝试使用Java驱动程序连接到Cassandra时出现AuthenticationException,cassandra,Cassandra,我试图编写一个Java代码段,在一个单独的线程中启动Cassandra,然后使用驱动程序进行连接并创建几个用户。我们有一个使用基于Python的CQLSH客户端的脚本,但是当我们将一台服务器升级到Ubuntu 16.04时遇到了问题。显然,RHEL 7上的Ubuntu与Python版本不兼容,但Ubuntu 16.04不兼容。我甚至尝试在Ubuntu上降级Python版本,但仍然无法使用CQLSH客户端,所以我求助于Java。这些是Maven依赖项。请注意,我曾尝试使用默认的Guava版本16.

我试图编写一个Java代码段,在一个单独的线程中启动Cassandra,然后使用驱动程序进行连接并创建几个用户。我们有一个使用基于Python的CQLSH客户端的脚本,但是当我们将一台服务器升级到Ubuntu 16.04时遇到了问题。显然,RHEL 7上的Ubuntu与Python版本不兼容,但Ubuntu 16.04不兼容。我甚至尝试在Ubuntu上降级Python版本,但仍然无法使用CQLSH客户端,所以我求助于Java。这些是Maven依赖项。请注意,我曾尝试使用默认的Guava版本16.0,但遇到了一些其他问题,因此我用17.0取代了它

[INFO] +- commons-io:commons-io:jar:1.3.2:compile
[INFO] +- org.apache.cassandra:cassandra-all:jar:2.2.4:compile
[INFO] |  +- org.xerial.snappy:snappy-java:jar:1.1.1.7:compile
[INFO] |  +- net.jpountz.lz4:lz4:jar:1.3.0:compile
[INFO] |  +- com.ning:compress-lzf:jar:0.8.4:compile
[INFO] |  +- commons-cli:commons-cli:jar:1.1:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.9:compile
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO] |  +- org.apache.commons:commons-math3:jar:3.2:compile
[INFO] |  +- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.4:compile
[INFO] |  +- org.antlr:antlr:jar:3.5.2:compile
[INFO] |  |  \- org.antlr:ST4:jar:4.0.8:compile
[INFO] |  +- org.antlr:antlr-runtime:jar:3.5.2:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] |  +- org.slf4j:log4j-over-slf4j:jar:1.7.7:compile
[INFO] |  +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile
[INFO] |  +- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] |  +- com.boundary:high-scale-lib:jar:1.0.6:compile
[INFO] |  +- org.yaml:snakeyaml:jar:1.11:compile
[INFO] |  +- org.mindrot:jbcrypt:jar:0.3m:compile
[INFO] |  +- io.dropwizard.metrics:metrics-core:jar:3.1.0:compile
[INFO] |  +- com.addthis.metrics:reporter-config3:jar:3.0.0:compile
[INFO] |  |  +- com.addthis.metrics:reporter-config-base:jar:3.0.0:compile
[INFO] |  |  \- org.hibernate:hibernate-validator:jar:4.3.0.Final:compile
[INFO] |  |     +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] |  |     \- org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
[INFO] |  +- com.thinkaurelius.thrift:thrift-server:jar:0.3.7:compile
[INFO] |  |  \- com.lmax:disruptor:jar:3.0.1:compile
[INFO] |  +- com.clearspring.analytics:stream:jar:2.5.2:compile
[INFO] |  |  \- it.unimi.dsi:fastutil:jar:6.5.7:compile
[INFO] |  +- net.sf.supercsv:super-csv:jar:2.1.0:compile
[INFO] |  +- ch.qos.logback:logback-core:jar:1.0.6:compile
[INFO] |  +- ch.qos.logback:logback-classic:jar:1.0.6:compile
[INFO] |  +- org.apache.thrift:libthrift:jar:0.9.2:compile
[INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.2.5:compile
[INFO] |  |  \- org.apache.httpcomponents:httpcore:jar:4.2.4:compile
[INFO] |  +- org.apache.cassandra:cassandra-thrift:jar:2.2.4:compile
[INFO] |  +- net.java.dev.jna:jna:jar:4.0.0:compile
[INFO] |  +- com.github.jbellis:jamm:jar:0.3.0:compile
[INFO] |  +- com.github.tjake:crc32ex:jar:0.1.1:compile
[INFO] |  +- io.netty:netty-all:jar:4.0.23.Final:compile
[INFO] |  +- joda-time:joda-time:jar:2.4:compile
[INFO] |  \- org.fusesource:sigar:jar:1.6.4:compile
[INFO] +- com.google.guava:guava:jar:17.0:test
[INFO] +- com.datastax.cassandra:cassandra-driver-core:jar:3.1.2:compile
[INFO] |  +- io.netty:netty-handler:jar:4.0.37.Final:compile
[INFO] |  |  +- io.netty:netty-buffer:jar:4.0.37.Final:compile
[INFO] |  |  |  \- io.netty:netty-common:jar:4.0.37.Final:compile
[INFO] |  |  +- io.netty:netty-transport:jar:4.0.37.Final:compile
[INFO] |  |  \- io.netty:netty-codec:jar:4.0.37.Final:compile
[INFO] |  +- com.github.jnr:jnr-ffi:jar:2.0.7:compile
[INFO] |  |  +- com.github.jnr:jffi:jar:1.2.10:compile
[INFO] |  |  +- com.github.jnr:jffi:jar:native:1.2.10:runtime
[INFO] |  |  +- org.ow2.asm:asm:jar:5.0.3:compile
[INFO] |  |  +- org.ow2.asm:asm-commons:jar:5.0.3:compile
[INFO] |  |  +- org.ow2.asm:asm-util:jar:5.0.3:compile
[INFO] |  |  \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile
[INFO] |  \- com.github.jnr:jnr-posix:jar:3.0.27:compile
[INFO] |     \- com.github.jnr:jnr-constants:jar:0.9.0:compile
[INFO] +- com.cisco.dascode:dascode-cassandra:zip:2.2.4:compile
[INFO] \- junit:junit:jar:4.11:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test
起初,我使用cassandra unit启动服务器,但遇到了一系列其他问题,因此我最终只是在一个单独的线程中从代码启动服务器,如下所示:

System.setProperty("cassandra.config", "file:" + file.getAbsolutePath()); // Path to cassandra.yaml
System.setProperty("cassandra-foreground", "true");
System.setProperty("cassandra.native.epoll.enabled", "false");
...
cassandraDaemon = new CassandraDaemon();
cassandraDaemon.activate();
Cluster cluster = new       Cluster.Builder().addContactPoints("localhost").withPort(9042).withCredentials("cassandra", "cassandra").build();
Session session = cluster.connect("system_auth");
客户端代码如下所示:

System.setProperty("cassandra.config", "file:" + file.getAbsolutePath()); // Path to cassandra.yaml
System.setProperty("cassandra-foreground", "true");
System.setProperty("cassandra.native.epoll.enabled", "false");
...
cassandraDaemon = new CassandraDaemon();
cassandraDaemon.activate();
Cluster cluster = new       Cluster.Builder().addContactPoints("localhost").withPort(9042).withCredentials("cassandra", "cassandra").build();
Session session = cluster.connect("system_auth");
我尝试了使用和不使用键空间的connect调用,在行为上没有区别。当客户端尝试连接时,出现以下异常:

com.datastax.driver.core.exceptions.AuthenticationException: Authentication error on host localhost/127.0.0.1:9042: Username and/or password are incorrect
at com.datastax.driver.core.Connection$8.apply(Connection.java:393)
at com.datastax.driver.core.Connection$8.apply(Connection.java:362)
有趣的是,如果我只在Mac上本地启动服务器部分,我可以使用用户名/密码设置为cassandra/cassandra的CQLSH客户端,并且我没有任何身份验证问题

我的cassandra.yaml文件如下所示:

cluster_name: 'Test Cluster'
num_tokens: 256
hinted_handoff_enabled: true
hinted_handoff_throttle_in_kb: 1024
max_hints_delivery_threads: 2
batchlog_replay_throttle_in_kb: 1024
authenticator: PasswordAuthenticator
authorizer: CassandraAuthorizer
role_manager: CassandraRoleManager
roles_validity_in_ms: 2000
permissions_validity_in_ms: 2000
partitioner: org.apache.cassandra.dht.Murmur3Partitioner
disk_failure_policy: stop
commit_failure_policy: stop
key_cache_size_in_mb:
key_cache_save_period: 14400
row_cache_size_in_mb: 0
row_cache_save_period: 0
counter_cache_size_in_mb:
counter_cache_save_period: 7200
commitlog_sync: periodic
commitlog_sync_period_in_ms: 10000
commitlog_segment_size_in_mb: 32
seed_provider:
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
    parameters:
        - seeds: "127.0.0.1"
concurrent_reads: 32
concurrent_writes: 32
concurrent_counter_writes: 32
memtable_allocation_type: heap_buffers
index_summary_capacity_in_mb:
index_summary_resize_interval_in_minutes: 60
trickle_fsync: false
trickle_fsync_interval_in_kb: 10240
storage_port: 7000
ssl_storage_port: 7001
listen_address: localhost
start_native_transport: true
native_transport_port: 9042
start_rpc: false
rpc_address: localhost
rpc_port: 9160
rpc_keepalive: true
rpc_server_type: sync
thrift_framed_transport_size_in_mb: 15
incremental_backups: false
snapshot_before_compaction: false
auto_snapshot: true
tombstone_warn_threshold: 1000
tombstone_failure_threshold: 100000
column_index_size_in_kb: 64
batch_size_warn_threshold_in_kb: 5
batch_size_fail_threshold_in_kb: 50
compaction_throughput_mb_per_sec: 16
compaction_large_partition_warning_threshold_mb: 100
sstable_preemptive_open_interval_in_mb: 50

任何关于我可能做错了什么的提示都将不胜感激

我想这是一种比赛条件。客户端尝试连接时,服务器尚未完全初始化。我放了一根线;在尝试连接之前在代码中输入,这是有效的。是否有更好的方法验证服务器是否已完全初始化

我想这是一种比赛条件。客户端尝试连接时,服务器尚未完全初始化。我放了一根线;在尝试连接之前在代码中输入,这是有效的。是否有更好的方法验证服务器是否已完全初始化

我不确定这是否有帮助,但如果您在创建Cassandrademon之前添加以下内容,cassandra用户可能不会立即出现:

System.setPropertycassandra.superuser\u setup\u delay\u ms,0;
这可能会解决您的问题。默认值为10000 10秒,这解释了为什么睡眠20秒可能会解决您的问题。

我不确定这是否有帮助,但如果您在创建Cassandrademon之前添加以下内容,cassandra用户可能不会立即出现:

System.setPropertycassandra.superuser\u setup\u delay\u ms,0;
这可能会解决您的问题。该值默认为10000 10秒,这解释了为什么睡眠20秒可能会解决您的问题。

这可能对您没有帮助,但对于DSE,JMX中有一个com.datasax.bdp:type=core,name=DseDaemon startupped操作,但这需要点击JMX和DSE这可能对您没有帮助,但对于DSE,JMX中有一个com.datasax.bdp:type=core,name=DseDaemon StartupFinished操作,但这需要点击JMX和DSE