cassandra linux 集群安装,Cassandra 集群的使用——测试集群是否能够访问

访问Cassandra

Cassandra集群中的机器没有主从或者线性关系,分布式的集群可以通过访问集群中任一机器的cassandra来连接cassandra集群。

Cassandra 集群可以有无数个节点

cqlsh连接cassandra

[root@cassandra-01 ~]# cqlsh -u username -pdbname ip1

Connected to DBS Cluster at ip1:9042.

[cqlsh 5·0·1 | Cassandra 3·10 | CQL spec 3·4·4 | Native protocol v4]

Use HELP for help.

cqlsh> select cluster_name, listen_address from system.local;

cluster_name | listen_address

DBS Cluster | ip1

(1 rows)

cqlsh>

Python连接cassandra

在Cassandra 集群部署(二)——Ntpd和Python、Java安装文章中我们介绍了python pip安装命令pip install cassandra-drive安装Python访问Cassandra的驱动包,现在我们在命令行运行python直接访问测试

[root@cassandra-01 ~]# python

Python 2.7.13 (default, Jun 2 2017, 10:12:53)

[GCC 4.4.7 20120313 (Red Hat 4·4·7-18)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> from cassandra.cluster import Cluster

>>> from cassandra.auth import PlainTextAuthProvider

>>> cluster = Cluster(['ip1'],auth_provider=PlainTextAuthProvider(username='username', password='password'))

>>> session = cluster.connect('system')

>>> rows = session.execute('select cluster_name, listen_address from local')

>>> for row in rows:

... print(row)

Row(cluster_name=u'DBS Cluster', listen_address='ip1')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值