importcom.google.api.gax.longrunning.OperationFuture;importcom.google.cloud.dataproc.v1.Cluster;importcom.google.cloud.dataproc.v1.ClusterConfig;importcom.google.cloud.dataproc.v1.ClusterControllerClient;importcom.google.cloud.dataproc.v1.ClusterControllerSettings;importcom.google.cloud.dataproc.v1.ClusterOperationMetadata;importcom.google.cloud.dataproc.v1.InstanceGroupConfig;importjava.io.IOException;importjava.util.concurrent.ExecutionException;publicclassCreateCluster{publicstaticvoidcreateCluster()throwsIOException,InterruptedException{// TODO(developer): Replace these variables before running the sample.StringprojectId="your-project-id";Stringregion="your-project-region";StringclusterName="your-cluster-name";createCluster(projectId,region,clusterName);}publicstaticvoidcreateCluster(StringprojectId,Stringregion,StringclusterName)throwsIOException,InterruptedException{StringmyEndpoint=String.format("%s-dataproc.googleapis.com:443",region);// Configure the settings for the cluster controller client.ClusterControllerSettingsclusterControllerSettings=ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build();// Create a cluster controller client with the configured settings. The client only needs to be// created once and can be reused for multiple requests. Using a try-with-resources// closes the client, but this can also be done manually with the .close() method.try(ClusterControllerClientclusterControllerClient=ClusterControllerClient.create(clusterControllerSettings)){// Configure the settings for our cluster.InstanceGroupConfigmasterConfig=InstanceGroupConfig.newBuilder().setMachineTypeUri("n1-standard-2").setNumInstances(1).build();InstanceGroupConfigworkerConfig=InstanceGroupConfig.newBuilder().setMachineTypeUri("n1-standard-2").setNumInstances(2).build();ClusterConfigclusterConfig=ClusterConfig.newBuilder().setMasterConfig(masterConfig).setWorkerConfig(workerConfig).build();// Create the cluster object with the desired cluster config.Clustercluster=Cluster.newBuilder().setClusterName(clusterName).setConfig(clusterConfig).build();// Create the Cloud Dataproc cluster.OperationFuture<Cluster,ClusterOperationMetadata>createClusterAsyncRequest=clusterControllerClient.createClusterAsync(projectId,region,cluster);Clusterresponse=createClusterAsyncRequest.get();// Print out a success message.System.out.printf("Cluster created successfully: %s",response.getClusterName());}catch(ExecutionExceptione){System.err.println(String.format("Error executing createCluster: %s ",e.getMessage()));}}}
constdataproc=require('@google-cloud/dataproc');// TODO(developer): Uncomment and set the following variables// projectId = 'YOUR_PROJECT_ID'// region = 'YOUR_CLUSTER_REGION'// clusterName = 'YOUR_CLUSTER_NAME'// Create a client with the endpoint set to the desired cluster regionconstclient=newdataproc.v1.ClusterControllerClient({apiEndpoint:`${region}-dataproc.googleapis.com`,projectId:projectId,});asyncfunctioncreateCluster(){// Create the cluster configconstrequest={projectId:projectId,region:region,cluster:{clusterName:clusterName,config:{masterConfig:{numInstances:1,machineTypeUri:'n1-standard-2',},workerConfig:{numInstances:2,machineTypeUri:'n1-standard-2',},},},};// Create the clusterconst[operation]=awaitclient.createCluster(request);const[response]=awaitoperation.promise();// Output a success messageconsole.log(`Cluster created successfully: ${response.clusterName}`);
fromgoogle.cloudimportdataproc_v1asdataprocdefcreate_cluster(project_id,region,cluster_name):"""This sample walks a user through creating a Cloud Dataproc cluster using the Python client library. Args: project_id (string): Project to use for creating resources. region (string): Region where the resources should live. cluster_name (string): Name to use for creating a cluster. """# Create a client with the endpoint set to the desired cluster region.cluster_client=dataproc.ClusterControllerClient(client_options={"api_endpoint":f"{region}-dataproc.googleapis.com:443"})# Create the cluster config.cluster={"project_id":project_id,"cluster_name":cluster_name,"config":{"master_config":{"num_instances":1,"machine_type_uri":"n1-standard-2"},"worker_config":{"num_instances":2,"machine_type_uri":"n1-standard-2"},},}# Create the cluster.operation=cluster_client.create_cluster(request={"project_id":project_id,"region":region,"cluster":cluster})result=operation.result()# Output a success message.print(f"Cluster created successfully: {result.cluster_name}")
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-25。"],[[["Dataproc restricts the creation of clusters with image versions older than 1.3.95, 1.4.77, 1.5.53, and 2.0.27 to mitigate Apache Log4j security vulnerabilities, and it also blocks clusters on Dataproc image versions 0.x, 1.0.x, 1.1.x, and 1.2.x."],["It's recommended to utilize the latest sub-minor image versions for Dataproc clusters, such as 2.0.29, 1.5.55, and 1.4.79 or later, which include log4j.2.17.1, for enhanced security."],["Creating a Dataproc cluster requires a name that starts with a lowercase letter, up to 51 lowercase letters, numbers, and hyphens, and must not end with a hyphen, as well as specifying a Compute Engine region for resource isolation."],["The most common methods for creating a cluster are using `gcloud` commands, by importing a YAML configuration file, or by using the Dataproc API REST requests; the Google Cloud Console is also an option for cluster creation."],["Full internal IP networking cross connectivity is required for master and worker VMs in a Dataproc cluster, which is provided by the `default` VPC network."]]],[]]