Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Esecuzione di un'istanza di blocchi note gestiti su un cluster Dataproc
Questa pagina mostra come eseguire il file blocco note di un'istanza di blocchi note gestiti su un cluster Dataproc.
Prima di iniziare
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Per assicurarti che il account di servizio disponga delle autorizzazioni
necessarie per eseguire un file notebook su un cluster Dataproc Serverless,
chiedi all'amministratore di concedere al account di servizio i
seguenti ruoli IAM:
Questi ruoli predefiniti contengono
le autorizzazioni necessarie per eseguire un file notebook su un cluster Dataproc Serverless. Per vedere quali sono esattamente le autorizzazioni richieste, espandi la sezione Autorizzazioni obbligatorie:
Autorizzazioni obbligatorie
Per eseguire un file notebook su un cluster Dataproc Serverless sono necessarie le seguenti autorizzazioni:
dataproc.agents.create
dataproc.agents.delete
dataproc.agents.get
dataproc.agents.update
dataproc.tasks.lease
dataproc.tasks.listInvalidatedLeases
dataproc.tasks.reportStatus
dataproc.clusters.use
L'amministratore potrebbe anche essere in grado di concedere al account di servizio queste autorizzazioni tramite ruoli personalizzati o altri ruoli predefiniti.
Crea un cluster Dataproc
Per eseguire il file del blocco note di un'istanza di blocchi note gestiti
in un cluster Dataproc, il cluster deve soddisfare i seguenti
criteri:
Il gateway dei componenti del cluster deve essere abilitato.
Fai clic su Apri JupyterLab accanto al nome dell'istanza di blocchi note gestiti.
Esegui un file notebook nel cluster Dataproc
Puoi eseguire un file notebook nel cluster Dataproc
da qualsiasi istanza di blocchi note gestiti nello stesso progetto e
nella stessa regione.
Esegui un nuovo file notebook
Nell'interfaccia JupyterLab dell'istanza di notebook gestiti,
seleziona File >
Nuovo > Notebook.
I kernel disponibili del cluster Dataproc vengono visualizzati nel menu Seleziona kernel. Seleziona il kernel che vuoi utilizzare
e poi fai clic su Seleziona.
Si apre il nuovo file del notebook.
Aggiungi il codice al nuovo file del notebook ed eseguilo.
Per modificare il kernel che vuoi utilizzare
dopo aver creato il file del notebook, consulta la sezione seguente.
Esegui un file notebook esistente
Nell'interfaccia JupyterLab dell'istanza di blocchi note gestiti,
fai clic sul pulsante
folderEsplora file,
vai al file del notebook che vuoi eseguire e aprilo.
Per aprire la finestra di dialogo Seleziona kernel, fai clic sul nome del kernel del file del notebook, ad esempio Python (locale).
Per selezionare un kernel dal cluster Dataproc,
seleziona un nome del kernel che includa il nome del cluster alla fine.
Ad esempio, un kernel PySpark su un cluster Dataproc
denominato mycluster viene chiamato PySpark su mycluster.
Fai clic su Seleziona per chiudere la finestra di dialogo.
Ora puoi eseguire il codice del file del notebook sul cluster Dataproc.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema รจ stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-02 UTC."],[],[],null,["# Run a managed notebooks instance on a Dataproc cluster\n======================================================\n\n\n| Vertex AI Workbench managed notebooks is\n| [deprecated](/vertex-ai/docs/deprecations). On\n| April 14, 2025, support for\n| managed notebooks will end and the ability to create managed notebooks instances\n| will be removed. Existing instances will continue to function\n| but patches, updates, and upgrades won't be available. To continue using\n| Vertex AI Workbench, we recommend that you\n| [migrate\n| your managed notebooks instances to Vertex AI Workbench instances](/vertex-ai/docs/workbench/managed/migrate-to-instances).\n\n\u003cbr /\u003e\n\nThis page shows you how to run a managed notebooks instance's\nnotebook file on a Dataproc cluster.\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Notebooks and Dataproc APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=notebooks.googleapis.com,dataproc)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Notebooks and Dataproc APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=notebooks.googleapis.com,dataproc)\n\n1. If you haven't already, [create\n a managed notebooks instance](/vertex-ai/docs/workbench/managed/create-instance#create).\n\n### Required roles\n\n\nTo ensure that the service account has the necessary\npermissions to run a notebook file on a Dataproc Serverless cluster,\n\nask your administrator to grant the service account the\nfollowing IAM roles:\n\n| **Important:** You must grant these roles to the service account, *not* to your user account. Failure to grant the roles to the correct principal might result in permission errors.\n\n- [Dataproc Worker](/iam/docs/roles-permissions/dataproc#dataproc.worker) (`roles/dataproc.worker`) on your project\n- [Dataproc Editor](/iam/docs/roles-permissions/dataproc#dataproc.editor) (`roles/dataproc.editor`) on the cluster for the `dataproc.clusters.use` permission\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nThese predefined roles contain\n\nthe permissions required to run a notebook file on a Dataproc Serverless cluster. To see the exact permissions that are\nrequired, expand the **Required permissions** section:\n\n\n#### Required permissions\n\nThe following permissions are required to run a notebook file on a Dataproc Serverless cluster:\n\n- ` dataproc.agents.create `\n- ` dataproc.agents.delete `\n- ` dataproc.agents.get `\n- ` dataproc.agents.update `\n- ` dataproc.tasks.lease `\n- ` dataproc.tasks.listInvalidatedLeases `\n- ` dataproc.tasks.reportStatus `\n- ` dataproc.clusters.use`\n\n\nYour administrator might also be able to give the service account\nthese permissions\nwith [custom roles](/iam/docs/creating-custom-roles) or\nother [predefined roles](/iam/docs/roles-overview#predefined).\n\nCreate a Dataproc cluster\n-------------------------\n\nTo run a managed notebooks instance's notebook file\nin a Dataproc cluster, your cluster must meet the following\ncriteria:\n\n- The cluster's component gateway must be enabled.\n\n- The cluster must have\n the [Jupyter component](/dataproc/docs/concepts/components/jupyter).\n\n- The cluster must be in the same region as\n your managed notebooks instance.\n\nTo create your Dataproc cluster,\nenter the following command in either\n[Cloud Shell](https://console.cloud.google.com?cloudshell=true) or another\nenvironment where the [Google Cloud CLI](/sdk/docs) is installed. \n\n```bash\ngcloud dataproc clusters create CLUSTER_NAME\\\n --region=REGION \\\n --enable-component-gateway \\\n --optional-components=JUPYTER\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the Google Cloud location of\n your managed notebooks instance\n\n- \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: the name of your new\n cluster\n\nAfter a few minutes, your Dataproc cluster\nis available for use. [Learn more about creating Dataproc\nclusters](/dataproc/docs/guides/create-cluster).\n\nOpen JupyterLab\n---------------\n\n1. If you haven't already,\n [create\n a managed notebooks instance](/vertex-ai/docs/workbench/managed/create-instance#create) in the same region\n where your Dataproc cluster is.\n\n2. In the Google Cloud console, go to the **Managed notebooks** page.\n\n [Go to Managed notebooks](https://console.cloud.google.com/vertex-ai/workbench/managed)\n3. Next to your managed notebooks instance's name,\n click **Open JupyterLab**.\n\nRun a notebook file in your Dataproc cluster\n--------------------------------------------\n\nYou can run a notebook file in your Dataproc cluster\nfrom any managed notebooks instance in the same project and\nregion.\n\n### Run a new notebook file\n\n1. In your managed notebooks instance's JupyterLab interface,\n select **File \\\u003e\n New \\\u003e Notebook**.\n\n2. Your Dataproc cluster's available kernels appear in\n the **Select kernel** menu. Select the kernel that you want to use,\n and then click **Select**.\n\n Your new notebook file opens.\n3. Add code to your new notebook file, and run the code.\n\nTo change the kernel that you want to use\nafter you've created your notebook file, see the following section.\n\n### Run an existing notebook file\n\n1. In your managed notebooks instance's JupyterLab interface,\n click the\n folder **File Browser** button,\n navigate to the notebook file that you want to run, and open it.\n\n2. To open the **Select kernel** dialog, click the kernel name of your notebook\n file, for example: **Python (Local)**.\n\n3. To select a kernel from your Dataproc cluster,\n select a kernel name that includes your cluster name at the end of it.\n For example, a PySpark kernel on a Dataproc cluster\n named `mycluster` is named **PySpark on mycluster**.\n\n4. Click **Select** to close the dialog.\n\n You can now run your notebook file's code\n on the Dataproc cluster.\n\nWhat's next\n-----------\n\n- Learn more about [Dataproc](/dataproc/docs/concepts/overview)."]]