【问题标题】:How do you create the first user in Cassandra DB如何在 Cassandra DB 中创建第一个用户
【发布时间】:2014-04-08 10:58:36
【问题描述】:

如何在 cassandra 数据库中创建第一个用户?

我试过了:

CREATE USER username WITH PASSWORD "";

它说:

Bad Request: Only superusers are allowed to perform CREATE USER queries

但在此尝试之前我从未创建过用户,那么如何在 cassandra 数据库中创建第一个用户?

这似乎有点奇怪,因为它就像鸡和蛋的问题,但人们使用 Cassandra,所以我确信在某个地方一定有解决方案。

【问题讨论】:

    标签: cassandra cql cqlsh


    【解决方案1】:

    启用身份验证和授权后,您可以像这样以默认 Cassandra 管理员用户身份登录(到本地 Cassandra 实例):

    ./cqlsh localhost -u cassandra -p cassandra
    

    如果你在 Windows Server 上运行 Cassandra,我相信 you need to invoke it with Python

    python cqlsh localhost -u cassandra -p cassandra
    

    进入后,您的首要任务应该是创建另一个超级用户帐户。

    CREATE USER dba WITH PASSWORD 'bacon' SUPERUSER;
    

    接下来,将当前 Cassandra 超级用户的密码设置为其他内容是一个非常好的主意……最好是冗长且难以理解的内容。对于您的新超级用户,您应该不再需要默认的 Cassandra 帐户。

    ALTER USER cassandra WITH PASSWORD 'dfsso67347mething54747long67a7ndincom4574prehensi562ble';
    

    欲了解更多信息,请查看这篇 DataStax 文章:A Quick Tour of Internal Authentication and Authorization Security in DataStax Enterprise and Apache Cassandra

    【讨论】:

    • 为什么登录时需要 localhost 参数?我以前从来没有把它放进去
    • 其实不是。我只是将它包括在内,以防你想连接到远程 Cassandra 服务器,然后你就会知道在哪里指定它。但是./cqlsh -u cassandra -p cassandra 应该可以正常工作。
    • 当您说启用身份验证和授权时,您的明确含义是什么?目前我所做的是更改身份验证器:PasswordAuthenticator 和授权器:AllowAllAuthorizer?
    • @Pinocchio “目前我所做的是更改身份验证器:PasswordAuthenticator 和授权器:AllowAllAuthorizer?”...是的,这就是我的意思。
    • Microsoft Azure 实例不允许使用 cassandra/cassandra 登录...我需要编辑 yaml 文件并重置密码
    【解决方案2】:

    改变

    authenticator: AllowAllAuthenticator 
    

    authenticator: PasswordAuthenticator 
    

    cassandra.yamlconfiguration 文件中并重新启动 Cassandra。

    这将在重新启动时为您创建一个超级用户 cassandra。确保您安装了 Phthon27、thrift-0.91、Cassandra(datastax 社区版 2.0.9)等。现在,当您登录 cassandra 时,它会让您以超级用户身份输入。您现在可以创建新的超级用户并更改现有超级用户的密码。

    python cqlsh localhost -u cassandra -p cassandra 
    Connected to Test Cluster at localhost:9160. 
    [cqlsh 4.1.1 | Cassandra 2.0.9 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
    

    使用帮助寻求帮助。

    cqlsh> create user abc with password 'xyz' superuser; 
    cqlsh> alter user cassandra with password 'gaurav'; 
    cqlsh> exit
    

    【讨论】:

    • 如果你把这个大段拆开一点,这个答案会更容易阅读。此外,请在发布之前检查您的答案的渲染输出。输入文本中的一个换行符不在输出中(在前一行添加两个空格或在它们之间添加一个空行)。
    • 谢谢你的回答提醒我重启 cassandra :p
    【解决方案3】:

    要开始使用身份验证,默认的超级用户用户名/密码对是cassandra/cassandra。这应该可以解决先有鸡还是先有蛋的问题。

    来源: http://www.datastax.com/docs/datastax_enterprise3.0/security/native_authentication

    【讨论】:

    • 当然,但我什至如何以任何用户身份登录?
    • 您对启动 cqlsh 的 python 调用使用命令行参数,如下所示: "C:\Program Files\DataStax Community\python\python.exe" "C:\Program Files\DataStax Community\apache -cassandra\bin\cqlsh" 本地主机 -u cassandra -p cassandra
    【解决方案4】:

    回复:一旦您启用了身份验证和授权(从 3 月 6 日 14:41 的 BryceAtNetwork23 评论开始)

    首先,是否需要更改授权才能设置身份验证?我猜不是。

    其次,如果您有数据中心风格的复制设置,那么设置授权并非易事。我使用以下步骤设置授权:

    • 在 conf/cassandra.yaml 中,将所有节点的身份验证器从 AllowAllAuthenticator 更改为 PasswordAuthenticator
    • 重启所有节点
    • 如上所述更改了默认的“cassandra”密码并添加了其他超级用户
    • 通过运行将 system_auth 密钥空间更改为冗余(根据 cassandra.yaml 文件中的说明):“ALTER KEYSPACE system_auth WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'MY_DATACENTER_NAME':N }”
    • 我将 N 设置为我的数据中心中的节点数(即完全冗余)
    • 在每个节点上串行运行 bin/nodetool 修复

    对于知道自己在做什么的人来说,这听起来合理吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-08
      • 2015-04-12
      • 1970-01-01
      • 2018-02-05
      • 2023-01-07
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多