如何在Cassandra DB中创建第一个用户

Pin*_*hio 16 cql cassandra cqlsh

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

我试过了:

CREATE USER username WITH PASSWORD "";
Run Code Online (Sandbox Code Playgroud)

它说:

Bad Request: Only superusers are allowed to perform CREATE USER queries
Run Code Online (Sandbox Code Playgroud)

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

这看起来有点奇怪,因为它就像鸡和蛋的问题,但人们使用Cassandra,所以我相信某处必须有解决方案.

Aar*_*ron 25

启用身份验证和授权后,您可以以默认的Cassandra管理员用户身份登录(到您的本地Cassandra实例),如下所示:

./cqlsh localhost -u cassandra -p cassandra
Run Code Online (Sandbox Code Playgroud)

如果您在Windows Server上运行Cassandra,我相信您需要使用Python调用它:

python cqlsh localhost -u cassandra -p cassandra
Run Code Online (Sandbox Code Playgroud)

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

CREATE USER dba WITH PASSWORD 'bacon' SUPERUSER;
Run Code Online (Sandbox Code Playgroud)

接下来,将当前Cassandra超级用户的密码设置为其他内容是一个非常好的主意...最好是长时间且难以理解的东西.使用新的超级用户,您不应再次使用默认的Cassandra帐户.

ALTER USER cassandra WITH PASSWORD 'dfsso67347mething54747long67a7ndincom4574prehensi562ble';
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请查看此DataStax文章:DataStax Enterprise和Apache Cassandra中的内部身份验证和授权安全快速浏览

  • 实际上,事实并非如此.我只是包含它以防你想连接到远程Cassandra服务器,然后你就知道在哪里指定它.但做`./cqlsh -u cassandra -p cassandra`应该可以正常工作. (5认同)
  • @Pinocchio"目前我所做的是更改身份验证器:PasswordAuthenticator和authrizer:AllowAllAuthorizer?"......是的,这就是我的意思. (2认同)

小智 6

更改

authenticator: AllowAllAuthenticator 
Run Code Online (Sandbox Code Playgroud)

authenticator: PasswordAuthenticator 
Run Code Online (Sandbox Code Playgroud)

cassandra.yaml配置文件中,然后重新启动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]
Run Code Online (Sandbox Code Playgroud)

使用帮助。

cqlsh> create user abc with password 'xyz' superuser; 
cqlsh> alter user cassandra with password 'gaurav'; 
cqlsh> exit
Run Code Online (Sandbox Code Playgroud)