为什么我无法在 MacOS 上连接到 Cassandra?
我使用的是 MAC OS (Monterey 12.2.1) Apple M1,Chip
PostgreSQL 对我来说工作正常,但 Cassandra 不行。安装并导入 cassandra 后,我尝试连接到 Apache Cassandra 的本地实例,如下所示
import cassandra
from cassandra.cluster import Cluster
try:
cluster = Cluster(['127.0.0.1'])
session = cluster.connect()
except Exception as e:
print(e)
但是我收到以下错误:
('Unable to connect to any servers', {'127.0.0.1:9042': ConnectionRefusedError(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
我已安装 cassandra 4.0.3 并且我已尝试了许多在线建议但对我不起作用。我什至找不到像 cassandra-env.sh
、cassandra.yaml
这样的文件
使用命令 java -version
,我有:
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
I am using MAC OS (Monterey 12.2.1) Apple M1, Chip
PostgreSQL works fine for me but Cassandra doesn't. After installing and importing cassandra, I tried connecting to the local instance of Apache Cassandra as done below
import cassandra
from cassandra.cluster import Cluster
try:
cluster = Cluster(['127.0.0.1'])
session = cluster.connect()
except Exception as e:
print(e)
However I got the following error:
('Unable to connect to any servers', {'127.0.0.1:9042': ConnectionRefusedError(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
I have cassandra 4.0.3
installed and and I have tried many of the suggestions online but didn't work for me. I cannot even find files like cassandra-env.sh
, cassandra.yaml
With the command java -version
, I have:
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,Cassandra 是如何安装在您的 Mac 上(自制软件等)的还不是很清楚。但作为实现此目标的另一种可能方法,我将列出有关如何在 Mac 上运行 Apache Cassandra 的步骤,也许这会对您有所帮助。
下载压缩包。对于本示例,我将使用 Apache Cassandra 4.0.3。
https://dlcdn.apache。 org/cassandra/4.0.3/apache-cassandra-4.0.3-bin.tar.gz
将 tarball 移动到所需位置:
Untar:
配置(如果跳过此步骤,则将) start:
Start:
这 ^ 使用 PID 文件启动 Cassandra。这允许您脱离输出,并且它仍然会在后台继续运行(与
bin/cassandra
或bin/cassandra -f
不同)。So it's not abundantly clear how Cassandra was installed on your Mac (homebrew, etc). But as another possible method of achieving this, I'll list out the steps about how I run Apache Cassandra on my Mac, and maybe that'll help you.
Download the tarball. For this example, I'll go with Apache Cassandra 4.0.3.
https://dlcdn.apache.org/cassandra/4.0.3/apache-cassandra-4.0.3-bin.tar.gz
Move the tarball to the desired location:
Untar:
Configure (if you skip this step, it will) start:
Start:
This ^ starts Cassandra with a PID file. That allows you to break-away from the output, and it will still keep running in the background (unlike
bin/cassandra
orbin/cassandra -f
).此消息表明
localhost
上没有运行的 Cassandra 实例侦听端口9042
:您需要确认 Cassandra 正在您的 Mac 上运行。最快的方法是使用以下任一命令确定是否有进程正在侦听端口
9042
:Cassandra 默认情况下侦听在
中配置的 CQL 端口
with:9042
上的客户端连接>cassandra.yaml客户端使用
cassandra.yaml
中的rpc_address
连接到 Cassandra:如果您已将其设置为 Mac 的 IP 地址那么您需要使用它作为应用程序这一行的接触点,而不是
localhost
:如果您是 Cassandra 新手,我建议您查看 datastax.com/dev 其中有很多免费的实践互动学习资源。特别是,Cassandra 基础知识学习系列可让您快速学习基本概念。干杯!
This message indicates that there is no Cassandra instance running on
localhost
listening on port9042
:You need to confirm that Cassandra is running on your Mac. The quickest way is to determine if there is a process listening on port
9042
with either of these commands:Cassandra by default listens for client connections on CQL port
9042
configured incassandra.yaml
with:Clients connect to Cassandra using the
rpc_address
incassandra.yaml
:If you've set it to your Mac's IP address then you will need to use it as the contact point on this line of your app instead of
localhost
:If you're new to Cassandra, I recommend having a look at datastax.com/dev which has lots of free hands-on interactive learning resources. In particular, the Cassandra Fundamentals learning series lets you learn the basic concepts quickly. Cheers!