下载Hadoop
从北京理工大学的镜像上下载Hadoop:
wget http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.10.0/hadoop-2.10.0.tar.gz
创建文件夹
mkdir /usr/local/hadoop
解压
tar -xzvf hadoop-2.10.0.tar.gz -C /usr/local/hadoop
配置环境变量
追加Hadoop的环境变量到/etc/profile文件中
cat >> /etc/profile <<EOF
#Hadoop
export HADOOP_HOME=/usr/local/hadoop/hadoop-2.10.0
export PATH=$PATH:$HADOOP_HOME/bin
EOF
使环境变量生效
source /etc/profile
修改配置文件
修改core-site.xml配置文件
vi /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/core-site.xml
修改其内容为:
hadoop.tmp.dir
file:/usr/local/hadoop/tmp
Abase for other temporary directories.
fs.defaultFS
hdfs://onemore-hadoop-master:9000
修改hdfs-site.xml配置文件
vi /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/hdfs-site.xml
修改其内容为:
dfs.replication
3
dfs.name.dir
/usr/local/hadoop/hdfs/name
dfs.data.dir
/usr/local/hadoop/hdfs/data
复制mapred-site.xml.template为mapred-site.xml
cp /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/mapred-site.xml.template /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/mapred-site.xml
再修改mapred-site.xml配置文件
vi /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/mapred-site.xml
修改其内容为:
mapreduce.framework.name
yarn
mapred.job.tracker
http://onemore-hadoop-master:9001
修改yarn-site.xml配置文件
vi /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/yarn-site.xml
修改其内容为:
yarn.nodemanager.aux-services
mapreduce_shuffle
yarn.resourcemanager.hostname
onemore-hadoop-master
新建masters配置文件
vi /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/masters
新增内容为:
onemore-hadoop-master
配置slaves文件
vi /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/slaves
修改其内容为:
onemore-hadoop-slave1
onemore-hadoop-slave2
onemore-hadoop-slave3
从节点配置
下面以onemore-hadoop-slave1从节点为例进行叙述,您需参照以下步骤完成onemore-hadoop-slave2和onemore-hadoop-slave3从节点的配置。
下载Hadoop
还是从北京理工大学的镜像上下载Hadoop(如果下载速度慢,可以在主节点上发送到从节点):
wget http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.10.0/hadoop-2.10.0.tar.gz
创建文件夹
mkdir /usr/local/hadoop
解压
tar -xzvf hadoop-2.10.0.tar.gz -C /usr/local/hadoop
配置环境变量
追加Hadoop的环境变量到/etc/profile文件中
cat >> /etc
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
/profile <<EOF
#Hadoop
export HADOOP_HOME=/usr/local/hadoop/hadoop-2.10.0
export PATH=$PATH:$HADOOP_HOME/bin
EOF
使环境变量生效
source /etc/profile
修改配置文件
删除slaves文件
rm -rfv /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/slaves
在主节点上把5个配置文件发送到从节点上
scp -r /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/core-site.xml onemore-hadoop-slave1:/usr/local/hadoop/hadoop-2.10.0/etc/hadoop/
scp -r /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/hdfs-site.xml onemore-hadoop-slave1:/usr/local/hadoop/hadoop-2.10.0/etc/hadoop/
scp -r /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/mapred-site.xml onemore-hadoop-slave1:/usr/local/hadoop/hadoop-2.10.0/etc/hadoop/
scp -r /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/yarn-site.xml onemore-hadoop-slave1:/usr/local/hadoop/hadoop-2.10.0/etc/hadoop/
scp -r /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/masters onemore-hadoop-slave1:/usr/local/hadoop/hadoop-2.10.0/etc/hadoop/
启动Hadoop集群
格式化namenode
第一次启动服务前需要执行词操作,以后就不需要执行了。
hadoop namenode -format
启动hadoop
/usr/local/hadoop/hadoop-2.10.0/sbin/start-all.sh
访问http://onemore-hadoop-master:50070/,就可以查看Hadoop集群的相关信息了,如图:
常用命令
查看Hadoop集群的状态
hadoop dfsadmin -report
重启Hadoop
/usr/local/hadoop/hadoop-2.10.0/sbin/stop-all.sh
/usr/local/hadoop/hadoop-2.10.0/sbin/start-all.sh
启动dfs服务
/usr/local/hadoop/hadoop-2.10.0/sbin/start-dfs.sh
常见错误
Error: JAVA_HOME is not set and could not be found.
这个错误大概意思是没有找到JDK的环境变量,可以修改hadoop-env.sh。
vi /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/hadoop-env.sh
增加JDK的环境变量,比如:
export JAVA_HOME=/usr/local/java/jdk1.8.0_231
因为是在主节点上修改的,还需要发送到各个从节点:
scp -r /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/hadoop-env.sh onemore-hadoop-slave1:/usr/local/hadoop/hadoop-2.10.0/etc/hadoop/
scp -r /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/hadoop-env.sh onemore-hadoop-slave2:/usr/local/hadoop/hadoop-2.10.0/etc/hadoop/
scp -r /usr/local/hadoop/hadoop-2.10.0/etc/hadoop/hadoop-env.sh onemore-hadoop-slave3:/usr/local/hadoop/hadoop-2.10.0/etc/hadoop/