Spark bind on port 0. Attempting port 1 问题解决

Linux 下运行spark local bind on port 0. Attempting port 1 问题

2016-11-01 16:04:56 [org.apache.spark.util.Utils]-[WARN] - Service 'sparkDriver' could not bind on port 0. Attempting port 1.

2016-11-01 16:04:56 [org.apache.spark.SparkContext]-[ERROR] - Error initializing SparkContext.

java.net.BindException: Can't assign requested address: Service 'sparkDriver' failed after 16 retries! Consider explicitly setting the appropriate port for the service 'sparkDriver' (for example spark.ui.port for SparkUI) to an available port or increasing spark.port.maxRetries.


原因是找不到主机对应的ip地址,而不是端口绑定不正确引起的。


在hosts中加入如下代码


127.0.0.1 hostname


这里的用户名根据实际情况来写,这样,spark  local 就能找到本地对应的ip了,启动成功