我已根据official doc使用ScyllaDB设置Docker容器。我创建了键空间和表格。现在我想在此表中插入一些数据。我想我能做到吗?我找到了例子:
import cql
con = cql.connect('localhost', 9160, 'logs', cql_version='3.0.0')
print ("Connected!")
cursor = con.cursor()
CQLString = "INSERT INTO event_attend (event_id, event_type, event_user_id) VALUES (131, 'Party', 3156);"
cursor.execute(CQLString)
但是我得到的错误如下所示。我找不到任何显示如何使用Docker完成的示例。有什么想法吗?
No handlers could be found for logger "thrift.transport.TSocket"
Traceback (most recent call last):
File "scylla_test.py", line 2, in <module>
con = cql.connect('localhost', 9160, 'logs', cql_version='3.0.0')
File "/usr/local/lib/python2.7/dist-packages/cql/connection.py", line 143, in connect
consistency_level=consistency_level, transport=transport)
File "/usr/local/lib/python2.7/dist-packages/cql/connection.py", line 59, in __init__
self.establish_connection()
File "/usr/local/lib/python2.7/dist-packages/cql/thrifteries.py", line 151, in establish_connection
self.transport.open()
File "/usr/local/lib/python2.7/dist-packages/thrift/transport/TTransport.py", line 271, in open
return self.__trans.open()
File "/usr/local/lib/python2.7/dist-packages/thrift/transport/TSocket.py", line 113, in open
raise TTransportException(TTransportException.NOT_OPEN, msg)
thrift.transport.TTransport.TTransportException: Could not connect to any of [('::1', 9160, 0, 0), ('127.0.0.1', 9160)]
答案 0 :(得分:4)
您可以查看端口9042,这是默认的CQL端口。 9160是节俭港口,现在使用较少。 此外,您是否可以确保转发端口,例如:
docker run --name some-scylla \
--volume /var/lib/scylla:/var/lib/scylla \
-p 9042:9042 -p 7000:7000 -p 7001:7001 -p 7199:7199 \
-p 9160:9160 -p 9180:9180 -p 10000:10000 \
-d scylladb/scylla --overprovisioned 1
答案 1 :(得分:1)
&#39; localhost&#39;容器的地址不能在容器本身之外访问。
您可能想要执行以下操作。首先确保使用
启用ScyllaDB节点docker exec -it scylla nodetool status
它应输出类似于:
的内容Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.2 153.41 KB 256 100.0% 70a72849-5608-47d5-8c8d-0f1db0f57444 rack1
如果所有节点的状态为&#34; down&#34; (DN)您可能需要首先启动它们。
现在,使用显示的节点的地址。如果群集中有多个节点,则任何这些地址都可以。如果系统中安装了cqlsh,您可以先尝试手动连接:
cqlsh 172.17.0.2
否则,只需将其放入Python脚本并运行即可。