赞
踩
**
**
3.1 创建Hadoop用户
如果你安装 CentOS 的时候不是用的 “hadoop” 用户,那么需要增加一个名为 hadoop 的用户。
首先点击左上角的 “应用程序” -> “系统工具” -> “终端”,首先在终端中输入 su ,按回车,输入 root 密码以 root 用户登录,接着执行命令创建新用户 hadoop:
[root@bogon hadoop]# sudo useradd –m Hadoop –G root –s /bin/bash
如下图所示,这条命令创建了可以登陆的 hadoop 用户,并使用 /bin/bash 作为shell。
接着使用如下命令修改密码,按提示输入两次密码,可简单的设为 “hadoop”(密码随意指定,若提示“无效的密码,过于简单”则再次输入确认就行):
[root@bogon hadoop]# passwd Hadoop
[root@bogon hadoop]# visudo
如下图,找到 root ALL=(ALL) ALL 这行(应该在第98行,可以先按一下键盘上的 ESC 键,然后输入 :98 (按一下冒号,接着输入98,再按回车键),可以直接跳到第98行 ),然后在这行下面增加一行内容:hadoop ALL=(ALL) ALL
(当中的间隔为tab),如下图所示:
添加上一行内容后,先按一下键盘上的 ESC 键,然后输入 :wq (输入冒号还有wq,这是vi/vim编辑器的保存方法),再按回车键保存退出就可以了。
最后注销当前用户(点击屏幕右上角的用户名,选择退出->注销),在登陆界面使用刚创建的 hadoop 用户进行登陆。(如果已经是 hadoop 用户,且在终端中使用 su 登录了 root 用户,那么需要执行 exit 退出 root 用户状态)
3.2 准备工作
使用 hadoop 用户登录后,还需要安装几个软件才能安装 Hadoop。
CentOS 使用 yum 来安装软件,需要联网环境,首先应检查一下是否连上了网络。如下图所示,桌面右上角的网络图标若显示红叉,则表明还未联网,应点击选择可用网络。
检查是否联网
连接网络后,需要安装 SSH 和 Java。
3.3 安装SSH、配置SSH无密码登陆
集群、单节点模式都需要用到 SSH 登陆(类似于远程登陆,你可以登录某台 Linux 主机,并且在上面运行命令),一般情况下,CentOS 默认已安装了 SSH client、SSH server,打开终端执行如下命令进行检验:
1.
rpm -qa | grep ssh
Shell 命令
如果返回的结果如下图所示,包含了 SSH client 跟 SSH server,则不需要再安装。
检查是否安装了SSH
若需要安装,则可以通过 yum 进行安装(安装过程中会让你输入 [y/N],输入 y 即可):
exit
# 退出刚才的 ssh localhostcd ~/.ssh/
# 若没有该目录,请先执行一次ssh localhostssh-keygen -t rsa
# 会有提示,都按回车就可以cat id_rsa.pub >> authorized_keys
# 加入授权chmod 600 ./authorized_keys
# 修改文件权限ssh localhost
命令,无需输入密码就可以直接登陆了,如下图所示。3.4 下载Hadoop的压缩包
3.5 上传Hadoop到Centos
1.1 检查系统是否有JDK环境
[root@bogon jdk1.8]# rpm -qa | grep jdk
java-1.7.0-openjdk-1.7.0.241-2.6.20.0.el6_10.x86_64
java-1.7.0-openjdk-devel-1.7.0.241-2.6.20.0.el6_10.x86_64
copy-jdk-configs-3.3-9.el6.noarch
1.2 有如果JDK环境先卸载
[root@bogon jdk1.8]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.241-2.6.20.0.el6_10.x86_64
[root@bogon jdk1.8]# rpm -e --nodeps java-1.7.0-openjdk-devel-1.7.0.241-2.6.20.0.el6_10.x86_64
[root@bogon jvm]# rpm -qa | grep jdk
copy-jdk-configs-3.3-9.el6.noarch
[root@bogon jvm]# rpm -e --nodeps copy-jdk-configs-3.3-9.el6.noarch
1.3 JDK下载
1.4 上传
1.5 解压
[hadoop@bogon ~]$ sudo tar -zxf jdk-8u241-linux-x64.tar.gz -C /usr/lib/jvm
1.6 配置环境变量
[hadoop@bogon ~]$ cd /usr/lib/jvm
[hadoop@bogon jvm]$ sudo mv jdk1.8.0_241/ jdk1.8
[hadoop@bogon jvm]$ cd jdk1.8/
[hadoop@bogon jdk1.8]$ pwd
/usr/lib/jvm/jdk1.8
[hadoop@bogon jvm]$ vim ~/.bashrc
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export JAVA_HOME=/usr/lib/jvm/jdk1.8
export PATH=$PATH:$JAVA_HOME/bin
export HADOOP_HOME=/usr/local/hadoop
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin
export HBASE_HOME=/usr/local/hbase
export PATH=$PATH:$HBASE_HOME/bin
[hadoop@bogon jvm]$ source ~/.bashrc
[hadoop@bogon jvm]$ echo $JAVA_HOME
/usr/lib/jvm/jdk1.8
[hadoop@bogon jvm]$
‘
J
A
V
A
H
O
M
E
/
b
i
n
/
j
a
v
a
−
v
e
r
s
i
o
n
‘
j
a
v
a
v
e
r
s
i
o
n
"
1.8.
0
2
41
"
J
a
v
a
(
T
M
)
S
E
R
u
n
t
i
m
e
E
n
v
i
r
o
n
m
e
n
t
(
b
u
i
l
d
1.8.
0
2
41
−
b
07
)
J
a
v
a
H
o
t
S
p
o
t
(
T
M
)
64
−
B
i
t
S
e
r
v
e
r
V
M
(
b
u
i
l
d
25.241
−
b
07
,
m
i
x
e
d
m
o
d
e
)
[
h
a
d
o
o
p
@
b
o
g
o
n
j
v
m
]
`JAVA_HOME/bin/java -version` java version "1.8.0_241" Java(TM) SE Runtime Environment (build 1.8.0_241-b07) Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode) [hadoop@bogon jvm]
‘JAVAHOME/bin/java−version‘javaversion"1.8.0241"Java(TM)SERuntimeEnvironment(build1.8.0241−b07)JavaHotSpot(TM)64−BitServerVM(build25.241−b07,mixedmode)[hadoop@bogonjvm] vim ~/.bashrc
[hadoop@bogon jvm]$ source ~/.bashrc
[hadoop@bogon jvm]$ java -version
java version “1.8.0_241”
Java™ SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot™ 64-Bit Server VM (build 25.241-b07, mixed mode)
3.6 解压、重命名并赋权
[hadoop@bogon ~]$ sudo tar -zxf hadoop-2.7.7.tar.gz -C /usr/local
[sudo] password for hadoop:
[hadoop@bogon local]$ sudo mv hadoop-2.7.7/ hadoop
[sudo] password for hadoop:
[hadoop@bogon local]$ sudo chown -R hadoop:hadoop hadoop/
[hadoop@bogon hadoop]$ ./bin/hadoop version
Hadoop 2.7.7
Subversion Unknown -r c1aad84bd27cd79c3d1a7dd58202a8c3ee1ed3ac
Compiled by stevel on 2018-07-18T22:47Z
Compiled with protoc 2.5.0
From source with checksum 792e15d20b12c74bd6f19a1fb886490
This command was run using /usr/local/hadoop/share/hadoop/common/hadoop-common-2.7.7.jar
3.7 配置环境变量
3.8 修改Hosts文件
host文件配置非常重要,可以在本机或者主机通过域名进行访问,同时可以在配置文件中使用使用该域名。
[hadoop@bogon hadoop]$ hostname
bogon
[hadoop@bogon hadoop]$ sudo vim /etc/hosts
[sudo] password for hadoop:
[hadoop@bogon hadoop]$ hostname
bogon
[hadoop@bogon hadoop]$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 bogon
<configuration>
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/usr/local/hadoop/tmp</value>
<description>Abase for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop:9000</value>
</property>
</configuration>
</configuration>
**
**
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/usr/local/hadoop/tmp/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/usr/local/hadoop/tmp/dfs/data</value>
</property>
</configuration>
3.11 格式化名称节点
格式化的时候,如果临时目录存在则需手动删除
直接删除tmp文件夹
[hadoop@bogon hadoop]$ ./bin/hdfs namenode -format
20/04/01 03:02:06 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = localhost/127.0.0.1
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 2.7.7
STARTUP_MSG: classpath = /usr/local/hadoop/etc/hadoop:/usr/local/hadoop/share/hadoop/common/lib/m
20/04/01 03:02:11 INFO util.ExitUtil: Exiting with status 0
20/04/01 03:02:11 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at localhost/127.0.0.1
************************************************************/
[hadoop@bogon hadoop]$ ./sbin/start-dfs.sh
20/04/01 03:02:32 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
Starting namenodes on [hadoop]
The authenticity of host ‘hadoop (192.168.138.141)’ can’t be established.
RSA key fingerprint is b9:b4:a7:7f:3f:21:76:ca:30:20:53:1b:23:24:82:ca.
Are you sure you want to continue connecting (yes/no)? yes
hadoop: Warning: Permanently added ‘hadoop,192.168.138.141’ (RSA) to the list of known hosts.
hadoop: starting namenode, logging to /usr/local/hadoop/logs/hadoop-hadoop-namenode-bogon.out
localhost: starting datanode, logging to /usr/local/hadoop/logs/hadoop-hadoop-datanode-bogon.out
Starting secondary namenodes [0.0.0.0]
The authenticity of host ‘0.0.0.0 (0.0.0.0)’ can’t be established.
RSA key fingerprint is b9:b4:a7:7f:3f:21:76:ca:30:20:53:1b:23:24:82:ca.
Are you sure you want to continue connecting (yes/no)? yes
0.0.0.0: Warning: Permanently added ‘0.0.0.0’ (RSA) to the list of known hosts.
0.0.0.0: starting secondarynamenode, logging to /usr/local/hadoop/logs/hadoop-hadoop-secondarynamenode-bogon.out
20/04/01 03:03:31 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
[hadoop@bogon hadoop]$ jps
107808 DataNode
109712 Jps
108931 SecondaryNameNode
107491 NameNode
3.12 配置mapred-site.xml
[hadoop@bogon hadoop]$ cp mapred-site.xml.template mapred-site.xml
[hadoop@bogon hadoop]$ vim mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
3.13 配置yarn-site.xml
[hadoop@bogon hadoop]$
vim yarn-site.xml
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
[hadoop@bogon sbin]$ start-yarn.sh
starting yarn daemons
starting resourcemanager, logging to /usr/local/hadoop/logs/yarn-hadoop-resourcemanager-bogon.out
localhost: starting nodemanager, logging to /usr/local/hadoop/logs/yarn-hadoop-nodemanager-bogon.out
[hadoop@bogon sbin]$ jps
121009 ResourceManager
121233 NodeManager
107808 DataNode
108931 SecondaryNameNode
107491 NameNode
121460 Jps
3.14 测试
也可以用ip进行测试
hadoop:50070 ip地址:50070
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。