http://www.open-open.com/lib/view/open1435761287778.html html
整體思路,準備主從服務器,配置主服務器能夠無密碼SSH登陸從服務器,解壓安裝JDK,解壓安裝Hadoop,配置hdfs、mapreduce等主從關係。
一、環境,3臺CentOS7,64位,Hadoop2.7須要64位Linux,CentOS7 Minimal的ISO文件只有600M,操做系統十幾分鍾就能夠安裝完成,
Master 192.168.0.182
Slave1 192.168.0.183
Slave2 192.168.0.184
二、SSH免密碼登陸,由於Hadoop須要經過SSH登陸到各個節點進行操做,我用的是root用戶,每臺服務器都生成公鑰,再合併到authorized_keys
(1)CentOS默認沒有啓動ssh無密登陸,去掉/etc/ssh/sshd_config其中2行的註釋,每臺服務器都要設置,
#RSAAuthentication yes
#PubkeyAuthentication yes
(2)輸入命令,ssh-keygen -t rsa,生成key,都不輸入密碼,一直回車,/root就會生成.ssh文件夾,每臺服務器都要設置,
(3)合併公鑰到authorized_keys文件,在Master服務器,進入/root/.ssh目錄,經過SSH命令合併,
cat id_rsa.pub>> authorized_keys
ssh root@192.168.0.183 cat ~/.ssh/id_rsa.pub>> authorized_keys
ssh root@192.168.0.184 cat ~/.ssh/id_rsa.pub>> authorized_keys
(4)把Master服務器的authorized_keys、known_hosts複製到Slave服務器的/root/.ssh目錄
(5)完成,ssh root@192.168.0.18三、ssh root@192.168.0.184就不須要輸入密碼了
三、安裝JDK,Hadoop2.7須要JDK7,因爲個人CentOS是最小化安裝,因此沒有OpenJDK,直接解壓下載的JDK並配置變量便可
(1)下載「jdk-7u79-linux-x64.gz」,放到/home/java目錄下
(2)解壓,輸入命令,tar -zxvf jdk-7u79-linux-x64.gz
(3)編輯/etc/profile
export JAVA_HOME=/home/java/jdk1.7.0_79
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
(4)使配置生效,輸入命令,source /etc/profile
(5)輸入命令,java -version,完成
四、安裝Hadoop2.7,只在Master服務器解壓,再複製到Slave服務器
(1)下載「hadoop-2.7.0.tar.gz」,放到/home/hadoop目錄下
(2)解壓,輸入命令,tar -xzvf hadoop-2.7.0.tar.gz
(3)在/home/hadoop目錄下建立數據存放的文件夾,tmp、dfs、dfs/data、dfs/name
五、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://192.168.0.182:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/home/hadoop/tmp</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131702</value>
</property>
</configuration>
六、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/hadoop/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/hadoop/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>192.168.0.182:9001</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
七、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>192.168.0.182:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>192.168.0.182:19888</value>
</property>
</configuration>
八、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>192.168.0.182:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>192.168.0.182:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>192.168.0.182:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>192.168.0.182:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>192.168.0.182:8088</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>768</value>
</property>
</configuration>
九、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下hadoop-env.sh、yarn-env.sh的JAVA_HOME,不設置的話,啓動不了,
export JAVA_HOME=/home/java/jdk1.7.0_79
十、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的slaves,刪除默認的localhost,增長2個從節點,
192.168.0.183
192.168.0.184
十一、將配置好的Hadoop複製到各個節點對應位置上,經過scp傳送,
scp -r /home/hadoop 192.168.0.183:/home/
scp -r /home/hadoop 192.168.0.184:/home/
十二、在Master服務器啓動hadoop,從節點會自動啓動,進入/home/hadoop/hadoop-2.7.0目錄
(1)初始化,輸入命令,bin/hdfs namenode -format
(2)所有啓動sbin/start-all.sh,也能夠分開sbin/start-dfs.sh、sbin/start-yarn.sh
(3)中止的話,輸入命令,sbin/stop-all.sh
(4)輸入命令,jps,能夠看到相關信息
1三、Web訪問,要先開放端口或者直接關閉防火牆
(1)輸入命令,systemctl stop firewalld.service
(2)瀏覽器打開http://192.168.0.182:8088/
(3)瀏覽器打開http://192.168.0.182:50070/
1四、安裝完成。這只是大數據應用的開始,以後的工做就是,結合本身的狀況,編寫程序調用Hadoop的接口,發揮hdfs、mapreduce的做用。java
15 hadoop啓動腳本node
#####linux
#!/bin/bashweb
#express
# hadoop - this script starts and stops the hadoop-server daemonapache
#瀏覽器
# chkconfig: - 80 12bash
# description: hadoop is a persistent key-value database服務器
# processname: hadoop
# config: /usr/local/hadoop/etc
# pidfile:
source /etc/init.d/functions
RETVAL=0
start() {
/usr/local/hadoop/sbin/start-all.sh
}
stop() {
/usr/local/hadoop/sbin/stop-all.sh
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac
exit $RETVAL
#####
測試:
1 建立目錄
hdfs dfs -mkdir /user hdfs dfs -mkdir /user/bobo
2 上傳文件
hdfs dfs -put ab.txt /user/bobo
3 查看目錄列表
hdfs dfs -ls /user
4 下載文件
hdfs dfs -get /user/bobo/ab.txt ab.txt
5 刪除文件
hdfs dfs -rm /user/bobo/ab.txt ab.txt
6 刪除目錄
hdfs dfs -rmrf /user
hdfs dfs
Usage: hadoop fs [generic options]
[-appendToFile <localsrc> ... <dst>]
[-cat [-ignoreCrc] <src> ...]
[-checksum <src> ...]
[-chgrp [-R] GROUP PATH...]
[-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
[-chown [-R] [OWNER][:[GROUP]] PATH...]
[-copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst>]
[-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-count [-q] [-h] <path> ...]
[-cp [-f] [-p | -p[topax]] <src> ... <dst>]
[-createSnapshot <snapshotDir> [<snapshotName>]]
[-deleteSnapshot <snapshotDir> <snapshotName>]
[-df [-h] [<path> ...]]
[-du [-s] [-h] <path> ...]
[-expunge]
[-find <path> ... <expression> ...]
[-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-getfacl [-R] <path>]
[-getfattr [-R] {-n name | -d} [-e en] <path>]
[-getmerge [-nl] <src> <localdst>]
[-help [cmd ...]]
[-ls [-d] [-h] [-R] [<path> ...]]
[-mkdir [-p] <path> ...]
[-moveFromLocal <localsrc> ... <dst>]
[-moveToLocal <src> <localdst>]
[-mv <src> ... <dst>]
[-put [-f] [-p] [-l] <localsrc> ... <dst>]
[-renameSnapshot <snapshotDir> <oldName> <newName>]
[-rm [-f] [-r|-R] [-skipTrash] <src> ...]
[-rmdir [--ignore-fail-on-non-empty] <dir> ...]
[-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]]
[-setfattr {-n name [-v value] | -x name} <path>]
[-setrep [-R] [-w] <rep> <path> ...]
[-stat [format] <path> ...]
[-tail [-f] <file>]
[-test -[defsz] <path>]
[-text [-ignoreCrc] <src> ...]
[-touchz <path> ...]
[-truncate [-w] <length> <path> ...]
[-usage [cmd ...]]
Generic options supported are
-conf <configuration file> specify an application configuration file
-D <property=value> use value for given property
-fs <local|namenode:port> specify a namenode
-jt <local|resourcemanager:port> specify a ResourceManager
-files <comma separated list of files> specify comma separated files to be copied to the map reduce cluster
-libjars <comma separated list of jars> specify comma separated jar files to include in the classpath.
-archives <comma separated list of archives> specify comma separated archives to be unarchived on the compute machines.