http://192.168.175.123:8088/cluster
http://192.168.175.129:50070/cluster
http://192.168.175.129:60010/cluster
集群规划:
主机名 | IP | 安装的软件 | 运行的进程 |
hadoop01 | 192.168.175.129 | Jdk,hadoop | NameNod、DFSZKFailoverController(zkfc) |
hadoop02 | 192.168.175.127 | Jdk,hadoop | NameNod、DFSZKFailoverController(zkfc) |
hadoop03 | 192.168.175.126 | Jdk,hadoop | ResourceManager |
hadoop04 | 192.168.175.125 | Jdk,hadoop | ResourceManager |
hadoop05 | 192.168.175.124 | Jdk,hadoop, zookeeper | DataNode、NodeManager、 JournalNode、QuorumPeerMain |
hadoop06 | 192.168.175.123 | Jdk,hadoop, zookeeper | DataNode、NodeManager、 JournalNode、QuorumPeerMain |
hadoop07 | 192.168.175.122 | Jdk,hadoop, zookeeper | DataNode、NodeManager、 JournalNode、QuorumPeerMain |
以下操作均以hadoop01为例
windows:NLB
LINUX:LVS
1.liunx虚拟机安装后,虚拟机连接模式要选择host-only模式。然后分配IP(以hadoop01为例)
DEVICE="eth0"
BOOTPROTO="static" ###
HWADDR="00:0C:29:3C:BF:E7"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="ce22eeca-ecde-4536-8cc2-ef0dc36d4a8c"
IPADDR="192.168.175.129" ###
NETMASK="255.255.255.0" ###
GATEWAY="192.168.175.1" ###
2.修改主机名:
vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=hadoop01 ###
3.关闭防火墙:
#查看防火墙状态
service iptables status
#关闭防火墙
service iptables stop
#查看防火墙开机启动状态
chkconfig iptables --list
#关闭防火墙开机启动
chkconfig iptables off
4.免登录配置:
#生成ssh免登陆密钥
#进入到我的home目录
cd ~/.ssh
ssh-keygen -t rsa (四个回车)
执行完这个命令后,会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
将公钥拷贝到要免登陆的机器上
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
或
ssh-copy-id localhost
若报错ssh-copy-id: ERROR: No identities found,是因为找不到公钥路径,加上-i然后再加上路径即可
则用
$ ssh-copy-id -i ~/.ssh/id_dsa.pub user@remote_ip
5.主机IP映射关系(/etc/hosts每台机器上都要配置全部映射关系)
192.168.175.129 hadoop01
192.168.175.127 hadoop02
192.168.175.126 hadoop03
192.168.175.125 hadoop04
192.168.175.124 hadoop05
192.168.175.123 hadoop06
192.168.175.122 hadoop07
6./etc/profile下配置java环境变量:
export JAVA_HOME=/lichangwu/jdk1.7.0_79
export PATH=$PATH:$JAVA_HOME/bin
#刷新profile
source /etc/profile
若版本报错,vi /etc/selinux/config,设置SELINUX=disabled,然后重启虚拟机
7.安装zookeeper:
1.安装配置zooekeeper集群(在hadoop05上):
1.1解压
tar -zxvf zookeeper-3.4.6.tar.gz -C /lichangwu/
1.2修改配置
cd /lichangwu/zookeeper-3.4.6/conf/
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
修改:dataDir=/lichangwu/zookeeper-3.4.6/tmp
在最后添加:
server.1=hadoop05:2888:3888
server.2=hadoop06:2888:3888
server.3=hadoop07:2888:3888
保存退出
然后创建一个tmp文件夹
mkdir /lichangwu/zookeeper-3.4.6/tmp
再创建一个空文件
touch /lichangwu/zookeeper-3.4.6/tmp/myid
最后向该文件写入ID
echo 1 > /lichangwu/zookeeper-3.4.6/tmp/myid
1.3将配置好的zookeeper拷贝到其他节点(首先分别在hadoop06、hadoop07根目录下创建一个lichangwu目录:mkdir /lichangwu)
scp -r /lichangwu/zookeeper-3.4.6/ hadoop06:/lichangwu/
scp -r /lichangwu/zookeeper-3.4.6/ hadoop07:/lichangwu/
注意:修改hadoop06、hadoop07对应/lichangwu/zookeeper-3.4.6/tmp/myid内容
itcast06:
echo 2 > /lichangwu/zookeeper-3.4.6/tmp/myid
itcast07:
echo 3 > /lichangwu/zookeeper-3.4.6/tmp/myid
8.安装配置hadoop集群(在hadoop01上操作):
2.1解压
tar -zxvf hadoop-2.4.1.tar.gz -C /lichangwu/
2.2配置HDFS(hadoop2.0所有的配置文件都在$HADOOP_HOME/etc/hadoop目录下)
#将hadoop添加到环境变量中
vim /etc/profile
export JAVA_HOME=/lichangwu/jdk1.7.0_79
export HADOOP_HOME=/lichangwu/hadoop-2.4.1
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin
#hadoop2.0的配置文件全部在$HADOOP_HOME/etc/hadoop下
cd /lichangwu/hadoop-2.4.1/etc/hadoop
2.2.1修改hadoo-env.sh
export JAVA_HOME=/lichangwu/jdk1.7.0_79
2.2.2修改core-site.xml
<configuration>
<!-- 指定hdfs的nameservice为ns1 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1</value>
</property>
<!-- 指定hadoop临时目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/lichangwu/hadoop-2.4.1/tmp</value>
</property>
<!-- 指定zookeeper地址 -->
<property>
<name>ha.zookeeper.quorum</name>
<value>hadoop05:2181,hadoop06:2181,hadoop07:2181</value>
</property>
</configuration>
2.2.3修改hdfs-site.xml
<configuration>
<!--指定hdfs的nameservice为ns1,需要和core-site.xml中的保持一致 -->
<property>
<name>dfs.nameservices</name>
<value>ns1</value>
</property>
<!-- ns1下面有两个NameNode,分别是nn1,nn2 -->
<property>
<name>dfs.ha.namenodes.ns1</name>
<value>nn1,nn2</value>
</property>
<!-- nn1的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.ns1.nn1</name>
<value>hadoop01:9000</value>
</property>
<!-- nn1的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>hadoop01:50070</value>
</property>
<!-- nn2的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>hadoop02:9000</value>
</property>
<!-- nn2的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>hadoop02:50070</value>
</property>
<!-- 指定NameNode的元数据在JournalNode上的存放位置 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://hadoop05:8485;hadoop06:8485;hadoop07:8485/ns1</value>
</property>
<!-- 指定JournalNode在本地磁盘存放数据的位置 -->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/lichangwu/hadoop-2.4.1/journal</value>
</property>
<!-- 开启NameNode失败自动切换 -->
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<!-- 配置失败自动切换实现方式 -->
<property>
<name>dfs.client.failover.proxy.provider.ns1</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!-- 配置隔离机制方法,多个机制用换行分割,即每个机制暂用一行-->
<property>
<name>dfs.ha.fencing.methods</name>
<value>
sshfence
shell(/bin/true)
</value>
</property>
<!-- 使用sshfence隔离机制时需要ssh免登陆 -->
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/hadoop/.ssh/id_rsa</value>
</property>
<!-- 配置sshfence隔离机制超时时间 -->
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
</configuration>
2.2.4修改mapred-site.xml
<configuration>
<!-- 指定mr框架为yarn方式 -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
2.2.5修改yarn-site.xml
<configuration>
<!-- 开启RM高可靠 -->
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<!-- 指定RM的cluster id -->
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yrc</value>
</property>
<!-- 指定RM的名字 -->
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<!-- 分别指定RM的地址 -->
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>hadoop03</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>hadoop04</value>
</property>
<!-- 指定zk集群地址 -->
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>hadoop05:2181,hadoop06:2181,hadoop07:2181</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
2.2.6修改slaves(slaves是指定子节点的位置,因为要在itcast01上启动HDFS、在itcast03启动yarn,所以itcast01上的slaves文件指定的是datanode的位置,itcast03上的slaves文件指定的是nodemanager的位置)
hadoop05
hadoop06
hadoop07
2.2.7配置免密码登陆
#首先要配置itcast01到hadoop02、hadoop03、hadoop04、hadoop05、hadoop06、hadoop07的免密码登陆
#在hadoop01上生产一对钥匙
ssh-keygen -t rsa
#将公钥拷贝到其他节点,包括自己
ssh-coyp-id hadoop01
ssh-coyp-id hadoop02
ssh-coyp-id hadoop03
ssh-coyp-id hadoop04
ssh-coyp-id hadoop05
ssh-coyp-id hadoop06
ssh-coyp-id hadoop07
#配置hadoop03到hadoop04、hadoop05、hadoop06、hadoop07的免密码登陆
#在hadoop03上生产一对钥匙
ssh-keygen -t rsa
#将公钥拷贝到其他节点
ssh-coyp-id hadoop04
ssh-coyp-id hadoop05
ssh-coyp-id hadoop06
ssh-coyp-id hadoop07
#注意:两个namenode之间要配置ssh免密码登陆,别忘了配置hadoop02到hadoop01的免登陆
在hadoop02上生产一对钥匙
ssh-keygen -t rsa
ssh-coyp-id -i hadoop01
2.4将配置好的hadoop拷贝到其他节点
scp -r hadoop-2.4.1/ hadoop02:/lichangwu/hadoop-2.4.1/
scp -r hadoop-2.4.1/ hadoop03:/lichangwu/hadoop-2.4.1/
scp -r hadoop-2.4.1/ hadoop04:/lichangwu/hadoop-2.4.1/
scp -r hadoop-2.4.1/ hadoop05:/lichangwu/hadoop-2.4.1/
scp -r hadoop-2.4.1/ hadoop06:/lichangwu/hadoop-2.4.1/
scp -r hadoop-2.4.1/ hadoop07:/lichangwu/hadoop-2.4.1/
###注意:严格按照下面的步骤
2.5启动zookeeper集群(分别在hadoop05、hadoop06、hadoop07上启动zk)
cd /lichangwu/zookeeper-3.4.6/bin/
./zkServer.sh start
#查看状态:一个leader,两个follower
./zkServer.sh status
2.6启动journalnode(分别在在hadoop05、hadoop06、hadoop07上执行)
cd /lichangwu/hadoop-2.4.1
sbin/hadoop-daemon.sh start journalnode
#运行jps命令检验,hadoop05、hadoop06、hadoop07上多了JournalNode进程
2.7格式化HDFS
#在hadoop01上执行命令:
hdfs namenode -format
#格式化后会在根据core-site.xml中的hadoop.tmp.dir配置生成个文件,这里我配置的是/lichangwu/hadoop-2.4.1/tmp,然后将/lichangwu/hadoop-2.4.1/tmp拷贝到hadoop02的/lichangwu/hadoop-2.4.1/下。
scp -r tmp/ hadoop02:/lichangwu/hadoop-2.4.1/
2.8格式化ZK(在hadoop01上执行即可)
hdfs zkfc -formatZK
2.9启动HDFS(在hadoop01上执行)
sbin/start-dfs.sh
2.10启动YARN(#####注意#####:是在hadoop03上执行start-yarn.sh,如果hadoop04上没有启动成功,则在hadoop04上再启动一次start-yarn.sh;把namenode和resourcemanager分开是因为性能问题,因为他们都要占用大量资源,所以把他们分开了,他们分开了就要分别在不同的机器上启动)
sbin/start-yarn.sh
到此,hadoop-2.4.1配置完毕,可以统计浏览器访问:
http://192.168.175.129:50070
NameNode 'hadoop01:9000' (active)
http://192.168.175.127:50070
NameNode 'hadoop02:9000' (standby)
验证HDFS HA
首先向hdfs上传一个文件
hadoop fs -put /etc/profile /profile
hadoop fs -ls /
然后再kill掉active的NameNode
kill -9 <pid of NN>
通过浏览器访问:http://192.168.175.127:50070
NameNode 'hadoop02:9000' (active)
这个时候hadoop02上的NameNode变成了active
在执行命令:
hadoop fs -ls /
-rw-r--r-- 3 root supergroup 1926 2014-02-06 15:36 /profile
刚才上传的文件依然存在!!!
手动启动那个挂掉的NameNode
sbin/hadoop-daemon.sh start namenode
通过浏览器访问:http://192.168.175.129:50070
NameNode 'hadoop01:9000' (standby)
验证YARN:
运行一下hadoop提供的demo中的WordCount程序:
hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.4.1.jar wordcount /profile /out
OK,大功告成!!!