如果您在创建集群时启用了对集群的 SSH 访问权限,则可以使用 SSH 连接到 Managed Service for Apache Spark 集群。
启用或停用对集群的 SSH 访问权限
对于 3.1 之前的映像版本,默认情况下可以使用 SSH 连接到集群;对于 3.1 及更高版本的映像,默认情况下无法使用 SSH 连接到集群。使用映像版本 2.3.30 及更高版本创建集群时,可以更改默认行为。
Google Cloud CLI
使用 gcloud dataproc clusters create 命令创建集群时,传递 --enable-ssh 标志可启用 SSH 访问权限,传递 --no-ssh 标志可停用集群的 SSH 访问权限。
gcloud dataproc clusters create CLUSTER_NAME \ --region=REGION \ --enable-ssh | --no-ssh \ ... other args
REST API
在 clusters.create 请求中,将 IdentityConfig.enableSsh 字段设置为 true 可启用对集群的 SSH 访问权限,设置为 false 可停用对集群的 SSH 访问权限。
使用 SSH 连接到集群
控制台
- 在 Google Cloud 控制台中,前往虚拟机实例页面。
- 在虚拟机实例列表中,点击要连接的 Managed Service for Apache Spark 虚拟机实例所在行中的 SSH。
此时会打开一个浏览器窗口,并显示节点上的主目录。
Connected, host fingerprint: ssh-rsa ... Linux cluster-1-m 3.16.0-0.bpo.4-amd64 ... ... user@cluster-1-m:~$
Google Cloud CLI
在本地终端窗口或通过 Cloud Shell 运行 gcloud compute ssh 命令,使用 SSH 连接到集群虚拟机节点。
gcloud compute ssh VM_NAME\ --zone=ZONE \ --project=PROJECT_ID
示例(主节点的默认名称是集群名称,后跟 -m 后缀):
gcloud compute ssh cluster-1-m \ --zone=us-central-1-a \ --project=my-project-id ... Linux cluster-1-m 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u6... ... user@cluster-1-m:~$