./spark-shell 无法正确启动(spark1.6.1-bin.hadoop2.6 版本)

Posted

技术标签:

【中文标题】./spark-shell 无法正确启动(spark1.6.1-bin.hadoop2.6 版本)【英文标题】:./spark-shell doesn't start correctly (spark1.6.1-bin.hadoop2.6 version) 【发布时间】:2016-03-28 23:55:04 【问题描述】:

我安装了这个 spark 版本:spark-1.6.1-bin-hadoop2.6.tgz。

现在,当我使用 ./spark-shell 命令启动 spark 时,我遇到了这个问题(它显示了很多错误行,所以我只放了一些看起来很重要的)

     Cleanup action completed
        16/03/27 00:19:35 ERROR Schema: Failed initialising database.
        Failed to create database 'metastore_db', see the next exception for details.
        org.datanucleus.exceptions.NucleusDataStoreException: Failed to create database 'metastore_db', see the next exception for details.
            at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.getConnection(ConnectionFactoryImpl.java:516)

        Caused by: java.sql.SQLException: Directory /usr/local/spark-1.6.1-bin-hadoop2.6/bin/metastore_db cannot be created.
            org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
            ... 128 more
        Caused by: ERROR XBM0H: Directory /usr/local/spark-1.6.1-bin-hadoop2.6/bin/metastore_db cannot be created.


        Nested Throwables StackTrace:
        java.sql.SQLException: Failed to create database 'metastore_db', see the next exception for details.
  org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
            ... 128 more
        Caused by: ERROR XBM0H: Directory /usr/local/spark-1.6.1-bin-hadoop2.6/bin/metastore_db cannot be created.
            at org.apache.derby.iapi.error.StandardException.newException


        Caused by: java.sql.SQLException: Directory /usr/local/spark-1.6.1-bin-hadoop2.6/bin/metastore_db cannot be created.
            at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
            at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
            at 
            ... 128 more

        <console>:16: error: not found: value sqlContext
                 import sqlContext.implicits._
                        ^
        <console>:16: error: not found: value sqlContext
                 import sqlContext.sql
                        ^

        scala> 

我尝试了一些配置来解决这个问题,我在其他问题中搜索了关于 value sqlContext not found 问题,例如:

/etc/hosts 文件:

127.0.0.1  hadoophost localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    10.2.0.15 hadoophost

echo $HOSTNAME 返回:

hadoophost

.bashrc 文件包含:

export SPARK_LOCAL_IP=127.0.0.1

但是不起作用,您能否提供一些帮助以尝试了解 spark 无法正确启动的原因?

hive-default.xml.template

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
--><configuration>
  <!-- WARNING!!! This file is auto generated for documentation purposes ONLY! -->
  <!-- WARNING!!! Any changes you make to this file will be ignored by Hive.   -->
  <!-- WARNING!!! You must make your changes in hive-site.xml instead.         -->

在主文件夹中我遇到了同样的问题:

[hadoopadmin@hadoop home]$ pwd
/home
[hadoopadmin@hadoop home]$ 

文件夹权限:

[hadoopdadmin@hadoop spark-1.6.1-bin-hadoop2.6]$ ls -la
total 1416
drwxr-xr-x. 12 hadoop hadoop    4096 .
drwxr-xr-x. 16 root   root      4096  ..
drwxr-xr-x.  2 hadoop hadoop    4096  bin
-rw-r--r--.  1 hadoop hadoop 1343562  CHANGES.txt
drwxr-xr-x.  2 hadoop hadoop    4096  conf
drwxr-xr-x.  3 hadoop hadoop    4096  data
drwxr-xr-x.  3 hadoop hadoop    4096  ec2
drwxr-xr-x.  3 hadoop hadoop    4096  examples
drwxr-xr-x.  2 hadoop hadoop    4096  lib
-rw-r--r--.  1 hadoop hadoop   17352  LICENSE
drwxr-xr-x.  2 hadoop hadoop    4096  licenses
-rw-r--r--.  1 hadoop hadoop   23529  NOTICE
drwxr-xr-x.  6 hadoop hadoop    4096  python
drwxr-xr-x.  3 hadoop hadoop    4096  R
-rw-r--r--.  1 hadoop hadoop    3359  README.md
-rw-r--r--.  1 hadoop hadoop     120  RELEASE
drwxr-xr-x.  2 hadoop hadoop    4096  sbin

【问题讨论】:

我遇到了类似的问题,我无法在本地运行 spark 1.6,你是如何解决这个问题的? 【参考方案1】:

显然您没有在该目录中写入的权限,我建议您在您的HOME 中运行./spark-shell(您可能希望将该命令添加到您的PATH),或者在任何其他可访问的目录中并且可由您的用户写入。

这也可能与您有关Notebooks together with Spark

【讨论】:

感谢您的回答。但是我遇到了同样的错误! @codin 显示终端的输出,你的当前目录和目录的权限【参考方案2】:

您正在使用基于 hive 支持构建的 spark。

根据您以后要使用 spark-shell 或在 spark 作业中执行的操作,有两种可能的解决方案 -

    您想在您的 hadoop+hive 安装中访问 hive 表。 您应该将 hive-site.xml 放在 spark 安装的 conf 子目录中。从现有的 hive 安装中找到 hive-site.xml。例如,在我的 cloudera VM 中,hive-site.xml 位于 /usr/lib/hive/conf。执行此步骤后启动 spark-shell 应该会成功连接到现有的 hive 元存储,并且不会尝试在当前工作目录中创建临时 .metastore 数据库。 您不想在 hadoop+hive 安装中访问 hive 表。 如果您不关心连接到 hive 表,那么您可以遵循 Alberto 的解决方案。修复启动 spark-shell 的目录中的权限问题。确保您可以在该目录中创建目录/文件。

希望这会有所帮助。

【讨论】:

感谢您的回答。我尝试你的第一点。但是错误仍然存​​在。我使用 hive-1.2.1 并复制 hive-default.xml.tepmplate 并且问题仍然存在 icual.. @codin 请查找 hive-site.xml。 Spark 将在其 conf 目录中查找 hive-site.XML。您可以尝试在 spark 的 conf 目录中将 hive-default.XML 重命名为 hive-site.xml。 再次感谢您的回答。但该文件不会出现在 hive 文件夹中。而且我没有对此进行任何配置。要安装和配置 hive,我只需提取到本地 foder 并在 .bashrc 中配置 hive 前缀。 如果您只是在您的开发环境中进行 POC,我建议您使用快速入门 VM,因为获取 hadoop+hive 等可以真正参与其中。您仍然可以像 (1.6) 一样使用自己的 spark 版本,如果您已正确配置 hive,则应该有 hive-site.xml 快速入门 VM 将帮助您学习,因为它具有所有配置的完整工作设置,您可以将其作为参考和推理。当然,手动完成所有工作是学习所有内部知识的好方法。对于 hadoop 的初学者来说,学习所有技术、它们的配置,然后使用 spark 或 map-reduce 进行实际编程是令人生畏的。建议至少使用快速入门 VM 来排除任何错误配置,以便专注于学习实际的分布式计算。

以上是关于./spark-shell 无法正确启动(spark1.6.1-bin.hadoop2.6 版本)的主要内容,如果未能解决你的问题,请参考以下文章

使用 spark-shell 时的番石榴版本

java 怎么提交应用程序到spark standalone集群中去运行

在运行 spark-shell 之前编辑 spark-env.sh 的正确方法是啥?

spark-shell启动报错如下。请问该如何解决。多谢帮助!

Spark-Shell的启动与运行

Spark-Shell的启动与运行