如何以client模式运行Spark Shell?master=yarn-client配置报错求助
Hey there! Let’s work through this issue together—running Spark Shell in yarn-client mode can throw tricky errors, but most of them boil down to configuration or resource mismatches. Here’s a breakdown of the right setup steps and fixes for the most common problems:
First, let’s confirm the correct launch command. For modern Spark versions, the explicit syntax for yarn-client mode is:
spark-shell --master yarn --deploy-mode client
(Note: The old yarn-client alias for --master still works in some older versions, but using --master yarn + --deploy-mode client is more reliable and aligns with Spark’s current best practices.)
Common Errors & Their Fixes
1. Connection Refused / YARN Resource Manager Unreachable
- First, verify YARN services are running on your cluster. On the master node, run:
If this fails, start YARN withyarn node -liststart-yarn.sh(or use your cluster’s service manager like systemd). - Ensure your
HADOOP_CONF_DIRenvironment variable points to your Hadoop config folder (whereyarn-site.xmlandcore-site.xmllive). Set it temporarily before launching Spark:export HADOOP_CONF_DIR=/path/to/your/hadoop/conf spark-shell --master yarn --deploy-mode client - Double-check
yarn.resourcemanager.addressinyarn-site.xmlmatches your Resource Manager’s actual hostname/IP.
2. Container Memory Limit Exceeded / Insufficient Memory
Spark often requests more memory than YARN allows by default. Adjust resource settings when launching:
spark-shell --master yarn --deploy-mode client \ --driver-memory 2g \ --executor-memory 4g \ --executor-cores 2
- Also, check YARN’s global memory limits in
yarn-site.xml:yarn.scheduler.maximum-allocation-mb: Max memory per containeryarn.nodemanager.resource.memory-mb: Total memory available on each worker node
3. Class Not Found / Dependency Issues
If you’re using custom JARs or external dependencies, make sure they’re accessible to both driver and executors:
- Use
--jarsto include local JARs:spark-shell --master yarn --deploy-mode client --jars /path/to/your/lib1.jar,/path/to/your/lib2.jar - For Maven-hosted dependencies, use
--packagesto pull them automatically:spark-shell --master yarn --deploy-mode client --packages com.example:your-dependency:1.0.0
4. Permission Denied (HDFS or Cluster Access)
- Ensure the user running Spark has write access to HDFS directories (like your user’s home directory
/user/your-username). Fix permissions with:hdfs dfs -chmod 755 /user/your-username - If your cluster uses Kerberos, run
kinitto get a valid authentication ticket before launching Spark Shell.
If you’re still stuck, share the exact error message you’re seeing—specific logs will help pinpoint the issue faster!
内容的提问来源于stack exchange,提问作者Suraj Karale

