经过几天的折腾,总算成功了~账号注册到现状近N年了,这是第一篇博客~
![大笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
1、软件准备
a.OS:CentOS-7.0-1406-x86_64-DVD.iso --去CentOS官网下
b.JDK:jdk-7u71-linux-x64.gz --oracle官网下,至于1.8是否可行,没试
c.Hadoop: hadoop-2.5.1.tar.gz --hadoop官网下
d.虚拟机: VMware Player --小巧够用, 其他虚拟机也行
2.环境介绍
a.主机:
192.168.1.100 master
192.168.1.101 slave1
192.168.1.102 slave2
192.168.1.103 slave3
b.用户:
Master SSH无密码登陆slaver
主机用户1: root 密码 hadoop
主机用户2: hadoop 密码 hadoop
c.JDK位置:
/usr/local 即/usr/local/jdk1.7.0_71
d.hadoop 位置:
/opt 即/opt/hadoop-2.5.1
e.SSH公匙位置
/home/hadoop/.ssh/ 即hadoop用户的根目录下的.shh隐藏目录,hadoop登陆后 $cd ~/.ssh 可进入
3、安装思路
由于master与slave除了IP地址不同外,其他配置基本相同(懒的话主机名不改都没问题^_^),所以思路就是配置好Master后将虚拟机复制,然后修改网络配置,将是最简单的办法。
4、安装步骤
a.建立虚拟机:
测试的话10G硬盘 2G RAM足够了),最小化安装centos7。其中:
分区自动
root密码 hadoop 另建立一个新用户hadoop 密码hadoop
主机名master(懒得后面改)
ip地址设置静态(懒得后面配置,并启动网卡):
IP:192.168.1.100
mask:255.255.255.0
gateway:192.168.1.1
DNS1:192.168.1.1
DNS2:8.8.8.8
b-关闭防火墙
systemctl stop firewalld.service --关闭防火墙
systemctl disable firewalld.service --永久关闭防火墙
c.增加五个工具(后续操作,若#都是root用户 $的都是hadoop用户,本节可选):
--vim
#yum -y install vim
--ifconfig
#yum -y net-tools
--时间同步
#yum -y install ntp
#ntpdate us.pool.ntp.org
#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
--系统信息
#yum install -y sysstat
--tree命令
#yum install -y tree
d.修改hosts
# vim /etc/hosts
按i进入插入模式,用#号注释掉已有,加入四行,:
192.168.1.100 master
192.168.1.101 slave1
192.168.1.102 slave2
192.168.1.103 slave3
按ESC :wq回车
e.修改ip
若安装没设置IP或者网卡没有启动:
[root@master ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:3d:ed:03 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.11/24 brd 192.168.88.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe3d:ed03/64 scope link
valid_lft forever preferred_lft forever
注意看2后面的eno16777736就是网卡名,然后编辑网卡配置:
[root@master ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
HWADDR=00:0C:29:3D:ED:03
TYPE=Ethernet
BOOTPROTO=static ##重要,否则dhcp了
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BROADCAST=192.168.1.255
DNS1=192.168.1.1
DNS2=8.8.8.8
ONBOOT=yes ##重要,这个为no则系统启动不启动该网卡
至少保证以上信息,其他的不管,重启网络:
#service network restart
5、SSH无密码登陆
#su hadoop
$cd ~
$mkdir .ssh
$chmod 744 .ssh ##权限重要,默认权限可以,本步骤可选
$ssh-keygen -t rsa -P '' ##ssh后无空格!!!
$cat ~/.ssh/id_rsa.pub>>~/.ssh/authorized_keys ##将公钥追加到AuthorizedKeysFile
$chmod 644 ~/.ssh/authorized_keys ##权限重要,默认权限不行
$su
#vim /etc/ssh/sshd_config
去除前面的#
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#service sshd restart #重启ssh服务
$su hadoop
$ssh localhost 或ssh master
Last login: Sat Nov 8 20:16:23 2014 #ssh无密码登陆成功
6、连接网络共享,取得安装程序(懒人不架设FTP服务器)
其中//192.168.1.9 是台windows 7的电脑,共享目录share,用户名密码均是share,里面放有下载好的JDK(jdk-7u71-linux-x64.gz)与 hadoop 2.5.1 (hadoop-2.5.1.tar.gz):
#mkdir /mnt/share #建立共享文件挂载点
#mount -t cifs -o username="share",password="share" //192.168.1.9/share /mnt/share
#cd /mnt/share
5.安装jdk
#tar xzvf jdk-7u71-linux-x64.gz -C /usr/local/
#vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.7.0_71
export PATH=$PATH:$JAVA_HOME/bin
#source /etc/profile ## 刷新系统配置
确认版本java安装成果
# java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
7、安装配置hadoop
#cd /mnt/share
#tar xzvf hadoop-2.5.1.tar.gz -C /opt/
#chown -R hadoop:hadoop /opt/hadoop-2.5.1
# vim /etc/profile ##修改系统配置
export HADOOP_HOME=/opt/hadoop-2.5.1
export PATH=$PATH:$HADOOP_HOME/bin
# source /etc/profile ## 刷新系统配置
# su hadoop
$ cd /opt/hadoop-2.5.1
$ mkdir -p dfs/name
$ mkdir -p dfs/data
$ mkdir -p tmp
$ cd etc/hadoop
a.配置所有slave节点
$ vim slaves
slave1
slave2
slave3
b.修改hadoop-env.sh和yarn-env.sh
$ vim hadoop-env.sh
export JAVA_HOME=/usr/local/jdk1.7.0_71
a.OS:CentOS-7.0-1406-x86_64-DVD.iso --去CentOS官网下
b.JDK:jdk-7u71-linux-x64.gz --oracle官网下,至于1.8是否可行,没试
c.Hadoop: hadoop-2.5.1.tar.gz --hadoop官网下
d.虚拟机: VMware Player --小巧够用, 其他虚拟机也行
2.环境介绍
a.主机:
192.168.1.100 master
192.168.1.101 slave1
192.168.1.102 slave2
192.168.1.103 slave3
b.用户:
Master SSH无密码登陆slaver
主机用户1: root 密码 hadoop
主机用户2: hadoop 密码 hadoop
c.JDK位置:
/usr/local 即/usr/local/jdk1.7.0_71
d.hadoop 位置:
/opt 即/opt/hadoop-2.5.1
e.SSH公匙位置
/home/hadoop/.ssh/ 即hadoop用户的根目录下的.shh隐藏目录,hadoop登陆后 $cd ~/.ssh 可进入
3、安装思路
由于master与slave除了IP地址不同外,其他配置基本相同(懒的话主机名不改都没问题^_^),所以思路就是配置好Master后将虚拟机复制,然后修改网络配置,将是最简单的办法。
4、安装步骤
a.建立虚拟机:
测试的话10G硬盘 2G RAM足够了),最小化安装centos7。其中:
分区自动
root密码 hadoop 另建立一个新用户hadoop 密码hadoop
主机名master(懒得后面改)
ip地址设置静态(懒得后面配置,并启动网卡):
IP:192.168.1.100
mask:255.255.255.0
gateway:192.168.1.1
DNS1:192.168.1.1
DNS2:8.8.8.8
b-关闭防火墙
systemctl stop firewalld.service --关闭防火墙
systemctl disable firewalld.service --永久关闭防火墙
c.增加五个工具(后续操作,若#都是root用户 $的都是hadoop用户,本节可选):
--vim
#yum -y install vim
--ifconfig
#yum -y net-tools
--时间同步
#yum -y install ntp
#ntpdate us.pool.ntp.org
#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
--系统信息
#yum install -y sysstat
--tree命令
#yum install -y tree
d.修改hosts
# vim /etc/hosts
按i进入插入模式,用#号注释掉已有,加入四行,:
192.168.1.100 master
192.168.1.101 slave1
192.168.1.102 slave2
192.168.1.103 slave3
按ESC :wq回车
e.修改ip
若安装没设置IP或者网卡没有启动:
[root@master ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:3d:ed:03 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.11/24 brd 192.168.88.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe3d:ed03/64 scope link
valid_lft forever preferred_lft forever
注意看2后面的eno16777736就是网卡名,然后编辑网卡配置:
[root@master ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
HWADDR=00:0C:29:3D:ED:03
TYPE=Ethernet
BOOTPROTO=static ##重要,否则dhcp了
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BROADCAST=192.168.1.255
DNS1=192.168.1.1
DNS2=8.8.8.8
ONBOOT=yes ##重要,这个为no则系统启动不启动该网卡
至少保证以上信息,其他的不管,重启网络:
#service network restart
5、SSH无密码登陆
#su hadoop
$cd ~
$mkdir .ssh
$chmod 744 .ssh ##权限重要,默认权限可以,本步骤可选
$ssh-keygen -t rsa -P '' ##ssh后无空格!!!
$cat ~/.ssh/id_rsa.pub>>~/.ssh/authorized_keys ##将公钥追加到AuthorizedKeysFile
$chmod 644 ~/.ssh/authorized_keys ##权限重要,默认权限不行
$su
#vim /etc/ssh/sshd_config
去除前面的#
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#service sshd restart #重启ssh服务
$su hadoop
$ssh localhost 或ssh master
Last login: Sat Nov 8 20:16:23 2014 #ssh无密码登陆成功
6、连接网络共享,取得安装程序(懒人不架设FTP服务器)
其中//192.168.1.9 是台windows 7的电脑,共享目录share,用户名密码均是share,里面放有下载好的JDK(jdk-7u71-linux-x64.gz)与 hadoop 2.5.1 (hadoop-2.5.1.tar.gz):
#mkdir /mnt/share #建立共享文件挂载点
#mount -t cifs -o username="share",password="share" //192.168.1.9/share /mnt/share
#cd /mnt/share
5.安装jdk
#tar xzvf jdk-7u71-linux-x64.gz -C /usr/local/
#vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.7.0_71
export PATH=$PATH:$JAVA_HOME/bin
#source /etc/profile ## 刷新系统配置
确认版本java安装成果
# java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
7、安装配置hadoop
#cd /mnt/share
#tar xzvf hadoop-2.5.1.tar.gz -C /opt/
#chown -R hadoop:hadoop /opt/hadoop-2.5.1
# vim /etc/profile ##修改系统配置
export HADOOP_HOME=/opt/hadoop-2.5.1
export PATH=$PATH:$HADOOP_HOME/bin
# source /etc/profile ## 刷新系统配置
# su hadoop
$ cd /opt/hadoop-2.5.1
$ mkdir -p dfs/name
$ mkdir -p dfs/data
$ mkdir -p tmp
$ cd etc/hadoop
a.配置所有slave节点
$ vim slaves
slave1
slave2
slave3
b.修改hadoop-env.sh和yarn-env.sh
$ vim hadoop-env.sh
export JAVA_HOME=/usr/local/jdk1.7.0_71
$ vim yarn-env.sh
export JAVA_HOME=/usr/local/jdk1.7.0_71
c.修改core-site.xml
$ vim etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/hadoop-2.5.1/tmp</value>
</property>
</configuration>
注意:/opt/hadoop-2.5.1/tmp前面不能有 file!!!与hdfs-site.xml不一样,而且所有内容中不能有空格,结尾处也不行!如<value>/opt/hadoop-2.5.1/tmp </value>会出错(tmp后有空格)。
d.修改hdfs-site.xml
$ vim etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/opt/hadoop-2.5.1/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/opt/hadoop-2.5.1/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master:9001</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
</configuration>
export JAVA_HOME=/usr/local/jdk1.7.0_71
c.修改core-site.xml
$ vim etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/hadoop-2.5.1/tmp</value>
</property>
</configuration>
注意:/opt/hadoop-2.5.1/tmp前面不能有 file!!!与hdfs-site.xml不一样,而且所有内容中不能有空格,结尾处也不行!如<value>/opt/hadoop-2.5.1/tmp </value>会出错(tmp后有空格)。
d.修改hdfs-site.xml
$ vim etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/opt/hadoop-2.5.1/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/opt/hadoop-2.5.1/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master:9001</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
</configuration>
e.修改mapred-site.xml
$ cd /opt/hadoop-2.5.1
$ cp etc/hadoop/mapred-site.xml.template etc/hadoop/mapred-site.xml
$ vim etc/hadoop/mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
f.配置yarn-site.xml
(a).伪分布配置:
$ vim etc/hadoop/yarn-site.xml:
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
(b)集群配置:
$ vim 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>master:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>master:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>master:8088</value>
</property>
</configuration>
8、关机,复制三台slave
#shutdown
9、启动slave1,修改网卡配置与主机名
#ip addr
[root@master ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:fd:1d:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.88.11/24 brd 192.168.88.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe3d:ed03/64 scope link
valid_lft forever preferred_lft forever
注意看2:后面的eno16777736就是网卡名,然后编辑网卡配置:
# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
HWADDR=00:0C:29:FD:1D:23 ##关键1,按刚才查出来的mac地址,eno16777736下面那行
TYPE=Ethernet
BOOTPROTO=static ##关键2
IPADDR=192.168.1.101 ##关键3
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BROADCAST=192.168.1.255
DNS1=192.168.1.1
DNS2=8.8.8.8
ONBOOT=yes ##关键4
至少保证以上信息
# service network restart --重启网络
修改主机名:
# hostnamectl set-hostname slave1
10、启动slave2/slave2,修改网卡配置与主机名
11、格式化namenode
$ cd /opt/hadoop-2.5.1
$ hdfs namenode -format
12 启动hdfs
$ ./sbin/start-dfs.sh
$ ./sbin/start-yarn.sh
--用pi程序测试:
$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.1.jar pi 2 20000
$ cd /opt/hadoop-2.5.1
$ cp etc/hadoop/mapred-site.xml.template etc/hadoop/mapred-site.xml
$ vim etc/hadoop/mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
f.配置yarn-site.xml
(a).伪分布配置:
$ vim etc/hadoop/yarn-site.xml:
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
(b)集群配置:
$ vim 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>master:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>master:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>master:8088</value>
</property>
</configuration>
8、关机,复制三台slave
#shutdown
9、启动slave1,修改网卡配置与主机名
#ip addr
[root@master ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:fd:1d:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.88.11/24 brd 192.168.88.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe3d:ed03/64 scope link
valid_lft forever preferred_lft forever
注意看2:后面的eno16777736就是网卡名,然后编辑网卡配置:
# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
HWADDR=00:0C:29:FD:1D:23 ##关键1,按刚才查出来的mac地址,eno16777736下面那行
TYPE=Ethernet
BOOTPROTO=static ##关键2
IPADDR=192.168.1.101 ##关键3
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BROADCAST=192.168.1.255
DNS1=192.168.1.1
DNS2=8.8.8.8
ONBOOT=yes ##关键4
至少保证以上信息
# service network restart --重启网络
修改主机名:
# hostnamectl set-hostname slave1
10、启动slave2/slave2,修改网卡配置与主机名
11、格式化namenode
$ cd /opt/hadoop-2.5.1
$ hdfs namenode -format
12 启动hdfs
$ ./sbin/start-dfs.sh
$ ./sbin/start-yarn.sh
--用pi程序测试:
$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.1.jar pi 2 20000
13 检查启动情况
http://192.168.1.100:8088
http://192.168.1.100:50070
http://192.168.1.100:8088
http://192.168.1.100:50070
14、关闭hadoop
$ ./sbin/stop-all.sh
$ ./sbin/stop-all.sh