cassandra设置密码

本文详细介绍了如何在Cassandra中设置密码,包括修改`authenticator`为`PasswordAuthenticator`,创建和修改用户密码,以及在Java客户端使用Credentials进行连接。还展示了Java代码示例以初始化连接和重置连接过程。
摘要由CSDN通过智能技术生成
  1. 给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);

}

        

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值