docker cassandra集群搭建
1、使用daocloud的镜像,创建docker集群
启用一个node
docker run -d --name cassandra -p 9042:9042 daocloud.io/library/cassandra
添加第二个node
docker run --name cassandra2 -d -e CASSANDRA_SEEDS="$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' cassandra)" daocloud.io/library/cassandra
进入某一个node
docker exec -it cassandra bash
可以看到集群建立
root@dbf6f33463de:/# nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.3 300.64 KiB 256 50.3% 57be7d95-e18c-4e65-9147-97bee3fd343a rack1
UN 172.17.0.2 245.31 KiB 256 49.7% cf5dd832-3af4-4e5a-9dd6-398a22f4ae0a rack1
2、python调用
在另外一台host上面安装Cassandra-driver
pip install cassandra-driver==3.6.0
即可使用客户端接入数据库
from cassandra.cluster import Cluster
cluster = Cluster(["192.168.137.30"]) #Cassandra的host ip
session = cluster.connect('my_keyspace')