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

用户名

我正在尝试编写一个Java代码段,该代码段在单独的线程中启动Cassandra,然后使用驱动程序进行连接并创建一些用户。我们有一个脚本为此目的使用基于Python的CQLSH客户端,但是当我们将其中一台服务器升级到Ubuntu 16.04时遇到了问题。显然在Ubuntu上存在Python版本不兼容(在RHEL 7上有效,但在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");

我已经尝试了使用keyspace和不使用keyspace的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

任何有关我可能在做错事的提示都将不胜感激。

安迪·托尔伯特(Andy Tolbert)

我不确定这是否有帮助,但是如果在创建您的代码之前添加以下内容,则可能不会立即显示cassandra用户CassandraDaemon

System.setProperty("cassandra.superuser_setup_delay_ms", "0");

这可能会解决您的问题。该值默认为10000(10秒)(source),这说明了为什么睡眠20秒可能会解决您的问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用DataStax Java驱动程序1.0.5连接到Cassandra时出现ConnectionException

来自分类Dev

无法使用 Cassandra Datastax Java 驱动程序连接到 Cassandra 节点之一

来自分类Dev

使用DataStax Java驱动程序1.0.4通过CQL连接到Cassandra时发生异常

来自分类Dev

使用Java驱动程序使用kerberos连接到Cassandra集群

来自分类Dev

连接到H2数据库时,DriverManager尝试使用mariadb驱动程序

来自分类Dev

使用datastax Java驱动程序2.1.4连接到Cassandra集群太慢

来自分类Dev

使用 Corda 3 节点驱动程序连接到 RPC 时出现异常

来自分类Dev

Apache Spark:驱动程序(而不只是执行程序)尝试连接到Cassandra

来自分类Dev

尝试使用MailKit连接到邮件服务器时出现AuthenticationException

来自分类Dev

使用Java驱动程序跟踪Cassandra查询时出现空指针错误

来自分类Dev

Cassandra Java驱动程序连接错误

来自分类Dev

当连接到数据库时,出现错误“驱动程序未加载”

来自分类Dev

无法使用 Cassandra 的 C 驱动程序连接到密钥空间

来自分类Dev

Cassandra Java驱动程序错误-所有尝试查询的主机失败连接已关闭

来自分类Dev

尝试连接到我的sql数据库,出现异常,提示“找不到合适的驱动程序”

来自分类Dev

使用准备好的语句时,Cassandra中的python驱动程序出现问题

来自分类Dev

在使用PHP连接到MSSQL Server时找不到驱动程序

来自分类Dev

尝试使用驱动程序安装升级时出现Installshield错误

来自分类Dev

尝试使用驱动程序安装升级时出现Installshield错误

来自分类Dev

尝试连接到Azure SQL服务器时,我得到PDOException找不到驱动程序

来自分类Dev

Qt使用ODBC驱动程序连接到XLSX文件

来自分类Dev

无法使用jdbc驱动程序连接到mysql

来自分类Dev

使用watir Web驱动程序连接到SQL Server

来自分类Dev

无法使用 Scala 驱动程序连接到 MongoDB Atlas

来自分类Dev

驱动程序连接到项目

来自分类Dev

如何使用Eclipse设置Cassandra Java驱动程序

来自分类Dev

Datastax Java Cassandra驱动程序:使用WHERE的多个AND语句?

来自分类Dev

使用Datastax Java驱动程序的Cassandra复合键

来自分类Dev

Mongo C#驱动程序尝试在连接失败时重新连接

Related 相关文章

  1. 1

    使用DataStax Java驱动程序1.0.5连接到Cassandra时出现ConnectionException

  2. 2

    无法使用 Cassandra Datastax Java 驱动程序连接到 Cassandra 节点之一

  3. 3

    使用DataStax Java驱动程序1.0.4通过CQL连接到Cassandra时发生异常

  4. 4

    使用Java驱动程序使用kerberos连接到Cassandra集群

  5. 5

    连接到H2数据库时,DriverManager尝试使用mariadb驱动程序

  6. 6

    使用datastax Java驱动程序2.1.4连接到Cassandra集群太慢

  7. 7

    使用 Corda 3 节点驱动程序连接到 RPC 时出现异常

  8. 8

    Apache Spark:驱动程序(而不只是执行程序)尝试连接到Cassandra

  9. 9

    尝试使用MailKit连接到邮件服务器时出现AuthenticationException

  10. 10

    使用Java驱动程序跟踪Cassandra查询时出现空指针错误

  11. 11

    Cassandra Java驱动程序连接错误

  12. 12

    当连接到数据库时,出现错误“驱动程序未加载”

  13. 13

    无法使用 Cassandra 的 C 驱动程序连接到密钥空间

  14. 14

    Cassandra Java驱动程序错误-所有尝试查询的主机失败连接已关闭

  15. 15

    尝试连接到我的sql数据库,出现异常,提示“找不到合适的驱动程序”

  16. 16

    使用准备好的语句时,Cassandra中的python驱动程序出现问题

  17. 17

    在使用PHP连接到MSSQL Server时找不到驱动程序

  18. 18

    尝试使用驱动程序安装升级时出现Installshield错误

  19. 19

    尝试使用驱动程序安装升级时出现Installshield错误

  20. 20

    尝试连接到Azure SQL服务器时,我得到PDOException找不到驱动程序

  21. 21

    Qt使用ODBC驱动程序连接到XLSX文件

  22. 22

    无法使用jdbc驱动程序连接到mysql

  23. 23

    使用watir Web驱动程序连接到SQL Server

  24. 24

    无法使用 Scala 驱动程序连接到 MongoDB Atlas

  25. 25

    驱动程序连接到项目

  26. 26

    如何使用Eclipse设置Cassandra Java驱动程序

  27. 27

    Datastax Java Cassandra驱动程序:使用WHERE的多个AND语句?

  28. 28

    使用Datastax Java驱动程序的Cassandra复合键

  29. 29

    Mongo C#驱动程序尝试在连接失败时重新连接

热门标签

归档