疑難排解 Amazon Keyspaces 中的連線 - Amazon Keyspaces (適用於 Apache Cassandra)

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

疑難排解 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

若要在使用公用端點進行連線時解決此問題,請從中選取可用的端點亞馬遜 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,但收到 SSL 錯誤。unknown

如果 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 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,您可以嘗試使用 AWS CLI,例如使用下列命令連線至金鑰空間。

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

如果此命令也逾時,表示未正確設定 Amazon EC2 執行個體。

若要確認您有足夠的權限可以存取 Amazon Keyspaces,您可以使用 AWS CloudShell 來連線。cqlsh如果該連線已建立,您需要設定 Amazon EC2 執行個體。

若要解決此問題,請確認您的 Amazon EC2 執行個體具有允許流量傳輸至 Amazon Keyspaces 的輸出規則。如果不是這種情況,則需要為 EC2 執行個體建立新的安全群組,並新增允許傳出流量至 Amazon Keyspaces 資源的規則。若要更新輸出規則以允許流量傳送至 Amazon Keyspaces,請從類型下拉式功能表中選擇 CQLSH/CASSAN DRA。

使用輸出流量規則建立新的安全性群組後,您需要將其新增至執行個體。選取執行個體,然後選擇動作安全性,然後選擇變更安全性群組。使用輸出規則新增安全性群組,但請確定預設群組也可以使用。

如需如何檢視和編輯 EC2 輸出規則的詳細資訊,請參閱 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"',)}) #

若要解決此問題,請確認程式碼中的使用者名稱和碼是否與您產生服務特定認證時取得的使用者名稱和密碼相符。

重要

如果您在嘗試與 cqlsh 連線時持續看到錯誤,請使用--debug選項重新執行命令,並在連絡時包含詳細的輸出。 AWS Support

我無法使用 Cassandra 客戶端驅動程序連接到 Amazon Keyspaces

以下部分顯示了與 Cassandra 客戶端驅動程序連接時最常見的錯誤。

您嘗試使用 DataStax Java 驅動程序連接到 Amazon Keyspaces 表,但收到NodeUnavailableException錯誤信息。

如果嘗試要求的連線中斷,就會導致下列錯誤。

[com.datastax.oss.driver.api.core.NodeUnavailableException: No connection was available to Node(endPoint=vpce-22ff22f2f22222fff-aa1bb234.cassandra.us-west-2.vpce.amazonaws.com/11.1.1111.222:9142, hostId=1a23456b-c77d-8888-9d99-146cb22d6ef6, hashCode=123ca4567)]

若要解決此問題,請尋找活動訊號值,如果活動訊號值較高,則將其降低至 30 秒。

advanced.heartbeat.interval = 30 seconds

然後查找關聯的超時,並確保該值設置為至少 5 秒。

advanced.connection.init-query-timeout = 5 seconds

您嘗試使用驅動程式和 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 使用者或角色相關聯的 AWS 存取金鑰。

  • AWS_SECRET_ACCESS_KEY— 指定與存取金鑰相關聯的秘密金鑰。這基本上是存取金鑰的「密碼」。

若要進一步瞭解存取金鑰和 Sigv4 外掛程式,請參閱如何創建和配置 Amazon Keyspaces 的 AWS 憑據

您嘗試使用驅動程序連接到 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_SECRET_ACCESS_KEY時同時傳遞AWS_ACCESS_KEY_ID和。若要進一步瞭解存取金鑰和 Sigv4 外掛程式,請參閱如何創建和配置 Amazon Keyspaces 的 AWS 憑據

您嘗試使用驅動程序連接到 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 的 AWS 憑據

我的 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 端點的詳細資訊,請參閱 使用 Amazon Keyspaces 的界面 VPC 端點

  3. 確認 Java 驅動程式的 SSL 組態將主機名稱驗證設定為 false,如此範例所示。

    hostname-validation = false

    如需驅動程式組態的詳細資訊,請參閱步驟 2:設定驅動程式

  4. 若要確認已正確設定 VPC 端點,您可以從 VPC 中執行下列陳述式。

    注意

    您無法使用本機開發人員環境或 Amazon Keyspaces CQL 編輯器來確認此組態,因為它們使用公有端點。

    SELECT peer FROM system.peers;

    根據您的 VPC 設定和 AWS 區域,輸出內容應類似於此範例,並在 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,但沒有正確設置信任庫,則會發生這種情況。Amazon Keyspaces 需要使用傳輸層安全性 (TLS) 來協助保護與用戶端的連線安全。

在此情況下,您會看到下列錯誤。

Error creating the initializing the SSL Context

若要解決此問題,請依照本主題開始之前所示的指示設定信任存放區。

設置信任庫後,您應該可以使用以下命令進行連接。

./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 陳述式來隔離錯誤,使用單一資料列。

用戶端會自動嘗試重新建立連線。