來吧,小夥伴們java
一、環境:3臺CentOS7,64位,Hadoop2.7須要64位Linux
node
提早安裝好jdk-8u121-linux-x64.tar.gz, 並配置JAVA_HOMElinux
hadoop-2.7.3.tar.gzweb
二、SSH免密碼登陸,由於Hadoop須要經過SSH登陸到各個節點進行操做,root用戶,每臺服務器都生成公鑰,再合併到authorized_keys
(1)CentOS默認沒有啓動ssh無密登陸,去掉/etc/ssh/sshd_config其中2行的註釋,每臺服務器都要設置,apache
#RSAAuthentication yes
#PubkeyAuthentication yescentos
改成:瀏覽器
(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.1.101 cat ~/.ssh/id_rsa.pub>> authorized_keys
ssh root@192.168.1.101 cat ~/.ssh/id_rsa.pub>> authorized_keys
(4)把Master服務器的authorized_keys、known_hosts複製到Slave服務器的/root/.ssh目錄
(5)完成,ssh root@192.168.1.10三、ssh root@192.168.1.105就不須要輸入密碼了服務器
三、安裝JDK,Hadoop2.7須要JDK7
編輯/etc/profile
export JAVA_HOME=/usr/local/software/jdk1.8.0_121
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,完成app
四、安裝Hadoop2.7,只在Master服務器解壓,再複製到Slave服務器
(1)下載「hadoop-2.7.3.tar.gz」,放到/home/hadoop目錄下
(2)解壓,輸入命令,tar -xzvf hadoop-2.7.3.tar.gz
(3)在/home/hadoop目錄下建立數據存放的文件夾,tmp、hdfs、hdfs/data、hdfs/namessh
五、配置/home/hadoop/hadoop-2.7.3/etc/hadoop目錄下的core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://192.168.1.101: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.3/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.1.101:9001</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
七、配置/home/hadoop/hadoop-2.7.3/etc/hadoop目錄下的yarn-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>192.168.1.101:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>192.168.1.101:19888</value>
</property>
</configuration>
八、配置/home/hadoop/hadoop-2.7.3/etc/hadoop目錄下的mapred-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.1.101:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>192.168.1.101:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>192.168.1.101:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>192.168.1.101:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>192.168.1.101:8088</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>768</value>
</property>
</configuration>
九、配置/home/hadoop/hadoop-2.7.3/etc/hadoop目錄下hadoop-env.sh、yarn-env.sh的JAVA_HOME,不設置的話,啓動不了,
export JAVA_HOME=/usr/local/software/jdk1.8.0_121
十、配置/home/hadoop/hadoop-2.7.3/etc/hadoop目錄下的slaves,刪除默認的localhost,增長2個從節點,
192.168.1.103
192.168.1.105
十一、將配置好的Hadoop複製到各個節點對應位置上,經過scp傳送,
scp -r /home/hadoop 192.168.1.103:/home/
scp -r /home/hadoop 192.168.1.105:/home/
十二、在Master服務器啓動hadoop,從節點會自動啓動,進入/home/hadoop/hadoop-2.7.3目錄
(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,能夠看到相關信息
(5)查看hadoop運行相關參數:ps -ef|grep hadoop
1三、Web訪問,要先開放端口或者直接關閉防火牆
(centos)查看防火牆狀態:service firewalld status
(centos)關閉防火牆:service firewalld stop
(centos)打開防火牆:service firewalld start
(1)輸入命令,systemctl stop firewalld.service
(2)瀏覽器打開http://192.168.1.101:8088/
(3)瀏覽器打開http://192.168.1.101:50070/
1四、安裝完成。這只是大數據應用的開始,以後能夠繼續安裝spark、hive等,在IDE上編寫程序調用Hadoop的接口,發揮hdfs、mapreduce的做用。