目录
1.打开Xftp,连接虚拟机,在/opt目录下新建两个文件夹
5.修改hadoop313文件及子目录文件的所有权为root
(一)新建一个虚拟机
配置如下,具体步骤可以参考我的另一篇博文《CentOS7中新建虚拟机详细步骤》
(二)配置网络
参考我的博文:《Linux网关设置》
(三)安装vim工具
[root@localhost ~]# yum -y install vim
(四)设置ssh免密登录
参考我的博文《Linux设置ssh免密登录》
(五)设置时间同步
参考我的博文《Linux中CentOS7时间与网络时间orWindows同步的方法》
(六)修改主机名
1.方法一
[root@localhost .ssh]# vim /etc/hostname
2.方法二
[root@localhost .ssh]# hostnamectl set-hostname lxm148
[root@localhost .ssh]# bash
[[email protected]]#
此时ping ip地址或主机名都可以连接上
[root@localhost .ssh]# ping 192.168.180.148
[root@localhost .ssh]# ping lxm148
(七)给主机文件添加IP名称映射
[root@localhost .ssh]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.180.148 lxm148
192.168.180.141 lxm141
修改后就可以直接ping主机名连接其他虚拟机
[root@localhost .ssh]# ping lxm141
(八)安装JDK8
参考我的博文《Linux安装JDK8详细步骤》
(九)安装Hadoop
1.打开Xftp,连接虚拟机,在/opt目录下新建两个文件夹
2.将Hadoop压缩包传输到install文件夹中
3.解压文件到指定目录
[root@localhost install]# tar -zxvf ./hadoop-3.1.3.tar.gz -C ../soft/
4.更改/opt/soft/目录下hadoop的文件名
[root@localhost soft]# mv hadoop-3.1.3/ hadoop313
5.修改hadoop313文件及子目录文件的所有权为root
[root@lxm148 soft]# chown -R root:root /opt/soft/hadoop313/
6.切换当前目录
[root@lxm148 hadoop]# pwd
/opt/soft/hadoop313/etc/hadoop
7.修改core-site.xml文件
[root@lxm148 hadoop]# vim ./core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://lxm148:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/soft/hadoop313/data</value>
<description>namenode上本地的hadoop临时文件夹</description>
</property>
<property>
<name>hadoop.http.staticuser.user</name>
<value>root</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
<description>读写队列缓存:128K</description>
</property>
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
</configuration>
8.创建data文件
切换目录
[root@lxm148 hadoop313]# pwd
/opt/soft/hadoop313
创建data文件
[root@lxm148 hadoop313]# mkdir data
[root@lxm148 hadoop313]# ll
total 176
drwxr-xr-x. 2 root root 183 Sep 12 2019 bin
drwxr-xr-x. 2 root root 6 Feb 2 15:11 data
drwxr-xr-x. 3 root root 20 Sep 12 2019 etc
drwxr-xr-x. 2 root root 106 Sep 12 2019 include
drwxr-xr-x. 3 root root 20 Sep 12 2019 lib
drwxr-xr-x. 4 root root 288 Sep 12 2019 libexec
-rw-rw-r--. 1 root root 147145 Sep 4 2019 LICENSE.txt
-rw-rw-r--. 1 root root 21867 Sep 4 2019 NOTICE.txt
-rw-rw-r--. 1 root root 1366 Sep 4 2019 README.txt
drwxr-xr-x. 3 root root 4096 Sep 12 2019 sbin
drwxr-xr-x. 4 root root 31 Sep 12 2019 share
9.配置JAVA_HOME
[root@lxm148 hadoop]# vim ./hadoop-env.sh
10.修改hdfs-site.xml文件
[root@lxm148 hadoop]# vim ./hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
<description>hadoop中每一个block文件的备份数量</description>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/opt/soft/hadoop313/data/dfs/name</value>
<description>namenode上存储hdfsq名字空间元数据的目录</description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/opt/soft/hadoop313/data/dfs/data</value>
<description>datanode上数据块的物理存储位置目录</description>
</property>
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
<description>关闭权限验证</description>
</property>
</configuration>
11.data文件夹下创建文件
[root@lxm148 data]# mkdir -p ./dfs/name
[root@lxm148 data]# mkdir -p ./dfs/data
12.修改mapred-site.xml文件
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
<description>job执行框架: local, classic or yarn</description>
<final>true</final>
</property>
<property>
<name>mapreduce.application.classpath</name>
<value>/opt/soft/hadoop313/etc/hadoop:/opt/soft/hadoop313/share/hadoop/common/lib/*:/opt/soft/hadoop313/share/hadoop/common/*:/opt/soft/hadoop313/share/hadoop/hdfs/*:/opt/soft/hadoop313/share/hadoop/hdfs/lib/*:/opt/soft/hadoop313/share/hadoop/mapreduce/*:/opt/soft/hadoop313/share/hadoop/mapreduce/lib/*:/opt/soft/hadoop313/share/hadoop/yarn/*:/opt/soft/hadoop313/share/hadoop/yarn/lib/*</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>lxm148:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>lxm148:19888</value>
</property>
<property>
<name>mapreduce.map.memory.mb</name>
<value>1024</value>
</property>
<property>
<name>mapreduce.reduce.memory.mb</name>
<value>1024</value>
</property>
</configuration>
13.修改yarn-site.xml
[root@lxm148 hadoop]# vim ./yarn-site.xml
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.resourcemanager.connect.retry-interval.ms</name>
<value>20000</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
<property>
<name>yarn.nodemanager.localizer.address</name>
<value>lxm148:8040</value>
</property>
<property>
<name>yarn.nodemanager.address</name>
<value>lxm148:8050</value>
</property>
<property>
<name>yarn.nodemanager.webapp.address</name>
<value>lxm148:8042</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.local-dirs</name>
<value>/opt/soft/hadoop313/yarndata/yarn</value>
</property>
<property>
<name>yarn.nodemanager.log-dirs</name>
<value>/opt/soft/hadoop313/yarndata/log</value>
</property>
</configuration>
14.创建yarndata文件
回到这个路径:/opt/soft/hadoop313/
[root@lxm148 hadoop313]# mkdir yarndata
15.配置HADOOP_HOME环境变量
[root@lxm148 hadoop]# vim /etc/profile
在JAVA_HOME下面接着配置HADOOP_HOME
# HADOOP_HOME
export HADOOP_HOME=/opt/soft/hadoop313
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HADOOP_HOME/lib
export HDFS_NAMENODE_USER=root
export HDFS_DATANODE_USER=root
export HDFS_SECONDARYNAMENODE_USER=root
export HDFS_JOURNALNODE_USER=root
export HDFS_ZKFC_USER=root
export YARN_RESOURCEMANAGER_USER=root
export YARN_NODEMANAGER_USER=root
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_YARN_HOME=$HADOOP_HOME
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_LIBEXEC_DIR=$HADOOP_HOME/libexec
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
16.重启/etc/profile文件
[root@lxm148 hadoop]# source /etc/profile
[root@lxm148 hadoop]# echo $HADOOP_HOME
17.初始化
[root@lxm148 yarndata]# hdfs namenode -format
18.启动服务
[root@lxm148 yarndata]# start-all.sh
19.jps
这里要注意:
如果输入jps命令后启动的数量少于6个,可能是缺少的那个xml文件或/etc/profile中的配置出错,需要仔细检查
如果配置没问题,可以输入命令单独启用服务
hdfs --daemon start datanode 各个服务组件逐一启动/停止 (1)分别启动/停止HDFS组件 hdfs --daemon start/stop namenode/datanode/secondarynamenode (2)启动/停止YARN yarn --daemon start/stop resourcemanager/nodemanager
20.网页连接服务
http://192.168.180.148:9870
也可以在网页输入
http://lxm147:9870
此时我门需要在windows上进行主机映射
添加主机映射
有的电脑可能无法直接在里面输入并保存,需要放到桌面上,配置完成后再进行保存,再放回C:\Windows\System32\drivers\etc目录下
21.上传一个文件
切换到这个目录下:
/opt/soft/hadoop313/etc/hadoop
[root@lxm148 hadoop]# hdfs dfs -put mapred-env.cmd /
2023-02-02 16:03:55,911 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
2023-02-02 16:03:58,392 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false
刷新网页
Block默认所占空间为128MB
22.停用服务
[root@lxm148 hadoop]# stop-all.sh
下次启动直接输入以下命令即可:
[root@lxm148 hadoop]# start-all.sh