Hadoop伪分布集群环境的搭建

Hadoop伪分布集群环境的搭建

一、关闭防火墙和禁用SELINUX

1、关闭防火墙
[root@bogon ~]# systemctl stop firewalld.service

[root@bogon ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

3月 30 05:58:13 localhost.localdomain systemd[1]: Starting firewalld - dynam...
3月 30 05:58:14 localhost.localdomain systemd[1]: Started firewalld - dynami...
3月 30 05:58:15 localhost.localdomain firewalld[777]: WARNING: ICMP type 'be...
3月 30 05:58:15 localhost.localdomain firewalld[777]: WARNING: beyond-scope:...
3月 30 05:58:15 localhost.localdomain firewalld[777]: WARNING: ICMP type 'fa...
3月 30 05:58:15 localhost.localdomain firewalld[777]: WARNING: failed-policy...
3月 30 05:58:15 localhost.localdomain firewalld[777]: WARNING: ICMP type 're...
3月 30 05:58:15 localhost.localdomain firewalld[777]: WARNING: reject-route:...
3月 29 22:03:42 bogon systemd[1]: Stopping firewalld - dynamic firewall da.....
3月 29 22:03:42 bogon systemd[1]: Stopped firewalld - dynamic firewall daemon.
Hint: Some lines were ellipsized, use -l to show in full.

2、禁用SELINUX

运行命令sudo vim /etc/sysconfig/selinux
找到行SELINUX=enforcing
替换为SELINUX=disabled
保存退出
reboot


# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted                                       

三、 配置hostname与IP地址之间的对应关系

[root@localhost ~]# vi /etc/hosts
[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.122.110 localhost

四、配置SSH免密码登录

[hadoop@localhost ~]$ mkdir .ssh
[hadoop@localhost ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:gs36CppDtcXbrBFQme8H8pYZ523rnZi9287QDCj8Zyc hadoop@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|    ..o          |
|   . o           |
|    o .          |
|   . O +..  .    |
|  . + % So.. .   |
| . . + X ooo  +  |
|. . . + . ...E + |
|.o . o     .B B  |
|o.  ...   .+ *++ |
+----[SHA256]-----+
[hadoop@localhost ~]$ cd .ssh/
[hadoop@localhost .ssh]$ ls
id_rsa  id_rsa.pub
[hadoop@localhost .ssh]$ cat id_rsa.pub >> authorized_keys
[hadoop@localhost .ssh]$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCigTeuw1spXoaqwdsROjamKwSsbZmtB1QZe2cvM6PVYu+bTTt47f7VyGQWZJqUz45QsJ5yAUwATHDHbDk0XVdXr8S6YDI/ON9aGDHNS316UNU2+gBwd52k1fnf/HKu7ivSuA1IKQwWkYudkSyUyg1yb+WHb7PlMsBXl+r909I9NrhOP+MT1SNeQMkiuDFjghpJg0abymECblwxIdZtG50cHE4xVlk8W2ZHECiAfvl6EjcYR0+SG2fi5QIVlCw7bJGkdan8maXSfLD3aGWeRKhKcebBdmQtF+4MJsiq0of+CAznfqvoTeklWL3gifmk1Akm7HDD8UlrDJ9ed4DDnvsv hadoop@localhost.localdomain
[hadoop@localhost .ssh]$ cd ..
[hadoop@localhost ~]$ chmod 700 .ssh
[hadoop@localhost ~]$ chmod 600 .ssh/*
[hadoop@localhost ~]$ ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:8tfa8326wjdlr8z6PLJh70gZ+RUlr3+QAN4g3qdp66o.
ECDSA key fingerprint is MD5:e3:25:85:67:f1:4c:45:04:6d:03:4f:41:f2:43:a3:73.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Last login: Mon Mar 29 22:23:11 2021
[hadoop@localhost ~]$ exit
登出
Connection to localhost closed.
[hadoop@localhost ~]$ ssh localhost
Last login: Mon Mar 29 22:26:17 2021 from ::1

五、JDK的安装

[hadoop@localhost ~]$ ls
hadoop-2.7.3.tar.gz              公共  视频  文档  音乐
jdk-14.0.2_linux-x64_bin.tar.gz  模板  图片  下载  桌面
[hadoop@localhost ~]$ mkdir app
[hadoop@localhost ~]$ cp jdk-14.0.2_linux-x64_bin.tar.gz app
[hadoop@localhost ~]$ cd app
[hadoop@localhost app]$ ls
jdk-14.0.2_linux-x64_bin.tar.gz
[hadoop@localhost app]$ tar -zxvf jdk-14.0.2_linux-x64_bin.tar.gz 
jdk-14.0.2/bin/jaotc
jdk-14.0.2/bin/jar
jdk-14.0.2/bin/jarsigner
jdk-14.0.2/bin/java
jdk-14.0.2/bin/javac
jdk-14.0.2/bin/javadoc
jdk-14.0.2/bin/javap
jdk-14.0.2/bin/jcmd
jdk-14.0.2/bin/jconsole
jdk-14.0.2/bin/jdb
jdk-14.0.2/bin/jdeprscan
......
[hadoop@localhost app]$ ls
jdk-14.0.2  jdk-14.0.2_linux-x64_bin.tar.gz
[hadoop@localhost app]$ ln -s jdk-14.0.2 jdk
[hadoop@localhost app]$ ls
jdk  jdk-14.0.2  jdk-14.0.2_linux-x64_bin.tar.gz
[hadoop@localhost app]$ vi ~/.bashrc
[hadoop@localhost app]$ cat ~/.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
JAVA_HOME=/home/hadoop/app/jdk
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PASH 
[hadoop@localhost app]$ source ~/.bashrc
[hadoop@localhost app]$ java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)

六、Hadoop伪分布集群的安装配置

1、解压进入hadoop配置文件目录
[hadoop@localhost ~]$ cp hadoop-2.7.3.tar.gz app
[hadoop@localhost ~]$ cd app
[hadoop@localhost ~]$ tar -zxvf hadoop-2.7.3.tar.gz
.......
[hadoop@localhost app]$ cd
[hadoop@localhost ~]$ cd app/hadoop-2.7.3/etc/hadoop
[hadoop@localhost hadoop]$ ls
capacity-scheduler.xml      httpfs-env.sh            mapred-env.sh
configuration.xsl           httpfs-log4j.properties  mapred-queues.xml.template
container-executor.cfg      httpfs-signature.secret  mapred-site.xml.template
core-site.xml               httpfs-site.xml          slaves
hadoop-env.cmd              kms-acls.xml             ssl-client.xml.example
hadoop-env.sh               kms-env.sh               ssl-server.xml.example
hadoop-metrics2.properties  kms-log4j.properties     yarn-env.cmd
hadoop-metrics.properties   kms-site.xml             yarn-env.sh
hadoop-policy.xml           log4j.properties         yarn-site.xml
hdfs-site.xml               mapred-env.cmd

2、修改core-site.xml,hdfs-site.xml,hadoop-env.sh,mapred-site.xml,yarn-site.xml,slaves配置文件

hadoop-env.sh中只改这一条
export JAVA_HOME=/home/hadoop/app/jdk

[hadoop@localhost hadoop]$ vi core-site.xml
[hadoop@localhost hadoop]$ cat core-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
               <name>fs.defaultFS</name>
               <value>hdfs://localhost:9000</value>
</property>
<property>
               <name>hadoop.tmp.dir</name>
               <value>file:/home/hadoop/data/tmp</value>
</property>
<property>
               <name>hadoop.proxyuser.hadoop.hosts</name>
               <value>*</value>
</property>
<property>
               <name>hadoop.proxyuser.hadoop.groups</name>
               <value>*</value>
</property>
</configuration>


[hadoop@localhost hadoop]$ vi hdfs-site.xml
[hadoop@localhost hadoop]$ cat hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
         <name>dfs.namenode.name.dir</name>
         <value>/home/hadoop/data/dfs/name</value>   
         <final>true</final>
</property>
<property>
         <name>dfs.datanode.data.dir</name>  
         <value>/home/hadoop/data/dfs/data</value>
         <final>true</final>
</property>
<property>
         <name>dfs.replication</name>
         <value>1</value>   
</property>
<property>
         <name>dfs.permissions</name> 
         <value>false</value>
</property>

</configuration>



[hadoop@localhost hadoop]$ vi hadoop-env.sh
[hadoop@localhost hadoop]$ cat hadoop-env.sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Set Hadoop-specific environment variables here.

# The only required environment variable is JAVA_HOME.  All others are
# optional.  When running a distributed configuration it is best to
# set JAVA_HOME in this file, so that it is correctly defined on
# remote nodes.

# The java implementation to use.
export JAVA_HOME=/home/hadoop/app/jdk

# The jsvc implementation to use. Jsvc is required to run secure datanodes
# that bind to privileged ports to provide authentication of data transfer
# protocol.  Jsvc is not required if SASL is configured for authentication of
# data transfer protocol using non-privileged ports.
#export JSVC_HOME=${JSVC_HOME}

export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-"/etc/hadoop"}

# Extra Java CLASSPATH elements.  Automatically insert capacity-scheduler.
for f in $HADOOP_HOME/contrib/capacity-scheduler/*.jar; do
  if [ "$HADOOP_CLASSPATH" ]; then
    export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$f
  else
    export HADOOP_CLASSPATH=$f
  fi
done

# The maximum amount of heap to use, in MB. Default is 1000.
#export HADOOP_HEAPSIZE=
#export HADOOP_NAMENODE_INIT_HEAPSIZE=""

# Extra Java runtime options.  Empty by default.
export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true"

# Command specific options appended to HADOOP_OPTS when specified
export HADOOP_NAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_NAMENODE_OPTS"
export HADOOP_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS $HADOOP_DATANODE_OPTS"

export HADOOP_SECONDARYNAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_SECONDARYNAMENODE_OPTS"

export HADOOP_NFS3_OPTS="$HADOOP_NFS3_OPTS"
export HADOOP_PORTMAP_OPTS="-Xmx512m $HADOOP_PORTMAP_OPTS"

# The following applies to multiple commands (fs, dfs, fsck, distcp etc)
export HADOOP_CLIENT_OPTS="-Xmx512m $HADOOP_CLIENT_OPTS"
#HADOOP_JAVA_PLATFORM_OPTS="-XX:-UsePerfData $HADOOP_JAVA_PLATFORM_OPTS"

# On secure datanodes, user to run the datanode as after dropping privileges.
# This **MUST** be uncommented to enable secure HDFS if using privileged ports
# to provide authentication of data transfer protocol.  This **MUST NOT** be
# defined if SASL is configured for authentication of data transfer protocol
# using non-privileged ports.
export HADOOP_SECURE_DN_USER=${HADOOP_SECURE_DN_USER}
export HADOOP_IDENT_STRING=$USER



[hadoop@localhost hadoop]$ vi mapred-site.xml
[hadoop@localhost hadoop]$ cat mapred-site.xml
<configuration>
		<property>
			<name>mapreduce.framework.name</name>
			<value>yarn</value>
		</property>
</configuration>


[hadoop@localhost hadoop]$ vi yarn-site.xnl
[hadoop@localhost hadoop]$ cat yarn-site.xnl
censed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>
	<property>
			<name>yarn.nodemanager.aux-services</name>  
			<value>mapreduce_shuffle</value>  
		</property>
</configuration
[hadoop@localhost hadoop]$ vi yarn-site.xnl
[hadoop@localhost hadoop]$ cat yarn-site.xnl
censed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>
	<property>
			<name>yarn.nodemanager.aux-services</name>  
			<value>mapreduce_shuffle</value>  
		</property>
</configuration>



[hadoop@localhost hadoop]$ cat slaves
localhost

[hadoop@localhost ~]$ cd app
[hadoop@localhost app]$ ls
hadoop-2.7.3         jdk         jdk-14.0.2_linux-x64_bin.tar.gz
hadoop-2.7.3.tar.gz  jdk-14.0.2
[hadoop@localhost app]$ ln -s hadoop-2.7.3 hadoop
[hadoop@localhost app]$ ls
hadoop        hadoop-2.7.3.tar.gz  jdk-14.0.2
hadoop-2.7.3  jdk                  jdk-14.0.2_linux-x64_bin.tar.gz
[hadoop@localhost app]$ vi ~/.bashrc
[hadoop@localhost app]$ cat ~/.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
JAVA_HOME=/home/hadoop/app/jdk
HADOOP_HOME=/home/hadoop/app/hadoop
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin/:HADOOP_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PASH HADOOP_HOME
[hadoop@localhost app]$ source ~/.bashrc
[hadoop@localhost app]$ cd
[hadoop@localhost ~]$ ls
app                  jdk-14.0.2_linux-x64_bin.tar.gz  模板  图片  下载  桌面
hadoop-2.7.3.tar.gz  公共                             视频  文档  音乐
[hadoop@localhost ~]$ mkdir -p data/tmp
[hadoop@localhost ~]$ mkdir -p data/dfs/name
[hadoop@localhost ~]$ mkdir -p data/dfs/data
[hadoop@localhost ~]$ ls
app   hadoop-2.7.3.tar.gz              公共  视频  文档  音乐
data  jdk-14.0.2_linux-x64_bin.tar.gz  模板  图片  下载  桌面
[hadoop@localhost ~]$ cd app/hadoop
[hadoop@localhost hadoop]$ cd bin
[hadoop@localhost bin]$ ./hadoop namenode -format
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.

21/03/29 23:02:38 INFO namenode.NameNode: STARTUP_MSG: 
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   host = localhost.localdomain/127.0.0.1
STARTUP_MSG:   args = [-format]
......
[hadoop@localhost hadoop]$ jps
3172 DataNode
3609 NodeManager
3501 ResourceManager
3901 Jps
1312 NameNode
1567 SecondaryNode

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木头科技

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值