docker composeを使ってApache Sparkを構築する

docker composeを使ってApache Sparkを構築する

docker composeを使ってオープンソースの分散処理のフレームワークであるApache Sparkを構築するまでの手順を記述してます。

環境

  • OS CentOS Linux release 7.8.2003 (Core)
  • docker 19.03.12
  • docker-compose 1.25.4

docker-compose.ymlダウンロード

gitよりcloneします。

git clone https://github.com/Semantive/docker-spark.git

docker-compose.ymlの内容は以下となります。

master:
  image: semantive/spark
  command: bin/spark-class org.apache.spark.deploy.master.Master -h master
  hostname: master
  environment:
    MASTER: spark://master:7077
    SPARK_CONF_DIR: /conf
    SPARK_PUBLIC_DNS: localhost
  ports:
    - 4040:4040
    - 6066:6066
    - 7077:7077
    - 8080:8080
  volumes:
    - ./data:/tmp/data

worker1:
  image: semantive/spark
  command: bin/spark-class org.apache.spark.deploy.worker.Worker spark://master:7077
  hostname: worker1
  environment:
    SPARK_CONF_DIR: /conf
    SPARK_WORKER_CORES: 4
    SPARK_WORKER_MEMORY: 2g
    SPARK_WORKER_PORT: 8881
    SPARK_WORKER_WEBUI_PORT: 8081
    SPARK_PUBLIC_DNS: localhost
  links:
    - master
  ports:
    - 8081:8081
  volumes:
    - ./data:/tmp/data

worker2:
  image: semantive/spark
  command: bin/spark-class org.apache.spark.deploy.worker.Worker spark://master:7077
  hostname: worker2
  environment:
    SPARK_CONF_DIR: /conf
    SPARK_WORKER_CORES: 4
    SPARK_WORKER_MEMORY: 2g
    SPARK_WORKER_PORT: 8882
    SPARK_WORKER_WEBUI_PORT: 8082
    SPARK_PUBLIC_DNS: localhost
  links:
    - master
  ports:
    - 8082:8082
  volumes:
    - ./data:/tmp/data

実行

firewallを先に設定しておきます。

sudo firewall-cmd --add-port=8080/tcp --zone=public --permanent
sudo firewall-cmd --reload

実行します。

docker-compose up -d

Apache Spark起動

ブラウザから http://プライベートIP or サーバーアドレス:8080 にアクセスします。

上記の画面が表示されていれば構築は完了です。