hadoop usr/hadoop/app/hadoop
jdk /usr/local/jdk-xxx
zookeeper /usr/hadoop/app/hadoop
软件去官网下载既可
lk | slave2 | slave2 | slave3 | slave4 | slave5 |
---|---|---|---|---|---|
namenode | y | y | n | n | n |
datanode | n | n | y | y | y |
resourcemanager | y | y | n | n | n |
jouralnode | y | y | y | y | y |
zookeeper | y | y | y | n | n |
注意不能用root用户,可以新建一个或者用一个普通账户就可以
我这里用的是qsb,home路径为/home/qsb
查看防火墙状态
service iptables status
然后永久关闭防火墙,使用chkconfig iptables off命令,此时当前虚拟机的防火墙还没有关闭。只有在关机重启后才能生效。
在家目录下创建tools文件夹,然后创建如下三个文件
这个工具很方便,前面的配置也可以用
#!/bin/bash
#set -x
#判断参数是否小于3个,因为运行deploy.sh需要有源文件(或源目录)和目标文件(或目标目录),
#以及在MachineTag(哪些主机)上执行,这个标记就是上面deploy.conf中的标记 ,如 zookeeper、all等
#使用实例如:我们把app目录下的所有文件复制到远程标记为zookeeper的主机上的/home/hadoop/app目录下
# ./deploy.sh /home/hadoop/app /home/hadoop/app zookeeper
#执行完上述命令后,shell脚本文件就自动把CDHNode1下的app目录中的文件复制到三个zookeeper节点的app目录下
if [ $# -lt 3 ]
then
echo "Usage: ./deply.sh srcFile(or Dir) descFile(or Dir) MachineTag"
echo "Usage: ./deply.sh srcFile(or Dir) descFile(or Dir) MachineTag confFile"
exit
fi
#源文件或源目录
src=$1
#目标文件或目标目录
dest=$2cat
#标记
tag=$3
#判断是否使用deploy.conf配置文件,或者自己指定配置文件
if [ 'a'$4'a' == 'aa' ]
then
confFile=/home/hadoop/tools/deploy.conf
else
confFile=$4
fi
#判断配置文件是否是普通文本文件
if [ -f $confFile ]
then
#判断原件是普通文件还是目录
if [ -f $src ]
then
#如果是普通文件就把解析出标记对应的主机名的ip
for server in `cat $confFile|grep -v '^#'|grep ','$tag','|awk -F',' '{print $1}'`
do
scp $src $server":"${dest} #使用循环把文件复制到目标ip上的相应目录下
done
elif [ -d $src ]
then
for server in `cat $confFile|grep -v '^#'|grep ','$tag','|awk -F',' '{print $1}'`
do
scp -r $src $server":"${dest}
done
else
echo "Error: No source file exist"
fi
else
echo "Error: Please assign config file or run deploy.sh command with deploy.conf in same directory"
fi
#!/bin/bash
#set -x
#判断参数个数
#实例如:显示所有节点的java进程,中间用引号的就是命令,这个命令将在所以节点上执行
#./runRemoteCmd.sh "jps" all
if [ $# -lt 2 ]
then
echo "Usage: ./runRemoteCmd.sh Command MachineTag"
echo "Usage: ./runRemoteCmd.sh Command MachineTag confFile"
exit
fi
cmd=$1
tag=$2
if [ 'a'$3'a' == 'aa' ]
then
confFile=/home/hadoop/tools/deploy.conf
else
confFile=$3
fi
if [ -f $confFile ]
then
for server in `cat $confFile|grep -v '^#'|grep ','$tag','|awk -F',' '{print $1}'`
do
echo "*******************$server***************************"
ssh $server "source /etc/profile; $cmd"
# 注意在使用的时候要根据自己设置的环境变量的配置位置,给定相应的source源 ,
# 如 我把环境变量设/home/hadoop/.bash_profile文件下,就需要上面这条命令改为
# ssh $server "source /home/hadoop/.bash_profile;$cmd"
#上面的例子:这条命令就是在远程标记为tag的主机下执行这个命令jps。
done
else
echo "Error: Please assign config file or run deploy.sh command with deploy.conf in same directory"
fi
lk,all,zookeeper,journalnode,namenode,resourcemanager,
slave2,all,slave,zookeeper,journalnode,namenode,datanode,resourcemanager,
slave3,all,slave,zookeeper,journalnode,datanode,nodemanager,
slave4,all,slave,journalnode,datanode,nodemanager,
slave5,all,slave,journalnode,datanode,nodemanager,
sudo chmod u+x deploy.sh
sudo chmod u+x runRemoteCmd.sh
为了方便起见,将tools目录添加到环境变量中
然后就可以通过runRemoteCmd.sh
脚本,一键创建所有节点的软件安装目录/usr/hadoop/app
。
卸载原有的openjdk
rpm -qa | grep java
rpm -e --nodeps xxxx
export JAVA_HOME=/usr/local/jdk-xxx
export CLASSPATH=.:$JAVA_HOME/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
记得source一下
然后查看:
java -version
显示是你下载的版本就行
下载好Zookeeper,然后解压到一个路径,我的机子上是/usr/hadoop/app/zookeeper
修改zookeeper的配置文件
conf/
文件夹下面
创建zoo.cfg文件
原来文件夹下面有一个zoo_sample.cfg
cp zoo_sample.cfg zoo.cfg
#添加下面的
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#数据文件目录与日志目录 ,这两个可根据自己的来
dataDir=/data/hadoop/data/zookeeper/zkdata
dataLogDir=/data/hadoop/data/zookeeper/zkdatalog
# the port at which the clients will connect
clientPort=2181
#server.服务编号=主机名称:Zookeeper不同节点之间同步和通信的端口:选举端口(选举leader)
server.1=lk:2888:3888
server.2=slave2:2888:3888
server.3=slave3:2888:3888
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
/etc/profile
中配置export ZOOKEEPER_HOME=/home/hadoop/app/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
记得source一下
deploy.sh zookeeper /usr/hadoop/app/ zookeeper
runRemoteCmd.sh "mkdir -p /home/hadoop/data/zookeeper/zkdata" zookeeper //创建数据目录
runRemoteCmd.sh "mkdir -p /home/hadoop/data/zookeeper/zkdatalog" zookeeper //创建日志目录
cd /data/hadoop/data/zookeeper/zkdata
vim myid
根据前面的server.x来输入
在这里lk,slave2,slave3中分别填入1,2,3
runRemoteCmd.sh "/home/hadoop/app/zookeeper/bin/zkServer.sh start" zookeeper
runRemoteCmd.sh "jps" zookeeper
或者
runRemoteCmd.sh "/home/hadoop/app/zookeeper/bin/zkServer.sh status" zookeeper
如果一个节点为leader,另2个节点为follower,则说明Zookeeper安装成功。
下载hadoop,解压到/usr/hadoop/app/hadoop中
配置环境变量
HADOOP_HOME=/usr/hadoop/app/hadoop
PATH=$HADOOP_HOME/bin:$PATH
切换到usr/hadoop/app/hadoop/etc/hadoop/
录下,修改配置文件。
配置hadoop-env.sh
vi hadoop-env.sh
export JAVA_HOME=/usrlocal/jdk1.7.0_79
vi core-site.xml
<configuration>
<property>
<name>fs.defaultFSname>
<value>hdfs://cluster1value>
property>
<property>
<name>hadoop.tmp.dirname>
<value>/data/hadoop/data/tmpvalue>
property>
<property>
<name>ha.zookeeper.quorumname>
<value>lk:2181,slave2:2181,slave3:2181,slave4:2181,slave5:2181value>
property>
configuration>
vi hdfs-site.xml
<configuration>
<property>
<name>dfs.replicationname>
<value>3value>
property>
<property>
<name>dfs.permissionsname>
<value>falsevalue>
property>
<property>
<name>dfs.permissions.enabledname>
<value>falsevalue>
property>
<property>
<name>dfs.nameservicesname>
<value>cluster1value>
property>
<property>
<name>dfs.ha.namenodes.cluster1name>
<value>lk,slave2value>
property>
<property>
<name>dfs.namenode.rpc-address.cluster1.lkname>
<value>lk:9000value>
property>
<property>
<name>dfs.namenode.http-address.cluster1.lkname>
<value>lk:50070value>
property>
<property>
<name>dfs.namenode.rpc-address.cluster1.slave2name>
<value>slave2:9000value>
property>
<property>
<name>dfs.namenode.http-address.cluster1.slave2name>
<value>slave2:50070value>
property>
<property>
<name>dfs.ha.automatic-failover.enabledname>
<value>truevalue>
property>
<property>
<name>dfs.namenode.shared.edits.dirname>
<value>qjournal://lk:8485;slave2:8485;slave3:8485;slave4:8485;slave5:8485/cluster1value>
property>
<property>
<name>dfs.client.failover.proxy.provider.cluster1name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvidervalue>
property>
<property>
<name>dfs.journalnode.edits.dirname>
<value>/tmp/hadoop/data/journaldata/jnvalue>
property>
<property>
<name>dfs.ha.fencing.methodsname>
<value>shell(/bin/true)value>
property>
<property>
<name>dfs.ha.fencing.ssh.private-key-filesname>
<value>/home/qsb/.ssh/id_rsavalue>
property>
<property>
<name>dfs.ha.fencing.ssh.connect-timeoutname>
<value>10000value>
property>
<property>
<name>dfs.namenode.handler.countname>
<value>100value>
property>
configuration>
vim slaves
slave3
slave4
slave5
<configuration>
<property>
<name>mapreduce.framework.namename>
<value>yarnvalue>
property>
configuration>
<configuration>
<property>
<name>yarn.resourcemanager.connect.retry-interval.msname>
<value>2000value>
property>
<property>
<name>yarn.resourcemanager.ha.enabledname>
<value>truevalue>
property>
<property>
<name>yarn.resourcemanager.ha.automatic-failover.enabledname>
<value>truevalue>
property>
<property>
<name>yarn.resourcemanager.ha.automatic-failover.embeddedname>
<value>truevalue>
property>
<property>
<name>yarn.resourcemanager.cluster-idname>
<value>yarn-rm-clustervalue>
property>
<property>
<name>yarn.resourcemanager.ha.rm-idsname>
<value>rm1,rm2value>
property>
<property>
<name>yarn.resourcemanager.hostname.rm1name>
<value>lkvalue>
property>
<property>
<name>yarn.resourcemanager.hostname.rm2name>
<value>slave2value>
property>
<property>
<name>yarn.resourcemanager.recovery.enabledname>
<value>truevalue>
property>
<property>
<name>yarn.resourcemanager.zk.state-store.addressname>
<value>lk:2181,slave2:2181,slave3:2181,slave4:2181slave5:2181value>
property>
<property>
<name>yarn.resourcemanager.zk-addressname>
<value>lk:2181,slave2:2181,slave3:2181,slave4:2181slave5:2181value>
property>
<property>
<name>yarn.resourcemanager.address.rm1name>
<value>lk:8032value>
property>
<property>
<name>yarn.resourcemanager.scheduler.address.rm1name>
<value>lk:8034value>
property>
<property>
<name>yarn.resourcemanager.webapp.address.rm1name>
<value>lk:8088value>
property>
<property>
<name>yarn.resourcemanager.address.rm2name>
<value>slave2:8032value>
property>
<property>
<name>yarn.resourcemanager.scheduler.address.rm2name>
<value>slave2:8034value>
property>
<property>
<name>yarn.resourcemanager.webapp.address.rm2name>
<value>slave2:8088value>
property>
<property>
<name>yarn.nodemanager.aux-servicesname>
<value>mapreduce_shufflevalue>
property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce_shuffle.classname>
<value>org.apache.hadoop.mapred.ShuffleHandlervalue>
property>
configuration>
runRemoteCmd.sh "mkdir -p /data/hadoop/data/name" all
runRemoteCmd.sh "mkdir -p /data/hadoop/data/hdfs/edits" all
runRemoteCmd.sh "mkdir -p /data/hadoop/data/datanode" all
runRemoteCmd.sh "mkdir -p /data/hadoop/data/journaldata/jn" all
runRemoteCmd.sh "mkdir -p /data/hadoop/data/tmp" all
runRemoteCmd.sh "touch /usr/hadoop/app/hadoop/etc/hadoop/excludes" all
runRemoteCmd.sh "mkdir -p /data/hadoop/data/pid" all
rm -rf /data/hadoop/data/name/*
rm -rf /data/hadoop/data/hdfs/edits/*
rm -rf /data/hadoop/data/datanode/*
rm -rf /data/hadoop/data/journaldata/jn/*
rm -rf /data/hadoop/data/tmp/
rm -rf /data/hadoop/data/name/*
rm -rf /data/hadoop/data/hdfs/edits/*
rm -rf /data/hadoop/data/datanode/*
rm -rf /data/hadoop/data/journaldata/jn/*
rm -rf /data/hadoop/data/tmp/*
runRemoteCmd.sh "/usr/hadoop/app/zookeeper/bin/zkServer.sh start" zookeeper
runRemoteCmd.sh "/usr/hadoop/app/hadoop/sbin/hadoop-daemon.sh start journalnode" all
bin/hdfs namenode -format / /namenode 格式化
bin/hdfs zkfc -formatZK //格式化高可用
bin/hdfs namenode //启动namenode
如果报错,记得看日志查找问题
bin/hdfs namenode -bootstrapStandby //同步主节点和备节点之间的元数据
runRemoteCmd.sh "/usr/hadoop/app/hadoop/sbin/hadoop-daemon.sh stop journalnode" all //然后停掉各节点的journalnode
sbin/start-dfs.sh
通过web界面查看namenode启动情况。
http://10.113.10.1:50070
一个active,一个standby(因为之前测试的时候把lk暂时关闭了,所以lk成了standby,slave2成了active)
启动成功之后,查看关闭其中一个namenode ,然后在启动namenode 观察切换的状况
关闭slave2
vi test1.txt //本地创建一个a.txt文件,内容自己写吧
hdfs dfs -mkdir /test //在hdfs上创建一个文件目录
hdfs dfs -put test1.txt /test //向hdfs上传一个文件
hdfs dfs -ls /test //查看a.txt是否上传成功
如果上面操作没有问题说明hdfs配置成功。
sbin/start-yarn.sh
sbin/yarn-daemon.sh start resourcemanager
网址是:10.113.10.1:8088
显示出集群的信息
如果是打开10.113.10.2:8088,那么会跳转到10.113.10.1的上面
bin/yarn rmadmin -getServiceState rm1
bin/yarn rmadmin -getServiceState rm2
#创建一个新的文件test2.txt
vim test2.txt
# 上传
hdfs dfs -put test2.txt /test
# 查看
hdfs dfs -ls /test
#测试
hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.4.jar wordcount /test/test2.txt /test/test2_out/
如果上面执行没有异常,说明YARN安装成功。
hadoop jar share/hadoop/mapreducehadoop-mapreduce-examples-2.7.4.jar pi 5 5 计算圆周率PI,任务5个,取样5个
sbin/yarn-daemon.sh stop resourcemanager
sbin/stop-yarn.sh
sbin/stop-dfs.sh
runRemoteCmd.sh "/usr/hadoop/app/zookeeper-3.4.10/bin/zkServer.sh stop" zookeeper
runRemoteCmd.sh "/usr/hadoop/app/zookeeper-3.4.10/bin/zkServer.sh start" zookeeper
sbin/start-dfs.sh
sbin/start-yarn.sh
sbin/yarn-daemon.sh start resourcemanager
至此,hadoop 分布式集群搭建完毕。
bin/hdfs dfsadmin -report
显示整个集群的信息
Starting namenodes on [slave2 lk]
lk: starting namenode, logging to /usr/hadoop/app/hadoop/logs/hadoop-qsb-namenode-lk.out
slave2: namenode running as process 13351. Stop it first.
slave3: datanode running as process 10874. Stop it first.
slave4: datanode running as process 10773. Stop it first.
slave5: datanode running as process 2446. Stop it first.
Starting journal nodes [lk slave2 slave3 slave4 slave5]
lk: journalnode running as process 8508. Stop it first.
slave4: journalnode running as process 10875. Stop it first.
slave5: journalnode running as process 2548. Stop it first.
slave2: journalnode running as process 13456. Stop it first.
slave3: journalnode running as process 10978. Stop it first.
Starting ZK Failover Controllers on NN hosts [slave2 lk]
lk: zkfc running as process 8795. Stop it first.
slave2: zkfc running as process 13672. Stop it first.
[qsb@lk hadoop]$ /bin/hdfs dfsadmin -report
-bash: /bin/hdfs: No such file or directory
[qsb@lk hadoop]$ bin/hdfs dfsadmin -report
Configured Capacity: 133037051904 (123.90 GB)
Present Capacity: 100757676032 (93.84 GB)
DFS Remaining: 100757311488 (93.84 GB)
DFS Used: 364544 (356 KB)
DFS Used%: 0.00%
Under replicated blocks: 0
Blocks with corrupt replicas: 0
Missing blocks: 0
Missing blocks (with replication factor 1): 0
-------------------------------------------------
Live datanodes (3):
Name: 10.113.10.4:50010 (slave4)
Hostname: slave4
Decommission Status : Normal
Configured Capacity: 44345683968 (41.30 GB)
DFS Used: 118784 (116 KB)
Non DFS Used: 10791297024 (10.05 GB)
DFS Remaining: 33554268160 (31.25 GB)
DFS Used%: 0.00%
DFS Remaining%: 75.67%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
Last contact: Sun Nov 05 22:01:14 CST 2017
Name: 10.113.10.3:50010 (slave3)
Hostname: slave3
Decommission Status : Normal
Configured Capacity: 44345683968 (41.30 GB)
DFS Used: 122880 (120 KB)
Non DFS Used: 10496921600 (9.78 GB)
DFS Remaining: 33848639488 (31.52 GB)
DFS Used%: 0.00%
DFS Remaining%: 76.33%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
Last contact: Sun Nov 05 22:01:13 CST 2017
Name: 10.113.10.5:50010 (slave5)
Hostname: slave5
Decommission Status : Normal
Configured Capacity: 44345683968 (41.30 GB)
DFS Used: 122880 (120 KB)
Non DFS Used: 10991157248 (10.24 GB)
DFS Remaining: 33354403840 (31.06 GB)
DFS Used%: 0.00%
DFS Remaining%: 75.21%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
Last contact: Sun Nov 05 22:01:14 CST 2017
首先还是推荐看日志,因为很多问题都在日志上写出来了
注意看网上教程的时候要根据自己本机的设置更改文件
我在hadoop配置的时候的问题主要是:
nohup: failed to run command ‘java’: No such file or directory
hadoop-env.sh
中 JAVA_HOME=你自己的java路径
2017-11-20 08:26:00,090 [myid:] - INFO [main:QuorumPeerConfig@134] - Reading configuration from: /usr/hadoop/app/zookeeper/bin/../conf/zoo.cfg
2017-11-20 08:26:00,110 [myid:] - INFO [main:QuorumPeer$QuorumServer@167] - Resolved hostname: 10.113.10.3 to address: /10.113.10.3
2017-11-20 08:26:00,110 [myid:] - INFO [main:QuorumPeer$QuorumServer@167] - Resolved hostname: 10.113.10.2 to address: /10.113.10.2
2017-11-20 08:26:00,113 [myid:] - INFO [main:QuorumPeer$QuorumServer@167] - Resolved hostname: 10.113.10.1 to address: /10.113.10.1
2017-11-20 08:26:00,113 [myid:] - INFO [main:QuorumPeerConfig@396] - Defaulting to majority quorums
2017-11-20 08:26:00,115 [myid:] - ERROR [main:QuorumPeerMain@85] - Invalid config, exiting abnormally
是myid文件出错
重新配置一下就可以了
hdfs dfsadmin -safemode leave
获取安全模式的状态:
hdfs dfsadmin -safemode get