一、軟件準備
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 可進入
三、安裝思路
因爲master與slave除了IP地址不一樣外,其餘配置基本相同(懶的話主機名不改都沒問題^_^),因此思路就是配置好Master後將虛擬機複製,而後修改網絡配置,將是最簡單的辦法。
四、安裝步驟
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
五、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無密碼登錄成功
六、鏈接網絡共享,取得安裝程序(懶人不架設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)
七、安裝配置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
java
$ 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>
node
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>
八、關機,複製三臺slave
#shutdown
九、啓動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
十、啓動slave2/slave2,修改網卡配置與主機名
十一、格式化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
linux
13 檢查啓動狀況
http://192.168.1.100:8088
http://192.168.1.100:50070
web
1四、關閉hadoop
$ ./sbin/stop-all.shapache