1. # 1.安装Zookeeper
  2. # 2.修改spark-env.sh文件添加如下配置
  3. 注释掉如下内容:
  4. # SPARK_MASTER_HOST=hadoop102  
  5. /注释掉master节点的ip,因为高可用部署的master是变化的
  6. # SPARK_MASTER_PORT=7077
  7. # 添加上如下内容:
  8. export SPARK_DAEMON_JAVA_OPTS="-Dspark.deploy.recoveryMode=ZOOKEEPER -Dspark.deploy.zookeeper.url=hdp01,hdp02,hdp03 -Dspark.deploy.zookeeper.dir=/spark"
  9. #url这里填写zookeeper集群的ip zookeeper单机式只需要填一个即可
  10. # 参数说明
  11. 1recoveryMode,恢复模式(Master重新启动的模式)
  12.    有三种:ZookeeperFileSystemNone
  13. 2deploy.zookeeper.url,Zookeeper的服务器地址
  14. 3deploy.zookeeper.dir,保存集群元数据信息的文件、目录。
  15.   包括worker,Driver,Application.
  16.   注意:
  17. 在普通模式下启动集群,只需要在主机上执行start-all.sh就可以了。
  18. 在高可用模式下启动spark集群,先需要在任意一台节点上启动start-all.sh命令。然后在另外一台节点上单独启动master.
  1. ./bin/spark-submit \
  2. --class <main-class> \
  3. --master <master-url> \
  4. --deploy-mode <deploy-mode> \
  5. --conf <key>=<value> \
  6. ... # other options
  7. <application-jar> \
  8. [application-arguments]
  9. Some of the commonly used options are:
  10. --class: The entry point for your application (e.g. org.apache.spark.examples.SparkPi)
  11. --master: The master URL for the cluster (e.g. spark://23.195.26.187:7077)
  12. --deploy-mode: Whether to deploy your driver on the worker nodes () or locally as an external client () (default: ) clusterclientclient
  13. --conf: Arbitrary Spark configuration property in key=value format. For values that contain spaces wrap key=value in quotes (as shown). Multiple configurations should be passed as separate arguments. (e.g. --conf <key>=<value> --conf <key2>=<value2>)
  14. application-jar: Path to a bundled jar including your application and all dependencies. The URL must be globally visible inside of your cluster, for instance, an path or a path that is present on all nodes.hdfs://file://
  15. application-arguments: Arguments passed to the main method of your main class, if any
  1. #zookeeper集群配置spark地址
  2. spark://HOST1:PORT1,HOST2:PORT2

遇到的问题

zookeeper集群启动时,端口不可用。

问题描述:

-Service 'sparkMaster' could not bind on port 7077.Attempting port 7078.
.....

解决过程:

检查服务器端口,不存在端口占用的情况。
在spark-defaults.conf中添加spark.port.maxRetries 32 配置,增加端口尝试次数,并未解决问题。
尝试使用网上所说,配置SPARK_LOCAL_IP,仍未解决问题。(该配置,在spark集群下是有效的)
后尝试多次未果,将spark和zookeeper迁移至其他服务器,启动成功。

原因分析:

复盘分析,因为原来两台服务的IP经过了映射,但未修改hosts,Spark在zookeeper集群下启动时,会去寻找主机名。hosts主机名和IP配置的还是原IP不是映射后的IP,导致找不到对应的主机。

解决方案:

修改hosts 主机名IP配置即可