硬件环境:
vmware虚拟机,3台centos 64位6.5版本镜像。hadoop2.6.5,zookeeper3.4.9nm1:192.168.85.128 namenode1+zookeeper+datanodenm2:192.168.85.130 namenode2+zookeeper+datanodenode1:192.168.85.131 datanode+zookeeper【注意事项】
(1)配置文件中尽量用全路径,不用变量
(2)保持namenode节点的配置文件始终一致,特别是name和tmp、data等根目录
(3)注意环境变量
(4)SSH注意,测试所有的ssh链接不要出现提示符,包括连自己
(5)native library找不到的问题还没解决,等有时间研究。
试试这个:
在hadoop-env.sh中 修改HADOOP_OPTS:
export HADOOP_OPTS="-Djava.library.path=$HADOOP_PREFIX/lib:$HADOOP_PREFIX/lib/native" 【步骤】
1、创建hadoop用户
2、首先配置jdk环境 从oracle官网下载jdk-7u80-linux-x64.tar.gz, 下载到/home/hadoopzookeeper下载到/home/hadoop分别解压在/etc/profile设置环境变量 :#set java path
JAVA_HOME=/home/hadoop/jdk1.7.0_80
JRE_HOME=/home/hadoop/jdk1.7.0_30/jre
HADOOP_HOME=/home/hadoop/hadoop-2.6.5
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$HADOOP_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH HADOOP_HOME
export HADOOP_OPTS="-Djava.library.path=/home/hadoop/hadoop-2.6.5/lib/native"
3、配置/etc/hosts nm1 192.168.85.128 nm2 192.168.85.130 node1 192.168.85.130 4、配置zookeeper zookeeper安装在/home/hadoop/zookeeper目录 dataDir=/home/hadoop/zookeeper/data
server.1=nm1:2888:3888
server.2=nm2:2888:3888
server.3=node1:2888:3888
$scp to other hosts
3台机器分别启动: /home/hadoop/zookeeper/bin/zkServer.sh start 【注意确保防火墙已经关闭 】 检查是否成功: /home/hadoop/zookeeper/bin/zkServer.sh status 应该一台显示leader,其余两台显示follower 5、配置hadoop5.1配置hadoop 将hadoop添加到环境变量中JAVA_HOME=/home/hadoop/jdk1.7.0_80
JRE_HOME=/home/hadoop/jdk1.7.0_30/jre
HADOOP_HOME=/home/hadoop/hadoop-2.6.5
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$HADOOP_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH HADOOP_HOME
# improve Could not resolve hostname library: Name or service not known
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native" 5.2 hdfs-site.xml
<property>
<name>dfs.nameservices</name>
<value>ns1</value>
</property>
<property>
<name>dfs.ha.namenodes.ns1</name>
<value>nn1,nn2</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.nn1</name>
<value>nm1:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>nm1:50070</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>nm2:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>nm2:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://nm1:8485;nm2:8485;node1:8485/ns1</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/home/hadoop/hadoop-2.6.5/journaldata</value>
</property>
<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>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/hadoop/.ssh/id_rsa</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
5.3 yarn-site.xml<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yrc</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>nm1</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>nm2</value>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>nm1:2181,nm2:2181,node1:2181</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
5.4 mapred-site.xml<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
5.5 hadoop-env.sh export JAVA_HOME=/home/hadoop/jdk1.7.0_80 5.6 core-site.xml<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>$HADOOP_HOME/tmp</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>nm1:2181,nm2:2181,node1:2181</value>
</property>
5.7 slaves
nm1
nm2
node1
6、启动
6.1启动zookeeper集群(分别在nm1、nm2、node1上启动zk)cd $ZKHOME/bin/./zkServer.sh start#查看状态:一个leader,两个follower./zkServer.sh status6.2启动journalnode(分别在在nm1、nm2、node1上执行)cd $HADOOP_HOMEsbin/hadoop-daemon.sh start journalnode#运行jps命令检验,nm1、nm2、node1上多了JournalNode进程 7、启动hadoop7.1格式化HDFS#在nm1上执行命令:hdfs namenode -format#格式化后会在根据core-site.xml中的hadoop.tmp.dir配置生成个文件,这里我配置的是$HADOOP_HOME/tmp,然后将$HADOOP_HOME/tmp拷贝到nm2的$HADOOP_HOME下。scp -r tmp/ nm2:$HADOOP_HOME##也可以这样,建议hdfs namenode -bootstrapStandby7.2格式化ZKFC(在master01上执行即可)hdfs zkfc -formatZK
7.3启动HDFS(在nm1上执行)
sbin/start-dfs.sh7.4启动YARNsbin/start-yarn.sh到此,hadoop-2.6.2配置完毕,可以统计浏览器访问:NameNode 'master01:9000' (active)NameNode 'master02:9000' (standby)验证HDFS HA首先向hdfs上传一个文件hadoop fs -put /etc/profile /profilehadoop fs -ls /然后再kill掉active的NameNodekill -9 <pid of NN>通过浏览器访问:NameNode 'master02:9000' (active)这个时候nm2上的NameNode变成了active在执行命令:hadoop fs -ls /-rw-r--r-- 3 root supergroup 1926 2014-02-06 15:36 /profile刚才上传的文件依然存在!!!手动启动那个挂掉的NameNodesbin/hadoop-daemon.sh start namenode通过浏览器访问:NameNode 'weekend01:9000' (standby)验证YARN:运行一下hadoop提供的demo中的WordCount程序:hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.4.1.jar wordcount /profile /out测试集群工作状态的一些指令 :bin/hdfs dfsadmin -report 查看hdfs的各节点状态信息bin/hdfs haadmin -getServiceState nn1 获取一个namenode节点的HA状态sbin/hadoop-daemon.sh start namenode 单独启动一个namenode进程./hadoop-daemon.sh start zkfc 单独启动一个zkfc进程