1、环境,3台CentOS7,64位,Hadoop2.7需要64位Linux,CentOS7 操作系统二十分钟就可以安装完成,
Master 192.168.1.32
Slave1 192.168.1.33
Slave2 192.168.1.31
2、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@slave1 cat ~/.ssh/id_rsa.pub>> authorized_keys
ssh root@slave2 cat ~/.ssh/id_rsa.pub>> authorized_keys
(4)把Master服务器的authorized_keys、known_hosts复制到Slave服务器的/root/.ssh目录
scp authorized_keys root@slave1:/root/.ssh/
scp known_hosts root@slave1:/root/.ssh/
scp authorized_keys root@slave2:/root/.ssh/
scp known_hosts root@slave2:/root/.ssh/
(5)完成,ssh root@192.168.1.33、ssh root@192.168.1.31就不需要输入密码了
3、安装JDK,Hadoop2.7需要JDK7,直接解压下载的JDK并配置变量即可
(1)下载“jdk-7u79-linux-x64.gz”,放到/home/目录下
(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
export HADOOP_HOME=/home/hadoop-2.7.3/
export PATH="$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH"
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
(4)使配置生效,输入命令,source /etc/profile
(5)输入命令,java -version,查看jdk是否安装正常
4、安装Hadoop2.7.3,只在Master服务器解压,再复制到Slave服务器
(1)到官网下载“hadoop-2.7.3.tar.gz”,放到/home目录下
(2)解压,输入命令,tar -xzvf hadoop-2.7.3.tar.gz
5、配置/home/hadoop-2.7.3/etc/hadoop目录下的core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/home/hadoop/tmp</value>
</property>
</configuration>
6、配置/home/hadoop-2.7.3/etc/hadoop目录下的hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/hadoop/bigdata/data/namenode</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/hadoop/bigdata/data/datanode/</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>vm1:9001</value>
</property>
</configuration>
7、配置/home/hadoop-2.7.3/etc/hadoop目录下的mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>master:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>master:19888</value>
</property>
<property>
<name>mapreduce.jobhistory.done-dir</name>
<value>/history/done</value>
</property>
<property>
<name>mapreduce.jobhistory.intermediate-done-dir</name>
<value>/history/done_intermediate</value>
</property>
</configuration>
8、配置/home/hadoop-2.7.3/etc/hadoop目录下的yarn-site.xml
<configuration>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>vm1</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
9、配置/home/hadoop-2.7.3/etc/hadoop目录下hadoop-env.sh的JAVA_HOME,不设置的话,启动不了,
export JAVA_HOME=/home/java/jdk1.7.0_79
10、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目录下的slaves,删除默认的localhost,增加2个从节点,
192.168.1.33
192.168.1.31
11、将配置好的Hadoop复制到各个节点对应位置上,通过scp传送,
scp -r /home/hadoop-2.7.3 192.168.1.33:/home/
scp -r /home/hadoop-2.7.3 192.168.1.31:/home/
并修改profile文件(同3)
12、在Master服务器启动hadoop,从节点会自动启动,进入/home/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,可以看到相关信息
13、Web访问,要先开放端口或者直接关闭防火墙
(1)输入命令,systemctl stop firewalld.service
(2)浏览器打开http://192.168.1.32:8088/
(3)浏览器打开http://192.168.1.32:50070/
14、安装完成。这只是大数据应用的开始,之后的工作就是,结合自己的情况,编写程序调用Hadoop的接口,发挥hdfs、mapreduce的作用。