$ brew install hadoop
如果提示说未安装Java的话,说明你没有安装jdk,则按照它的命令提示,安装Java,然后再安装Hadoop。
安装完Hadoop后,需要配置一下才能成功安装[4]。(又是一项浩大的工程啊,路途中出现各种小问题,下面一一道来)
- 在目录
/usr/local/Cellar/hadoop/2.6.0/libexec/etc/hadoop
下找到hadoop-env.sh
文件中找到其中一行:(有木有盆友不造怎么进入目录啊。。就是打开Finder,然后找最上面工具栏有一个“前往”-->“前往文件夹”-->将路径复制进去即可) -
export HADOOP_OPTS="$HADOOP_OPTS Djava.net.preferIPv4Stack=true"
将其替换为:
-
export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true -Djava.security.krb5.realm= -Djava.security.krb5.kdc="
- 在目录
/usr/local/Cellar/hadoop/2.6.0/libexec/etc/hadoop
下找到core-site.xml,插入如下代码:
-
<configuration> <property> <name>hadoop.tmp.dir</name> <value>/usr/local/Cellar/hadoop/hdfs/tmp</value> <description>A base for other temporary directories.</description> </property> <property> <name>fs.default.name</name> <value>hdfs://localhost:9000</value> </property> </configuration>
- 在目录
/usr/local/Cellar/hadoop/2.6.0/libexec/etc/hadoop
下找到mapred-site.xml, 在其中添加: -
<configuration> <property> <name>mapred.job.tracker</name> <value>localhost:9010</value> </property> </configuration>
这里!!就是这里,我居然没有找到mapred-site.xml这个文件,只有一个mapred-site-template.xml文件,然后打不开,最后没办法只好从朋友那里copy了一个这样的文件,具体如下:(当然有该文件的朋友直接按照上面的修改就行了)
-
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <!-- Licensed 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. See accompanying LICENSE file. --> <!-- Put site-specific property overrides in this file. --> <configuration> <property> <name>mapred.job.tracker</name> <value>localhost:9010</value> </property> </configuration>
- 在目录
/usr/local/Cellar/hadoop/2.6.0/libexec/etc/hadoop
下找到hdfs-site.xml
-
<configuration> <property> <name>dfs.replication</name> <value>1</value> </property> </configuration>
- 在运行后台程序前, 必须格式化新安装的HDFS, 并通过创建存储目录和初始化元数据创新空的文件系统, 执行下面命令:
-
$ hdfs namenode -format #生成类似下面的字符串: ... #此书省略大部分 STARTUP_MSG: java = 1.6.0_65 ************************************************************ /************************************************************ SHUTDOWN_MSG: Shutting down NameNode at Andrew-liudeMacBook-Pro.local/192.168.1.100 ************************************************************/
- 启动后台程序:在
/usr/local/Cellar/hadoop/2.6.0/sbin
目录下, 执行如下命令 - ./start-all.sh