【问题标题】:Connecting python to cassandra a cluster from windows with DseAuthenticator and DseAuthorizer使用 DseAuthenticator 和 DseAuthorizer 从 Windows 将 python 连接到 cassandra 集群
【发布时间】:2017-11-08 10:28:20
【问题描述】:

我已经尝试过使用pycassacassandra.clusterdse.cluster,但没有建立连接。

我觉得我连接到了错误的主机,因为我正在编写 linux 服务器主机名并且没有指定任何关于 cassandra 的内容。

同事告诉我他们只知道在 linux 机器上通过cqlsh inline 连接到服务器。这听起来很不方便。

cassandra.yaml中的具体配置

authenticator: com.datastax.bdp.cassandra.auth.DseAuthenticator
authorizer: com.datastax.bdp.cassandra.auth.DseAuthorizer

我在 pycassa 做什么:

import pycassa
URIPORTLIST = ['12345.mycompany.net:9420']
pool = pycassa.ConnectionPool('my_keyspace', server_list=URIPORTLIST,credentials={'USERNAME':'fancycar','PASSWORD':'becauseimbatman'}, prefill=False)
cf = pycassa.ColumnFamily(pool, 'my_table')

错误信息:

AllServersUnavailable: An attempt was made to connect to each of the servers twice, but none of the attempts succeeded. The last failure was TTransportException: Could not connect to 12345.mycompany.net:9420

dse.cluster

from dse.cluster import Cluster
auth_provider = PlainTextAuthProvider(
        username='fancycar', password='becauseimbatman')
cluster = Cluster(
    ['12345.mycompany.net'],
    port=9042,auth_provider=auth_provider)
session = cluster.connect('my_keyspace')

错误信息:

NoHostAvailable: ('Unable to connect to any servers', {'11.111.11.1': AuthenticationFailed('Failed to authenticate to 11.111.11.2: Error from server: code=0100 [Bad credentials] message="Failed to login. Please re-try."',)})

【问题讨论】:

  • 尝试使用来自 cqlsh 的相同主机和凭据连接到 cassandra 以查看它是否有效...cqlsh 12345.mycompany.net -u fancycar -p becauseimbatman
  • @undefined_variable 感谢您的建议。这给了我一个错误:[root@12345.mycompany.net SYST:~]# cqlsh 12345.mycompany.net -u fancycar -p becauseimbatman Connection error: ('Unable to connect to any servers', {'11.111.11.11': error(None, "Tried connecting to [('11.111.11.11', 9042)]. Last error: timed out")}) 而“照常”登录有效:[root@12345.mycompany.net SYST:~]# cqlsh -u fancycar -p becauseimbatmanConnected to 12345_cluster at 12345.mycompany.net:9042. [cqlsh 5.0.1 | Cassandra 3.0.11.1485 | DSE 5.0.5 | CQL spec 3.4.0 | Native protocol v4]
  • 您的第二个命令在第一次连接到远程服务器时连接到 localhost.. 12345.mycompany.net 是否解析到与 localhost 相同的主机?
  • 好的。我又试了一次,现在你的@undefined_variable 建议确实有效。我下一步应该做什么?
  • 你可能想看看 cassandra.yaml 中的 rpc_address 和 listen_address

标签: python linux cassandra cql cqlsh


【解决方案1】:

已通过使用 dse.auth PlainTextAuthProvider 而不是 Cassandra 来修复..

from dse.cluster import Cluster
# pip install dse-driver
from dse.auth import PlainTextAuthProvider
auth_provider = PlainTextAuthProvider(
        username='fancycar', password='becauseimbatman ')
cluster = Cluster(contact_points=['12345.mycompany.net'],
port=9042, auth_provider=auth_provider)
session = cluster.connect('batcave')
print "connected"
print session.execute("SELECT * FROM robinstears")[0]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-02
    • 2013-10-19
    • 1970-01-01
    • 2013-06-24
    • 2016-08-27
    • 2013-05-21
    • 2020-10-04
    • 1970-01-01
    相关资源
    最近更新 更多