机器分布
hadoop1 192.168.56121
hadoop2 192.168.56122
hadoop3 192.168.56123
准备安装包
jdk-7u71-linux-x64.tar.gz
zookeeper-3.4.9.tar.gz
hadoop-2.9.2.tar.gz
把安装包上传到三台机器的/usr/local目录下并解压
配置hosts
echo "192.168.56.121 hadoop1" >> /etc/hostsecho "192.168.56.122 hadoop2" >> /etc/hostsecho "192.168.56.123 hadoop3" >> /etc/hosts
配置环境变量
/etc/profile
export HADOOP_PREFIX=/usr/local/hadoop-2.9.2export JAVA_HOME=/usr/local/jdk1.7.0_71
部署zookeeper
创建zoo用户
useradd zoopasswd zoo
修改zookeeper目录的属主为zoo
chown zoo:zoo -R /usr/local/zookeeper-3.4.9
修改zookeeper配置文件
到/usr/local/zookeeper-3.4.9/conf目录
cp zoo_sample.cfg zoo.cfgvi zoo.cfgtickTime=2000initLimit=10syncLimit=5dataDir=/usr/local/zookeeper-3.4.9clientPort=2181server.1=hadoop1:2888:3888server.2=hadoop2:2888:3888server.3=hadoop3:2888:3888
创建myid文件放在/usr/local/zookeeper-3.4.9目录下,myid文件中只保存1-255的数字,与zoo.cfg中server.id行中的id相同。
hadoop1中myid为1
hadoop2中myid为2
hadoop3中myid为3
在三台机器启动zookeeper服务
[zoo@hadoop1 zookeeper-3.4.9]$ bin/zkServer.sh start
验证zookeeper
[zoo@hadoop1 zookeeper-3.4.9]$ bin/zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfgMode: follower
配置Hadoop
创建用户
useradd hadooppasswd hadoop
修改hadoop目录属主为hadoop
chmod hadoop:hadoop -R /usr/local/hadoop-2.9.2
创建目录
mkdir /hadoop1 /hadoop2 /hadoop3chown hadoop:hadoop /hadoop1chown hadoop:hadoop /hadoop2chown hadoop:hadoop /hadoop3
配置互信
ssh-keygenssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop1ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop2ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop3#使用如下命令测试互信ssh hadoop1 datessh hadoop2 datessh hadoop3 date
配置环境变量
/home/hadoop/.bash_profile
export PATH=$JAVA_HOME/bin:$HADOOP_PREFIX/bin:$HADOOP_PREFIX/sbin:$PATH
配置参数
etc/hadoop/hadoop-env.sh
export JAVA_HOME=/usr/local/jdk1.7.0_71
etc/hadoop/core-site.xml
fs.defaultFS hdfs://ns hadoop.tmp.dir /usr/loca/hadoop-2.9.2/temp io.file.buffer.size 4096 ha.zookeeper.quorum hadoop1:2181,hadoop2:2181,hadoop3:2181
etc/hadoop/hdfs-site.xml
dfs.nameservices ns dfs.ha.namenodes.ns nn1,nn2 dfs.namenode.rpc-address.ns.nn1 hadoop1:9000 dfs.namenode.http-address.ns.nn1 hadoop1:50070 dfs.namenode.rpc-address.ns.nn2 hadoop2:9000 dfs.namenode.http-address.ns.nn2 hadoop2:50070 dfs.namenode.shared.edits.dir qjournal://hadoop1:8485;hadoop2:8485;hadoop3:8485/ns dfs.journalnode.edits.dir /hadoop1/hdfs/journal dfs.ha.automatic-failover.enabled true dfs.client.failover.proxy.provider.ns org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider dfs.ha.fencing.methods sshfence dfs.ha.fencing.ssh.private-key-files /home/hadoop/.ssh/id_rsa dfs.namenode.name.dir file:/hadoop1/hdfs/name,file:/hadoop2/hdfs/name dfs.datanode.data.dir file:/hadoop1/hdfs/data,file:/hadoop2/hdfs/data,file:/hadoop3/hdfs/data dfs.replication 2 dfs.webhdfs.enabled true dfs.hosts.exclude /usr/local/hadoop-2.9.2/etc/hadoop/excludes
etc/hadoop/mapred-site.xml
yarn-site.xml mapreduce.framework.name yarn yarn.nodemanager.aux-services mapreduce_shuffle yarn.nodemanager.aux-services.mapreduce_shuffle.class org.apache.hadoop.mapred.ShuffleHandler yarn.resourcemanager.hostname hadoop1
etc/hadoop/slaves
hadoop1hadoop2hadoop3
首次启动命令
1、首先启动各个节点的Zookeeper,在各个节点上执行以下命令:bin/zkServer.sh start2、在某一个namenode节点执行如下命令,创建命名空间hdfs zkfc -formatZK3、在每个journalnode节点用如下命令启动journalnodesbin/hadoop-daemon.sh start journalnode4、在主namenode节点格式化namenode和journalnode目录hdfs namenode -format ns5、在主namenode节点启动namenode进程sbin/hadoop-daemon.sh start namenode6、在备namenode节点执行第一行命令,这个是把备namenode节点的目录格式化并把元数据从主namenode节点copy过来,并且这个命令不会把journalnode目录再格式化了!然后用第二个命令启动备namenode进程!hdfs namenode -bootstrapStandbysbin/hadoop-daemon.sh start namenode7、在两个namenode节点都执行以下命令sbin/hadoop-daemon.sh start zkfc8、在所有datanode节点都执行以下命令启动datanodesbin/hadoop-daemon.sh start datanode
日常启停命令
#启动脚本,启动所有节点服务sbin/start-dfs.sh#停止脚本,停止所有节点服务sbin/stop-dfs.sh验证
jps检查进程
http://192.168.56.122:50070
http://192.168.56.121:50070
测试文件上传下载
#创建目录[hadoop@hadoop1 ~]$ hadoop fs -mkdir /test#验证[hadoop@hadoop1 ~]$ hadoop fs -ls /Found 1 itemsdrwxr-xr-x - hadoop supergroup 0 2019-04-12 12:16 /test #上传文件[hadoop@hadoop1 ~]$ hadoop fs -put /usr/local/hadoop-2.9.2/LICENSE.txt /test#验证[hadoop@hadoop1 ~]$ hadoop fs -ls /test Found 1 items-rw-r--r-- 2 hadoop supergroup 106210 2019-04-12 12:17 /test/LICENSE.txt#下载文件到/tmp[hadoop@hadoop1 ~]$ hadoop fs -get /test/LICENSE.txt /tmp#验证[hadoop@hadoop1 ~]$ ls -l /tmp/LICENSE.txt -rw-r--r--. 1 hadoop hadoop 106210 Apr 12 12:19 /tmp/LICENSE.txt
参考: