1.CentOS7安装
(1)最小化安装CentOS7
(2)配置网络连接
vi/etc/sysconfig/network-scripts/ifcfg-eth0
修改:BOOTPROTO=static
ONBOOT=yes
添加:IPADDR= ipaddress(ip地址)
NETMASK=subnetmask(子网掩码)
GATEWAY=gateway(网关)
DNS1=dns ip1(DNS服务器1)
DNS2=dns ip2(DNS服务器2)
保存退出(:wq)
使用如下命令使配置生效
service network restart
cat /etc/resolv.conf显示
nameserverdns ip1
nameserverdns ip2
表明网络配置生效
(3)安装工具
yum-y install net-tools //ifconfignetstat等命令工具均被安装
yum–y install vim // vi编辑器升级版被安装
yum–y install wget // 远程下载工具被安装
yum –y installrsync // 远程同步工具
(4)关闭防火墙
systemctl stopfirewalld.service // 停止防火墙
systemctldisable firewalld.service // 系统重启后防火墙不再启动
2.JDK安装
mkdir /usr/java
cd /usr/java
wget ftp://localhost/jdk*.tar.gz // 下载jdk解压包
tar –zxvf jdk*.tar.gz //解压
vim /etc/profile //修改配置文件,添加环境变量如下:
#set jdk environment path
exportJAVA_HOME=/usr/java/jdk*
exportCLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar:${JAVA_HOME}/jre/rt.jar
exportPATH=$PATH:${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin
保存退出(press ESC Key,and type :wq)
source /etc/profile //是配置生效
java –version //验证配置是否生效
3.将当前安装的虚拟机CentOS7连续复制三份,并恰当设置网络IP,使其生效。
同时配置各虚拟机的hostname:(可选)
hostnamectl set-hostname namenode //修改namenode的主机名
配置各机器的解析表:(可选)
vim /etc/hosts
192.168.1.100namenode
192.168.1.101 datanode1
……
4.配置namenode到datanode的无密码登录(名称节点到数据节点的无密码登录)
(1)在namenode上以root登录,并生成私钥-公钥对:
ssh-keygen–t rsa–P ‘’
(2)cd /root/.ssh
(3)cat id_rsa.pub >>authorized_keys(使本机的ssh可以无密码启动本机的命令)
(4)ssh-copy-id –i id_rsa.pub root@datanode1 // 将公钥复制到datanode1节点上,使namenode可以无密码登录到datanode1上
(5) vim config //设置ssh配置,使首次远程登陆免打扰,文件中输入如下内容
StrictHostKeyCheckingno
5.安装Hadoop
mkdir /usr/hadoop
cd /usr/hadoop
wget ftp://ftpserver/hadoop-2.6.0.tar.gz
tar –zxvfhadoop-2.6.0.tar.gz
6.Hadoop集群配置
(1)准备环境
cd /usr/hadoop/hadoop-2.6.0
vimetc/hadoop/hadoop-env.sh
# set to the root of your Java installation
export JAVA_HOME=/usr/java/jdk* //JDK的安装目录
# Assuming your installation directory is/usr/hadoop/hadoop-2.6.0
export HADOOP_PREFIX=/usr/hadoop/hadoop-2.6.0 // hadoop的安装目录
vimetc/hadoop/yarn-env.sh
exportJAVA_HOME=/usr/java/jdk*
(2)修改配置文件
vim${HADOOP_HOME}/etc/hadoop/core-site.xml- // # core-site.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
- <configuration>
- <property>
- <name>fs.defaultFS</name>
- <value>hdfs://210.47.163.199:9000/</value>
- </property>
- <property>
- <name>io.file.buffer.size</name>
- <value>131072</value>
- </property>
- </configuration>
- // #hdfs-site.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
- <configuration>
- <property>
- <name>dfs.replication</name>
- <value>2</value>
- </property>
- <property>
- <name>dfs.namenode.name.dir</name>
- <value>file:///usr/hadoop/hadoop-2.6.0/dfs/name</value>
- </property>
- <property>
- <name>dfs.datanode.data.dir</name>
- <value>file:///usr/hadoop/hadoop-2.6.0/dfs/data</value>
- </property>
- <property>
- <name>dfs.permissions.enabled</name>
- <value>false</value>
- </property>
- </configuration>
- //#yarn-site.xml
- <?xml version="1.0"?>
- <configuration>
- <property>
- <name>yarn.nodemanager.aux-services</name>
- <value>mapreduce_shuffle</value>
- </property>
- <property>
- <name>yarn.resourcemanager.hostname</name>
- <value>210.47.163.199</value>
- </property>
- </configuration>
- #mapred-site.xml
- <?xml version="1.0"?>
- <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
- <configuration>
- <property>
- <name>mapreduce.framework.name</name>
- <value>yarn</value>
- </property>
- <property>
- <name>mapreduce.jobhistory.address</name>
- <value>210.47.163.199:10020</value>
- </property>
- <property>
- <name>mapreduce.jobhistory.webapp.address</name>
- <value>210.47.163.199:19888</value>
- </property>
- </configuration>
// # core-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://210.47.163.199:9000/</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
</property>
</configuration>
// #hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///usr/hadoop/hadoop-2.6.0/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:///usr/hadoop/hadoop-2.6.0/dfs/data</value>
</property>
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
</configuration>
//#yarn-site.xml
<?xml version="1.0"?>
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>210.47.163.199</value>
</property>
</configuration>
#mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>210.47.163.199:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>210.47.163.199:19888</value>
</property>
</configuration>
#slaves //配置从机datanodenodemanager
192.168.1.101
192.168.1.102
……
7 将在namenode上的hadoop安装复制到datanode
scp-r /usr/hadoop root@datanode1:/usr
scp -r /usr/hadoop root@datanode2:/usr
scp -r /usr/hadoop root@datanode3:/usr
常见问题:
(1)在hadoop2中查看网页中的/tmp目录出现下面的错误:Permission denied: user=dr.who,access=READ_EXECUTE inode="/tmp"
如果要查看hdfs://hostname:50070/tmp下面的文件,可以在hadoop2的安装目录$HADOOP_HOME运行bin/hadoopdfschmod -R 755 /tmp,然后就可以了。
(2)在Windows操作系统上通过Web浏览器无法下载hdfs文件
主要原因是namenode直接向浏览器返回的是datanode的hostname,然后浏览器再和datanode通信进行文件下载,而浏览器无法解析hostname,因此主要的修改方法是修改Windows操作系统的hosts文件,在文件中添加ip和hostname之间的映射。
C:\Windows\System32\Drivers\etc\hosts
然后修改Hadoop的配置文件etc/hadoop/hdfs-site.xml,添加
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
使节点不对用户身份进行验证。
(3)Hadoop Eclipse插件的安装问题
下载Hadoop的eclipse插件的地址:https://github.com/winghc/hadoop2x-eclipse-plugin,下载后拷贝到eclipse的plugins文件夹下面,然后重新启动eclipse即可进行配置。