1.、准备工作:
hadoop-2.6.0-x64.tar.gz
jdk-7u76-linux-x64.tar.gz
操作系统:centos 6.0, IP: 192.168.56.20,用户root, hadoop
以下操作使用root用户登录-------------------------------------------------------------------:
2、修改主机名和IP地址映射
vi/etc/sysconfig/network
HOSTNAME=master
主机名与IP地址映射
vi /ect/hosts
192.168.56.20 master
3、关闭防火墙和SELINUX
service iptables stop
iptables –F
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
/etc/init.d/iptables save
4、创建需要的目录
mkdir –p/application/hadoop
mkdir–p /data/hadoop
mkdir -p/data/hadoop/hdfs/name
mkdir -p/data/hadoop/hdfs/data
mkdir -p/data/hadoop/hdfs/namesecondary
mkdir -p /data/hadoop/tmp
mkdir -p/data/hadoop/mapred/mrlocal
mkdir -p/data/hadoop/mapred/mrsystem
chmod 755/data/hadoop/mapred/mrlocal
chmod 755/data/hadoop/mapred/mrsystem
创建组:
groupadd hadoop
创建用户并加到hadoop组中:
useradd –g hadoop hadoop
passwd hadoop
更改文件所有者,将刚才创建的hadoop目录的所有者改为hadoop用户:
chown –R hadoop:hadoop/application/hadoop
chown –R hadoop:hadoop/data/hadoop
使用hadoop用户登录------------------------------------
5、安装JDK
将jdk-7u76-linux-x64.tar.gz拷贝到/application/hadoop/目录下,
检查是否已经安装过JDK:
rpm -qa | grep jdk
若安装过1.7以下版本的,先卸载,如:
rpm -e --nodeps jdk-1.6.0_10-fcs
cd /application/hadoop/,解压:
tar -zxvf jdk-7u76-linux-x64.tar.gz
改名:
mv jdk-7u76-linux-x64 jdk
切换到root用户,配置环境变量:
vi /etc/profile.d/java.sh
export JAVA_HOME=/application/hadoop/jdk
export PATH=$JAVA_HOME/bin:$PATH
6、安装hadoop
切换到hadoop用户----------------
将hadoop-2.6.0-x64.tar.gz拷贝到/application/hadoop/目录下,
tar -zxvf hadoop-2.6.0-x64.tar.gz
改名:mvhadoop-2.6.0-x64 hadoop
使用root用户修改环境变量
vi /etc/profile.d/java.sh
exportHADOOP_HOME=/application/hadoop/hadoop
exportHADOOP_PREFIX=/application/hadoop/hadoop
export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$PATH
使环境变量生效:
source/etc/profile
7、配置无密码登录
[hadoop@master ~]$ mkdir.ssh
[hadoop@master ~]$ chmod755 .ssh
[hadoop@master ~]$ssh-keygen -t rsa -P ''
遇到要输入的地方直接回车
cd ~
[hadoop@master ~]$ cd .ssh
[hadoop@master .ssh]$ ls
id_rsa id_rsa.pub
[hadoop@master .ssh]$ catid_rsa.pub >> authorized_keys
[hadoop@master .ssh]$ chmod 600 authorized_keys
验证:
ssh master
第一次输入yes, 如下图:
再次输入命令验证:
ssh master
则不用再输入密码
8、hadoop配置
cd /application/hadoop/hadoop/etc/hadoop
修改以下文件:修改hadoop-env.sh,修改JAVA_HOME:
export JAVA_HOME=/application/hadoop/jdk
修改core-site.xml:
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/data/hadoop/hdfs/tmp</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>fs.checkpoint.dir</name>
<value>/data/hadoop/hdfs/namesecondary</value>
</property>
</configuration>
修改mapred-site.xml:
目录下没有mapred-site.xml文件,先复制一个:
cp mapred-site.xml.template mapred-site.xml
修改:
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>master:9001</value>
</property>
<property>
<name>mapred.local.dir</name>
<value>/data/hadoop/mapred/mrlocal</value>
<final>true</final>
</property>
<property>
<name>mapred.system.dir</name>
<value>/data/hadoop/mapred/mrsystem</value>
<final>true</final>
</property>
</configuration>
修改hdfs-site.xml:
<configuration>
<property>
<name> dfs.datanode.data.dir</name>
<value>/data/hadoop/hdfs/data</value>
</property>
</configuration>
修改yarn-site.xml
<configuration>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>master</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
9、 格式化hadoop namenode –format
10、启动hadoop/application/hadoop/hadoop/sbin/start-dfs.sh
11、查看查看进程:
[hadoop@master sbin]$ jps
出现上述内容则启动成功。
从web界面查看:
http://192.168.56.20:50070/dfshealth.jsp
/application/hadoop/hadoop/sbin/stop-dfs.sh