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

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

Amazon Keyspaces 中的连接故障排除

连接时遇到问题? 以下介绍一些常见问题以及如何解决这些问题。

连接到 Amazon Keyspaces 端点时出错

连接失败和连接错误会导致不同的错误信息。以下部分涵盖了最常见的场景。

我无法使用 cqlsh 连接到 Amazon Keyspaces

您尝试使用 cqlsh 连接到 Amazon Keyspaces 端点,但连接失败并显示 Connection error

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

注意

如果您尝试从 VPC 连接到 Amazon Keyspaces,需要额外的权限。要使用 VPC 端点成功配置连接,请按照教程:使用接口 VPC 端点连接到 Amazon Keyspaces 中的步骤操作。

您尝试使用 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,但收到 unknown SSL 错误。

如果 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 实例的配置造成的cqlsh,而不是由 Amazon EC2 实例的配置引起的,您可以尝试使用连接您的密钥空间 Amazon CLI,例如使用以下命令。

aws keyspaces list-tables --keyspace-name 'my_keyspace'

如果此命令也超时,则表示 Amazon EC2 实例的配置不正确。

要确认您是否有足够的权限访问 Amazon Keyspaces,您可以使用 Amazon CloudShell 进行连接。cqlsh如果该连接已建立,则需要配置 Amazon EC2 实例。

要解决此问题,请确认您的 Amazon EC2 实例具有允许流向 Amazon Keyspaces 的出站规则。如果情况并非如此,则需要为 EC2 实例创建一个新的安全组,并添加一条允许出站流量 Amazon Keyspaces 资源的规则。要更新出站规则以允许流向 Amazon Keyspaces,请从 “类型” 下拉菜单中选择 CQLSH/CAS SANDRA。

使用出站流量规则创建新的安全组后,您需要将其添加到实例中。选择实例,然后依次选择操作安全性和更改安全组。添加带有出站规则的新安全组,但要确保默认组也保持可用。

有关如何查看和修改 EC2 出站规则的更多信息,请参阅《适用于 Linux 实例的 Amazon EC2 用户指南》中的向安全组添加规则

您尝试使用 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."',)}) #

要解决此问题,请确保 IAM 用户 testuser-at-12345678910 有权访问 Amazon Keyspaces。有关授予 Amazon Keyspaces 访问权限的 IAM 策略的示例,请参阅 Amazon Keyspaces 基于身份的策略示例

有关专门针对 IAM 访问的故障排除指南,请参阅Amazon Keyspaces 身份和访问问题排查

您尝试使用 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"',)}) #

要解决此问题,请验证代码中的 USERNAMEPASSWORD 与生成服务专用凭证时获得的用户名和密码相匹配。

重要

如果您在尝试使用 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— 指定与 IAM 用户或角色关联的 Amazon 访问密钥。

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

要了解有关访问密钥和 SigV4 插件的更多信息,请参阅如何为 Amazon 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’)})

要解决此问题,请验证您在使用 SigV4 插件时传递了 AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY。要了解有关访问密钥和 SigV4 插件的更多信息,请参阅如何为 Amazon 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 插件的更多信息,请参阅如何为 Amazon Keyspaces 创建和配置 Amazon 凭证

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

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

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

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

  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 端点用于 Amazon Keyspaces

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

    hostname-validation = false

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

  4. 要确认 VPC 端点的配置是否正确,可以在 VPC 运行以下语句。

    注意

    您不能使用本地开发人员环境或 Amazon Keyspaces CQL 编辑器来确认此配置,因为它们使用的是公共端点。

    SELECT peer FROM system.peers;

    输出应与本示例类似,根据您的 VPC 设置和 Amazon 区域,返回 2 到 6 个带有私有 IP 地址的节点。

    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 命令连接 Amazon Keyspaces,但收到 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 策略示例,请参阅访问 Amazon Keyspaces 表

要查看专门针对 IAM 的故障排除部分,请参阅Amazon Keyspaces 身份和访问问题排查

我尝试使用 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 语句来使用单行数据,从而隔离错误。

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