伪分布式 (single node setup)
---------------------------
安装jdk、配置环境变量,测试
rpm -i jdk-7u67-linux-x64.rpm #安装jdk
cd /usr/java/jdk1.7.0_67/ #进入jdk安装目录,准备配置环境变量
pwd #查看当前目录并复制
vi + /etc/profile #替换配置复制的路径
. /etc/profile #启动jdk
jps #检测安装jdk是否安装成功
ssh localhost
ll -a #发现 .ssh文件
cd .ssh/
免秘钥
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
hadoop包安装并配置环变:hadoop-2.6.5.tar.gz
Hadoop的第二次JAVA_HOME 环境变量配置
vi hadoop-env.sh
vi mapred-env.sh
vi yarn-env.sh
配置core-site.xml
vi core-site.xml
<property>
<name>fs.defaultFS</name>
<value>hdfs://node001:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/var/sxt/hadoop/pseudo</value>
</property>
配置hdfs-site.xml
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>node001:50090</value>
</property>
配置slaves文件
vi slaves node001
格式化hdfs
hdfs namenode -format (只能格式化一次,再次启动集群不要执行)
启动集群
start-dfs.sh
角色进程查看:jps
帮助: hdfs
hdfs dfs
查看web UI: IP:50070
创建目录:hdfs dfs -mkdir -p /user/root
查看目录: hdfs dfs -ls /
上传文件: hdfs dfs -put hadoop-2.6.5.tar.gz /user/root
停止集群:stop-dfs.sh
全分布安装
---------------------------------------------
前期准备:
jdk
hostname
hosts
date
安全机制
firewall
windows 域名映射
节点: node06/07/08/09
全分布分配方案:
NN SNN DN
NODE06 *
NODE07 * *
NODE08 *
NODE09 *
节点状态:
node06: 伪分布
node07/08/09 : ip配置完成
建立各节点通讯(hosts)
设置时间同步:date -s “xxxx-x-xx xx:xx:xx”
秘钥分发:
在每个节点上登录一下自己:产生.ssh目录
从node001向node002/node003/node004分发公钥 (公钥的名称要变化)
scp id_dsa.pub node002:`pwd`/node001.pub
各节点把node01的公钥追加到认证文件里:
cat ~/node001.pub >> ~/.ssh/authorized_keys
node002/node003/node004安装jdk环境,node001分发profile给其他节点,并重读配置文件
分发hadoop部署程序2.6.5 到其他节点
copy node001 下的 hadoop 为 hadoop-local (管理脚本只会读取hadoop目录)
[root@node06 etc]# cp -r hadoop hadoop-local
配置core-site.xml
配置hdfs-site.xml
配置slaves
分发sxt到其他node002,node003,node004节点
格式化集群:hdfs namenode -format
启动集群:start-dfs.sh
Jps 查看各节点进程启动情况
HA
------------------------------------------
NN1 NN2 DN ZK ZKFC JNN
NODE06 * * *
NODE07 * * * * *
NODE08 * * *
NODE09 * *
两个nn节点免秘钥
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
-------------------------
进入hadoop-2.6.5/etc目录 (可以通过变量:cd $HADOOP_HOME)
拷贝hadoop 为 hadoop-full
hdfs.xml
---------------------------------------
去掉snn的配置
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>node002:50090</value>
</property>
增加:
<property>
<name>dfs.nameservices</name>
<value>mycluster</value>
</property>
<property>
<name>dfs.ha.namenodes.mycluster</name>
<value>nn1,nn2</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn1</name>
<value>node001:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>node002:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn1</name>
<value>node001:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn2</name>
<value>node002:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://node001:8485;node002:8485;node003:8485/mycluster</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/var/sxt/hadoop/ha/journalnode</value>
</property>
<property>
<name>dfs.client.failover.proxy.provider.mycluster</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<property>
<name>dfs.ha.fencing.methods</name>
<value>sshfence</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/root/.ssh/id_dsa</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
core-site.xml
-----------------------------------------
hadoop.tmp.dir的配置要变更:/var/sxt/hadoop-2.6/ha
<property>
<name>fs.defaultFS</name>
<value>hdfs://mycluster</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>node002:2181,node003:2181,node004:2181</value>
</property>
分发 hdfs.xml 和core.xml 给其他节点
scp core-site.xml hdfs-site.xml node002:`pwd`
scp core-site.xml hdfs-site.xml node003:`pwd`
scp core-site.xml hdfs-site.xml node004:`pwd`
安装zookeeper集群:
----------------------------
1.3节点 java 安装
2.所有集群节点创建目录: mkdir opt/sxt
3.zk压缩包解压在其他路径下::
# tar xf zookeeper-3.4.6.tar.gz -C /opt/sxt/
4.进入conf目录,拷贝zoo_sample.cfg zoo.cfg 并配置
dataDir,集群节点。
cd /opt/sxt/conf/
mv zoo_sample.cfg zoo.cfg
dataDir=/var/sxt/zk
server.1=node002:2888:3888
server.2=node003:2888:3888
server.3=node004:2888:3888
2888 主存节点之间的通信端口;3888当发生主挂断之后他的选举机制采用的端口
5.单节点配置环境变量、并分发 ZOOKEEPER_PREFIX,共享模式读取profile
scp -r zookeeper-3.4.6/ node003:`pwd`
scp -r zookeeper-3.4.6/ node004:`pwd`
6. 共享创建 /var/sxt/zk目录,进入各自目录 分别输出1,2,3 至文件 myid
mkdir -p /var/sxt/zk
在
echo 1 > /var/sxt/zk/myid
cat /var/sxt/zk/myid
echo 2 > /var/sxt/zk/myid
cat /var/sxt/zk/myid
echo 3 > /var/sxt/zk/myid
cat /var/sxt/zk/myid
配置zookeeper环境变量
export ZOOKEEPER_HOME=/opt/sxt/zookeeper-3.4.6
PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOM
E/bin
分发环境变量配置
scp /etc/profile node003:/etc/
scp /etc/profile node004:/etc/
7. 共享启动zkServer.sh start 集群
8.启动客户端 help命令查看
6,7,8节点启动jn 集群
-------------------------
hadoop-daemon.sh start journalnode
随意找一个nn节点格式化:
[root@node06 hadoop]# hdfs namenode -format
启动该节点:
[root@node06 hadoop]# hadoop-daemon.sh start namenode
另一nn节点同步:
[root@node07 sxt]# hdfs namenode -bootstrapStandby
(同步成功,会发现同步另一个nn节点的clusterID 不是秘钥分发,而是同步过来的)
cat /var/sxt/hadoop/ha/dfs/name/current/VERSION
格式化zkfc,在zookeeper中可见目录创建:
[root@node06 hadoop]# hdfs zkfc -formatZK
(ha.ActiveStandbyElector: Successfully created /hadoop-ha/mycluster in ZK.)
##进入zookeeper
zkCli.sh
在zookeeper 客户端可见:
[zk: localhost:2181(CONNECTED) 1] ls /
[hadoop-ha, zookeeper]
[zk: localhost:2181(CONNECTED) 2] ls /hadoop-ha
[mycluster]
启动hdfs集群;
start-dfs.sh
再次查看zk客户端,可见:
[zk: localhost:2181(CONNECTED) 9] ls /hadoop-ha/mycluster
[ActiveBreadCrumb, ActiveStandbyElectorLock]
或者两个目录的数据,谁是主谁被创建:
[zk: localhost:2181(CONNECTED) 11] get /hadoop-ha/mycluster/ActiveBreadCrumb
如果再次启动
首先先把zookeeper启动:zkServer.sh start
再启动dfs:start-dfs.sh
关闭程序时先把dfs关闭:stop-dfs.sh
再关闭zookeeper:zkServer.sh stop
mr-hd2.x yarn
------------------------------------------------
NN1 NN2 DN ZK ZKFC JNN RS NM
NODE06 * * *
NODE07 * * * * * *
NODE08 * * * * *
NODE09 * * *
node001:
两个rm节点互免秘钥:
003节点 .ssh 目录下: ssh-keygen -t dsa -P '' -f ./id_dsa
cat ~id_dsa.pub >> authorized_keys
scp id_dsa.pub root@node004:`pwd`/node003.pub
004节点 .ssh 目录下 :
cat node003.pub >> authorized_keys
ssh-keygen -t dsa -P '' -f ./id_dsa
cat ~id_dsa.pub >> authorized_keys
scp id_dsa.pub root@node003:`pwd`/node004.pub
003节点 .ssh 目录下:
cat node004.pub >> authorized_keys
(别忘了退出)
重命名: mv mapred-site.xml.template mapred-site.xml
mapred-site.xml
==============================
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
=================================
yarn-site.xml:
=================================
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>cluster1</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>node08</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>node09</value>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>node07:2181,node08:2181,node09:2181</value>
</property>
分发两个文件到:002,003,004节点
scp mapred-site.xml yarn-site.xml node002:`pwd`
scp mapred-site.xml yarn-site.xml node003:`pwd`
scp mapred-site.xml yarn-site.xml node004:`pwd`
启动:node001:
1 zookeeper 命令:zkServer.sh start
2 hdfs (注意,有一个脚本不要用,start-all)start-dfs.sh
如果nn 和 nn2没有启动,需要在node001,node002分别手动启动:
hadoop-daemon.sh start namenode
3 start-yarn.sh (启动nodemanager)
4 在003,004节点分别执行脚本: yarn-daemon.sh start resourcemanager
UI访问: ip:8088
停止:
第一步:
node003,node004: yarn-daemon.sh stop resourcemanager (停止resourcemanager)
第二步:
node001: stop-dfs.sh
node001: stop-yarn.sh (停止nodemanager)
或者直接:stop-all