# 1.安装Zookeeper
# 2.修改spark-env.sh文件添加如下配置
注释掉如下内容:
# SPARK_MASTER_HOST=hadoop102
/注释掉master节点的ip,因为高可用部署的master是变化的
# SPARK_MASTER_PORT=7077
# 添加上如下内容:
export SPARK_DAEMON_JAVA_OPTS="-Dspark.deploy.recoveryMode=ZOOKEEPER -Dspark.deploy.zookeeper.url=hdp01,hdp02,hdp03 -Dspark.deploy.zookeeper.dir=/spark"
#url这里填写zookeeper集群的ip zookeeper单机式只需要填一个即可
# 参数说明
(1)recoveryMode,恢复模式(Master重新启动的模式)
有三种:Zookeeper、FileSystem、None
(2)deploy.zookeeper.url,Zookeeper的服务器地址
(3)deploy.zookeeper.dir,保存集群元数据信息的文件、目录。
包括worker,Driver,Application.
注意:
在普通模式下启动集群,只需要在主机上执行start-all.sh就可以了。
在高可用模式下启动spark集群,先需要在任意一台节点上启动start-all.sh命令。然后在另外一台节点上单独启动master.
./bin/spark-submit \
--class <main-class> \
--master <master-url> \
--deploy-mode <deploy-mode> \
--conf <key>=<value> \
... # other options
<application-jar> \
[application-arguments]
Some of the commonly used options are:
--class: The entry point for your application (e.g. org.apache.spark.examples.SparkPi)
--master: The master URL for the cluster (e.g. spark://23.195.26.187:7077)
--deploy-mode: Whether to deploy your driver on the worker nodes () or locally as an external client () (default: ) † clusterclientclient
--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>)
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://
application-arguments: Arguments passed to the main method of your main class, if any
#zookeeper集群配置spark地址
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配置即可