系統(tǒng)信息
- 操作系統(tǒng):Ubuntu 16.04.4 LTS 64bit
- Hadoop版本:Hadoop 2.7.5
- JDK版本:JDK 1.8.0_161 64bit
參考資料
一晶密、修改配置文件
關(guān)于JDK的安裝和環(huán)境變量的配置,此處不作贅述。
在Apache Hadoop官網(wǎng)Release頁面選擇好某個版本的binary版规哪,下載鸟蜡,解壓至/usr/local/
下
這里,我的hadoop目錄為/usr/local/hadoop-2.7.5
進入hadoop目錄豌注,首先新建文件夾tmp和hdfs伤塌,接著,在hdfs里面新建data和name兩個文件夾
mkdir tmp hdfs
mkdir -p hdfs/data hdfs/name
進入etc/hadoop
目錄下轧铁,找到以下幾個文件:
hadoop-env.sh每聪、core-site.xml、hdfs-site.xml齿风、mapred-site.xml.template药薯、yarn-site.xml
1.hadoop-env.sh
該文件默認有個
export JAVA_HOME=${JAVA_HOME}
將其改為你的JAVA_HOME路徑,例如
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
2.core-site.xml
修改為如下內(nèi)容:
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost</value>
<description>HDFS的URI救斑,文件系統(tǒng)://namenode標識:端口號</description>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/hadoop-2.7.5/tmp</value>
<description>namenode上本地的hadoop臨時文件夾</description>
</property>
</configuration>
3.hdfs-site.xml
修改為如下內(nèi)容:
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/usr/local/hadoop-2.7.5/hdfs/name</value>
<description>namenode上存儲hdfs名字空間元數(shù)據(jù) </description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/usr/local/hadoop-2.7.5/hdfs/data</value>
<description>datanode上數(shù)據(jù)塊的物理存儲位置</description>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
<description>副本個數(shù)果善,應小于datanode機器數(shù)量</description>
</property>
</configuration>
value的值要以file:
開頭,否則到后面格式化節(jié)點時會出現(xiàn)警告
18/03/04 11:32:16 WARN common.Util: Path /usr/local/hadoop-2.7.5/hdfs/name should be specified as a URI in configuration files. Please update hdfs configuration.
18/03/04 11:32:16 WARN common.Util: Path /usr/local/hadoop-2.7.5/hdfs/name should be specified as a URI in configuration files. Please update hdfs configuration.
4.mapred-site.xml.template
重命名為mapred-site.xml
修改為如下內(nèi)容:
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
5.yarn-site.xml
修改為如下內(nèi)容:
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>localhost</value>
</property>
</configuration>
二系谐、配置環(huán)境變量
引入以下變量巾陕,sorce
或者重啟電腦使變量生效
export HADOOP_HOME=/usr/local/hadoop-2.7.5
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
三、配置SSH
終端執(zhí)行
apt install ssh
cd ~/.ssh
ssh-keygen -t rsa # 按四個回車生纪他,成秘鑰文件
cp id_rsa.pub authorized_keys
ssh localhost # 第一次登錄
四鄙煤、嘗試啟動Hadoop
格式化HDFS文件系統(tǒng)hadoop namenode -format
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
18/03/04 12:12:22 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = lsn-ubuntu.lan/192.168.199.177
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 2.7.5
STARTUP_MSG: build = https://shv@git-wip-us.apache.org/repos/asf/hadoop.git -r 18065c2b6806ed4aa6a3187d77cbe21bb3dba075; compiled by 'kshvachk' on 2017-12-16T01:06Z
STARTUP_MSG: java = 1.8.0_161
************************************************************/
18/03/04 12:12:22 INFO namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT]
...
...
...
18/03/04 12:12:23 INFO namenode.FSImageFormatProtobuf: Image file /usr/local/hadoop-2.7.5/hdfs/name/current/fsimage.ckpt_0000000000000000000 of size 329 bytes saved in 0 seconds.
18/03/04 12:12:23 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
18/03/04 12:12:23 INFO util.ExitUtil: Exiting with status 0
18/03/04 12:12:23 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at lsn-ubuntu.lan/192.168.199.177
************************************************************/
進入/usr/local/hadoop-2.7.5/sbin/
依次執(zhí)行
./start-dfs.sh
./start-yarn.sh
查看是否成功的方法,終端輸入jps
茶袒,出現(xiàn)以下信息即成功梯刚。
22848 DataNode
23537 NodeManager
23233 ResourceManager
23684 Jps
23046 SecondaryNameNode
22697 NameNode
此時,在瀏覽器分別輸入localhost:8088
和localhost:50070
將會看到以下兩個頁面薪寓。
五亡资、遇到的小問題
1.配置文件中路徑不規(guī)范
在配置hdfs-site.xml
時出現(xiàn)的警告
2.NameNode或DataNode進程未成功啟動
Hadoop配置后沒有NameNode進程是怎么回事澜共? - 雷雷的回答 - 知乎
https://www.zhihu.com/question/31239901/answer/51129753
Hadoop配置后沒有NameNode進程是怎么回事? - Ansel Ting的回答 - 知乎
https://www.zhihu.com/question/31239901/answer/127300168