Amazon Keyspaces 中的连接疑难解答 - Amazon Keyspaces (for Apache Cassandra)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon Keyspaces 中的连接疑难解答

连接时遇到问题? 以下解决方案。

连接到 Amazon Keyspaces 终端节点时出错

连接失败和连接错误可能会导致不同的错误消息。以下部分介绍最常见的场景。

我无法使用 cqlsh 连接到亚马逊的 Keyspaces

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces 终端节点,但连接失败了Connection error

如果您尝试连接到 Amazon Keyspaces 表,但 cqlsh 配置不正确,则连接将失败。以下部分提供了在您尝试使用 cqlsh 建立连接时导致连接错误的最常见配置问题的示例。

注意

如果您尝试从 VPC 连接到 Amazon Keyspaces,则需要额外的权限。要使用 VPC 终端节点成功配置连接,请按照教程:使用接口 VPC 终端节点,连接Amazon Keyata(创建)。

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你获得了连接timed out错误。

如果您没有提供正确的端口,则可能会出现这种情况,从而导致以下错误。

# cqlsh cassandra.us-east-1.amazonaws.com 9140 -u "USERNAME" -p "PASSWORD" --ssl Connection error: ('Unable to connect to any servers', {'3.234.248.199': error(None, "Tried connecting to [('3.234.248.199', 9140)]. Last error: timed out")})

要解决此问题,请确认您使用端口 9142 进行连接。

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你得到了Name or service not known错误。

如果您使用的端点拼写错误或不存在,则可能出现这种情况。在以下示例中,端点的名称拼写错误。

# cqlsh cassandra.us-east-1.amazon.com 9142 -u "USERNAME" -p "PASSWORD" --ssl Traceback (most recent call last): File "/usr/bin/cqlsh.py", line 2458, in >module> main(*read_options(sys.argv[1:], os.environ)) File "/usr/bin/cqlsh.py", line 2436, in main encoding=options.encoding) File "/usr/bin/cqlsh.py", line 484, in __init__ load_balancing_policy=WhiteListRoundRobinPolicy([self.hostname]), File "/usr/share/cassandra/lib/cassandra-driver-internal-only-3.11.0-bb96859b.zip/cassandra-driver-3.11.0-bb96859b/cassandra/policies.py", line 417, in __init__ socket.gaierror: [Errno -2] Name or service not known

要在使用公共终端节点进行连接时解决此问题,请从中选择一个可用的终端节点Amazon Keyspaces 服务端点,并确认终端节点的名称没有任何错误。如果您使用 VPC 终端节点进行连接,请验证 cqlsh 配置中的 VPC 终端节点信息是否正确。

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你收到OperationTimedOut错误。

Amazon Keyspaces 要求为连接启用 SSL,以确保强大的安全性。如果您收到以下错误,则可能缺少 SSL 参数。

# cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" Connection error: ('Unable to connect to any servers', {'3.234.248.192': OperationTimedOut('errors=Timed out creating connection (5 seconds), last_host=None',)}) #

要解决此问题,请在 cqlsh 连接命令中添加以下标志。

--ssl

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你会收到SSL transport factory requires a valid certfile to be specified错误。

在这种情况下,SSL/TLS 证书的路径丢失,这会导致以下错误。

# cat .cassandra/cqlshrc [connection] port = 9142 factory = cqlshlib.ssl.ssl_transport_factory # # cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" --ssl Validation is enabled; SSL transport factory requires a valid certfile to be specified. Please provide path to the certfile in [ssl] section as 'certfile' option in /root/.cassandra/cqlshrc (or use [certfiles] section) or set SSL_CERTFILE environment variable. #

要解决此问题,请在您的计算机上添加证书文件的路径。

certfile = path_to_file/sf-class2-root.crt

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你收到No such file or directory错误。

如果计算机上证书文件的路径错误,则可能出现这种情况,从而导致以下错误。

# cat .cassandra/cqlshrc [connection] port = 9142 factory = cqlshlib.ssl.ssl_transport_factory [ssl] validate = true certfile = /root/wrong_path/sf-class2-root.crt # # cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" --ssl Connection error: ('Unable to connect to any servers', {'3.234.248.192': IOError(2, 'No such file or directory')}) #

要解决此问题,请验证计算机上证书文件的路径是否正确。

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你收到[X509] PEM lib错误。

如果 SSL/TLS 证书文件sf-class2-root.crt无效,这会导致以下错误。

# cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" --ssl Connection error: ('Unable to connect to any servers', {'3.234.248.241': error(185090057, u"Tried connecting to [('3.234.248.241', 9142)]. Last error: [X509] PEM lib (_ssl.c:3063)")}) #

要解决此问题,请使用以下命令下载 Starfield 数字证书。保存sf-class2-root.crt本地或在您的主目录中。

curl https://certs.secureserver.net/repository/sf-class2-root.crt -O

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你收到unknownSSL 错误。

如果 SSL/TLS 证书文件sf-class2-root.crt此问题,这会导致以下错误。

# cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" --ssl Connection error: ('Unable to connect to any servers', {'3.234.248.220': error(0, u"Tried connecting to [('3.234.248.220', 9142)]. Last error: unknown error (_ssl.c:3063)")}) #

要解决此问题,请使用以下命令下载 Starfield 数字证书。保存sf-class2-root.crt本地或在您的主目录中。

curl https://certs.secureserver.net/repository/sf-class2-root.crt -O

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你收到SSL: CERTIFICATE_VERIFY_FAILED错误。

如果无法验证 SSL/TLS 证书文件,则可能出现这种情况,从而导致以下错误。

Connection error: ('Unable to connect to any servers', {'3.234.248.223': error(1, u"Tried connecting to [('3.234.248.223', 9142)]. Last error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)")})

要解决此问题,请使用以下命令再次下载证书文件。保存sf-class2-root.crt本地或在您的主目录中。

curl https://certs.secureserver.net/repository/sf-class2-root.crt -O

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但收到了Last error: timed out错误。

如果您没有在 Amazon EC2 安全组中为 Amazon Keyspaces 配置出站规则,则可能会出现这种情况,这会导致以下错误。

# cqlsh cassandra.us-east-1.amazonaws.com 9142 -u "USERNAME" -p "PASSWORD" --ssl Connection error: ('Unable to connect to any servers', {'3.234.248.206': error(None, "Tried connecting to [('3.234.248.206', 9142)]. Last error: timed out")}) #

要解决此问题,请检查您的 Amazon EC2 实例是否有阻止与 Amazon Keyspaces 连接的出站规则。如果是这种情况,则需要查看 EC2 实例的安全组,并添加一条允许出站流量 Amazon Keyspaces 资源的规则。要更新出站规则以允许流向 Amazon Keyspaces 的流量,请输入端口9142对于端口范围0.0.0.0/0作为目的地

有关如何查看和编辑 EC2 出站规则的更多信息,请参阅在 Amazon EC2 Linux 实例用户指南中为安全组添加规则

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你收到Unauthorized错误。

如果您在 IAM 用户策略中缺少 Amazon Keyspaces 权限,则可能会出现这种情况,从而导致以下错误。

# cqlsh cassandra.us-east-1.amazonaws.com 9142 -u "testuser-at-12345678910" -p "PASSWORD" --ssl Connection error: ('Unable to connect to any servers', {'3.234.248.241': AuthenticationFailed('Failed to authenticate to 3.234.248.241: Error from server: code=2100 [Unauthorized] message="User arn:aws:iam::12345678910:user/testuser has no permissions."',)}) #

要解决此问题,请尝试以下操作testuser-at-12345678910有权访问 Amazon Keyspaces。有关授予访问 Amazon Keyspaces 的 IAM 策略示例,请参阅亚马逊密钥空间基于身份的政策示例

有关特定于 IAM 访问权限的疑难解答指南,请参阅对亚马逊密钥空间的身份和访问权限进行故障排除

你正在尝试使用 cqlsh 连接到 Amazon Keyspaces,但你收到Bad credentials错误。

如果用户名或密码错误,则可能出现这种情况,从而导致以下错误。

# cqlsh cassandra.us-east-1.amazonaws.com 9142 -u "USERNAME" -p "PASSWORD" --ssl Connection error: ('Unable to connect to any servers', {'3.234.248.248': AuthenticationFailed('Failed to authenticate to 3.234.248.248: Error from server: code=0100 [Bad credentials] message="Provided username USERNAME and/or password are incorrect"',)}) #

要解决此问题,请验证以下用户名密码在你的代码中与你生成时获得的用户名和密码相匹配特定于服务的凭证

重要

如果您在尝试连接 cqlsh 时仍然看到错误,请使用以下命令重新运行该命令--debug选项,并在联系时包括详细输出Amazon Web Services Support。

我无法使用 Cassandra 客户端驱动程序连接到 Amazon Keyspaces

以下各节显示了与 Cassandra 客户端驱动程序连接时最常见的错误。

你正在尝试使用驱动程序和 Sigv4 插件连接到 Amazon Keyspaces 表,但你收到了一个AttributeError错误。

如果证书配置不正确,则会导致以下错误。

cassandra.cluster.NoHostAvailable: (‘Unable to connect to any servers’, {‘44.234.22.154:9142’: AttributeError(“‘NoneType’ object has no attribute ‘access_key’“)})

要解决此问题,请验证您在使用 Sigv4 插件时是否传递了与 IAM 用户或角色关联的证书。SigV4 插件需要以下凭据。

  • AWS_ACCESS_KEY_ID— 指定Amazon与 IAM 用户或角色关联的访问密钥。

  • AWS_SECRET_ACCESS_KEY— 指定与访问密钥相关联的密钥。这基本上是访问密钥的“密码”。

要了解有关访问密钥和 SigV4 插件的更多信息如何为亚马逊Keyspaces 创建和配置Amazon证书

您正在尝试使用驱动程序连接到 Amazon Keyspaces 表,但收到了PartialCredentialsError错误。

如果AWS_SECRET_ACCESS_KEY缺失该问题,可能会导致以下错误。

cassandra.cluster.NoHostAvailable: (‘Unable to connect to any servers’, {‘44.234.22.153:9142’: PartialCredentialsError(‘Partial credentials found in config-file, missing: aws_secret_access_key’)})

要解决此问题,请验证两个AWS_ACCESS_KEY_ID还有AWS_SECRET_ACCESS_KEY使用 SigV4 插件时。要了解有关访问密钥和 SigV4 插件的更多信息如何为亚马逊Keyspaces 创建和配置Amazon证书

您正在尝试使用驱动程序连接到 Amazon Keyspaces 表,但收到了Invalid signature错误。

如果您使用了错误的凭据,则可能会出现这种情况,从而导致以下错误。

cassandra.cluster.NoHostAvailable: (‘Unable to connect to any servers’, {‘44.234.22.134:9142’: AuthenticationFailed(‘Failed to authenticate to 44.234.22.134:9142: Error from server: code=0100 [Bad credentials] message=“Authentication failure: Invalid signature”’)})

要解决此问题,请验证您传递的证书是否与您配置为访问 Amazon Keyspaces 的 IAM 用户或角色相关联。要了解有关访问密钥和 SigV4 插件的更多信息如何为亚马逊Keyspaces 创建和配置Amazon证书

我的 VPC 终端节点连接无法正常工作

您正在尝试使用 VPC 终端节点连接到 Amazon Keyspaces,但收到了令牌映射错误或吞吐量低的问题。

如果 VPC 终端节点连接配置不正确,则可能出现这种情况。

要解决这些问题,请验证以下配置详细信息。要关注 step-by-step 学习如何通过接口 VPC 终端节点为 Amazon Keyspaces 配置连接的教程请参阅教程:使用接口 VPC 终端节点,连接Amazon Keyata(创建)。

  1. 确认用于连接到 Amazon Keyspaces 的 IAM 实体是否具有对用户表的读/写访问权限以及对系统表的读取权限,如以下示例所示。

    { "Version":"2012-10-17", "Statement":[ { "Effect":"Allow", "Action":[ "cassandra:Select", "cassandra:Modify" ], "Resource":[ "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable", "arn:aws:cassandra:us-east-1:111122223333:/keyspace/system*" ] } ] }
  2. 确认用于连接到 Amazon Keyspaces 的 IAM 实体具有访问您的 Amazon EC2 实例上的 VPC 终端节点信息所需的读取权限,如以下示例所示。

    { "Version":"2012-10-17", "Statement":[ { "Sid":"ListVPCEndpoints", "Effect":"Allow", "Action":[ "ec2:DescribeNetworkInterfaces", "ec2:DescribeVpcEndpoints" ], "Resource":"*" } ] }
    注意

    托管策略AmazonKeyspacesReadOnlyAccess_v2AmazonKeyspacesFullAccess包括允许 Amazon Keyspaces 访问 Amazon EC2 实例以读取有关可用接口 VPC 终端节点的信息所需的权限。

    有关 VPC 终端节点的更多信息将接口 VPC 终端节点与接口 VPC 终端节点结合使用来接口

  3. 确认 Java 驱动程序的 SSL 配置是否将主机名验证设置为 false,如本示例所示。

    hostname-validation = false

    有关驱动程序配置的更多信息步骤 2:配置驱动程序

  4. 要确认 VPC 终端节点配置正确,可以从中运行以下语句之内您的 VPC。

    注意

    您无法使用本地开发者环境或 Amazon Keyspaces CQL 编辑器来确认此配置,因为他们使用公共终端节点。

    SELECT peer FROM system.peers;

    输出应与本示例类似,并返回 2 到 6 个具有私有 IP 地址的节点,具体取决于您的 VPC 设置和Amazon区域。

    peer --------------- 192.0.2.0.15 192.0.2.0.24 192.0.2.0.13 192.0.2.0.7 192.0.2.0.8 (5 rows)

我无法使用以下连接cassandra-stress

您正在尝试以下以下cassandra-stress命令,但你收到了一个SSL context错误。

如果您尝试连接到 Amazon Keyspaces,但未正确设置 TrustStore,则会发生这种情况。Amazon Keyspaces 要求使用传输层安全 (TLS) 来帮助保护与客户端的连接。

这种情况,您会看到以下错误。

Error creating the initializing the SSL Context

要解决此问题,请按照本主题中所示的说明设置 TrustStore开始前的准备工作

TrustStore 设置完成后,您应该能够使用以下命令进行连接。

./cassandra-stress user profile=./profile.yaml n=100 "ops(insert=1,select=1)" cl=LOCAL_QUORUM -node "cassandra.eu-north-1.amazonaws.com" -port native=9142 -transport ssl-alg="PKIX" truststore="./cassandra_truststore.jks" truststore-password="trustStore_pw" -mode native cql3 user="user_name" password="password"

我无法使用 IAM 身份进行连接

您正在尝试使用 IAM 身份连接到 Amazon Keyspaces 表,但收到的是Unauthorized错误。

如果您尝试使用 IAM 身份(例如 IAM 用户)连接到 Amazon Keyspaces 表,但未实施策略并先向该用户授予所需权限,则会发生这种情况。

这种情况,您会看到以下错误。

Connection error: ('Unable to connect to any servers', {'3.234.248.202': AuthenticationFailed('Failed to authenticate to 3.234.248.202: Error from server: code=2100 [Unauthorized] message="User arn:aws:iam::1234567890123:user/testuser has no permissions."',)})

要解决此问题,请验证 IAM 用户的权限。要连接标准驱动程序,用户必须至少具有SELECT访问系统表,因为大多数驱动程序在建立连接时都会读取系统密钥空间/表。

有关授予对 Amazon Keyspaces 系统和用户表访问权限的 IAM 策略示例,请参阅访问亚马逊密钥空间表

要查看专门针对 IAM 的疑难解答部分,请参阅对亚马逊密钥空间的身份和访问权限进行故障排除

我正在尝试使用 cqlsh 导入数据,但与我的 Amazon Keyspaces 表的连接已断开

您正在尝试使用 cqlsh 将数据上传到 Amazon Keyspaces,但出现连接错误。

在 cqlsh 客户端连续三次收到来自服务器的任何类型的错误后,与 Amazon Keyspaces 的连接就会失败。cqlsh 客户端失败并显示以下消息。

Failed to import 1 rows: NoHostAvailable - , will retry later, attempt 3 of 100

要解决此错误,您需要确保要导入的数据与 Amazon Keyspaces 中的表架构相匹配。查看导入文件中是否存在解析错误。您可以尝试使用 INSERT 语句来隔离错误,从而使用单行数据。

客户端会自动尝试重新建立连接。