本文將探討 Managed Service for Apache Spark 最佳做法,協助您在生產環境的 Managed Service for Apache Spark 叢集上,執行可靠、有效率且有洞察力的資料處理工作。
指定叢集映像檔版本
Managed Service for Apache Spark 會使用映像檔版本,將作業系統、大數據元件和 Google Cloud 連接器整合成一個可於叢集部署的套件。如果您在建立叢集時未指定映像檔版本,Managed Service for Apache Spark 預設會使用最新的穩定版映像檔。
在正式版環境中,請將叢集與特定 major.minor Managed Service for Apache Spark 映像檔版本建立關聯,如下列 gcloud CLI 指令所示。
gcloud dataproc clusters create CLUSTER_NAME \ --region=region \ --image-version=2.0
Dataproc 會將 major.minor 版本解析為最新的子次要版本 (2.0 會解析為 2.0.x)。注意:如需依賴特定子次要版本建立叢集,可以指定該版本,例如 --image-version=2.0.x。詳情請參閱「版本管理機制」。
Managed Service for Apache Spark 預覽版映像檔版本
Managed Service for Apache Spark 映像檔的新次要版本會在標準次要映像檔版本軌中發布,但您可先使用 preview 版本。使用預覽映像檔測試及驗證工作,確認新次要映像檔版本是否適用於生產環境,再採用標準次要映像檔版本。詳情請參閱 Managed Service for Apache Spark 版本管理。
視需要使用自訂圖片
如果需要將依附元件新增至叢集 (例如原生 Python 程式庫,或是安全強化或防毒軟體),請從目標次要映像檔版本軌中的最新映像檔建立自訂映像檔。這樣一來,使用自訂映像檔建立叢集時,就能滿足依附元件需求。如要重建自訂映像檔來更新依附元件需求,請使用次要映像檔軌中最新的可用副次要映像檔版本。
將工作提交至 Managed Service for Apache Spark
使用 gcloud CLI 或 Google Cloud 控制台,透過 jobs.submit 呼叫,將工作提交至 Managed Service for Apache Spark。授予Managed Service for Apache Spark 角色,設定工作和叢集權限。使用自訂角色將叢集存取權與工作提交權限分開。
將工作提交至 Managed Service for Apache Spark 的優點:
- 不需要複雜的網路設定,API 隨時可供存取
- 輕鬆管理 IAM 權限和角色
- 輕鬆追蹤工作狀態,不必使用 Managed Service for Apache Spark 工作中繼資料,以免結果變得複雜。
在實際運作環境中,請以固定的次要映像檔版本 (例如 --image-version=2.0) 執行僅依附於叢集層級依附元件的工作。提交工作時,請將依附元件與工作一併提交。將 uber jar 提交至 Spark 或 MapReduce 是常見做法。
- 舉例來說,如果工作 JAR 檔案依附於
args4j和spark-sql,其中args4j是工作專屬的依附元件,而spark-sql是叢集層級的依附元件,請將args4j併入工作的大型 JAR 檔案。
控管初始化動作位置
初始化動作可讓您在建立 Managed Service for Apache Spark 叢集時,自動執行指令碼或安裝元件 (如需常見的 Managed Service for Apache Spark 初始化動作,請參閱 dataproc-initialization-actions GitHub 存放區)。在生產環境中使用叢集初始化動作時,請將初始化指令碼複製到 Cloud Storage,而非從公開存放區取得。這麼做可避免執行他人修改過的初始化指令碼。
監控 Managed Service for Apache Spark 版本資訊
Managed Service for Apache Spark 會定期發布新的次要次要版本映像檔。請查看或訂閱 Managed Service for Apache Spark 版本資訊,瞭解最新的 Managed Service for Apache Spark 映像檔版本,以及其他公告、變更和修正。
查看暫存 bucket,調查失敗原因
查看叢集的暫存值區,調查叢集和工作錯誤訊息。通常,暫存值區的 Cloud Storage 位置會顯示在錯誤訊息中,如下列範例錯誤訊息的粗體文字所示:
ERROR: (gcloud.dataproc.clusters.create) Operation ... failed: ... - Initialization action failed. Failed action ... see output in: gs://dataproc-<BUCKETID>-us-central1/google-cloud-dataproc-metainfo/CLUSTERID/<CLUSTER_ID>\dataproc-initialization-script-0_output
使用 gcloud CLI 查看暫存 bucket 內容:
輸出內容範例:gcloud storage cat gs://STAGING_BUCKET
+ readonly RANGER_VERSION=1.2.0 ... Ranger admin password not set. Please use metadata flag - default-password
取得支援
Google Cloud 支援正式版 OSS 工作負載,並透過支援層級協助您達成業務服務水準協議。此外, Google Cloud 顧問服務可為團隊的生產部署提供最佳做法指引。
瞭解詳情
請參閱 Google Cloud 這篇網誌文章,瞭解 Managed Service for Apache Spark 最佳做法指南。
在 YouTube 上觀看「Democratizing Managed Service for Apache Spark」。