为什么我无法在 MacOS 上连接到 Cassandra?

发布于 2025-01-12 00:12:22 字数 878 浏览 0 评论 0原文

我使用的是 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.shcassandra.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゃ懵逼小萝莉 2025-01-19 00:12:22

因此,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 移动到所需位置:

mv ~/Downloads/apache-cassandra-4.0.3-bin.tar.gz ~/local/

Untar:

cd ~/local
tar -zxvf apache-cassandra-4.0.3-bin.tar.gz
cd apache-cassandra-4.0.3

配置(如果跳过此步骤,则) start:

atom conf/cassandra.yaml

Start:

bin/cassandra -p cassandra.pid

这 ^ 使用 PID 文件启动 Cassandra。这允许您脱离输出,并且它仍然会在后台继续运行(与 bin/cassandrabin/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:

mv ~/Downloads/apache-cassandra-4.0.3-bin.tar.gz ~/local/

Untar:

cd ~/local
tar -zxvf apache-cassandra-4.0.3-bin.tar.gz
cd apache-cassandra-4.0.3

Configure (if you skip this step, it will) start:

atom conf/cassandra.yaml

Start:

bin/cassandra -p cassandra.pid

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 or bin/cassandra -f).

踏雪无痕 2025-01-19 00:12:22

此消息表明 localhost 上没有运行的 Cassandra 实例侦听端口 9042

('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 正在您的 Mac 上运行。最快的方法是使用以下任一命令确定是否有进程正在侦听端口 9042

$ netstat -tnlp
$ sudo lsof -nPi -sTCP:LISTEN

Cassandra 默认情况下侦听在 中配置的 CQL 端口 9042 上的客户端连接>cassandra.yaml with:

native_transport_port: 9042

客户端使用 cassandra.yaml 中的 rpc_address 连接到 Cassandra:

rpc_address: localhost

如果您已将其设置为 Mac 的 IP 地址那么您需要使用它作为应用程序这一行的接触点,而不是 localhost

    cluster = Cluster(['127.0.0.1']) 

如果您是 Cassandra 新手,我建议您查看 datastax.com/dev 其中有很多免费的实践互动学习资源。特别是,Cassandra 基础知识学习系列可让您快速学习基本概念。干杯!

This message indicates that there is no Cassandra instance running on localhost listening on port 9042:

('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")})

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:

$ netstat -tnlp
$ sudo lsof -nPi -sTCP:LISTEN

Cassandra by default listens for client connections on CQL port 9042 configured in cassandra.yaml with:

native_transport_port: 9042

Clients connect to Cassandra using the rpc_address in cassandra.yaml:

rpc_address: localhost

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:

    cluster = Cluster(['127.0.0.1']) 

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文