- 给cassandra设置密码
把cassandra.yaml得第64页
authenticator: AllowAllAuthenticator 改成
authenticator: PasswordAuthenticator
重新启动cassandra
./cqlsh 192.168.200.10 -ucassandra -pcassandra
设置完密码授权后,会默认有个cassandra用户(密码cassandra)
CREATE USER test WITH PASSWORD '123456' SUPERUSER ;
ALTER USER cassandra WITH PASSWORD '123456'; //修改cassandra密码
注意大小写
Java端
public static void initialize(String... endpoints) {
PoolingOptions opts = new PoolingOptions();
opts.setCoreConnectionsPerHost(HostDistance.LOCAL, 5);
opts.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 25);
cluster = Cluster.builder().addContactPoints(endpoints).withPoolingOptions(opts).withCredentials("test", "123456").build();
reinit();
}
private synchronized static void reinit() {
try {
if (session != null && !session.isClosed()) {
session.close();
}
session = cluster.connect("aaa");
LOGGER.info("cassandra connect is reinited");
} catch (Exception e) {
LOGGER.error("cassandra reinit error",e);
}
}