1、准备工作,将编译好的hadoop拷贝到安装目录并解压
[root@hadoop001 ~]# cp /opt/sourcecode/hadoop-2.8.3-src/hadoop-dist/target/hadoop-2.8.3.tar.gz /opt/software/
[root@hadoop001 ~]# cd /opt/software/
[root@hadoop001 ~]# tar -xvf hadoop-2.8.3.tar.gz
2、环境检查
[root@hadoop001 ~]# which java
/usr/java/jdk1.8.0_161/bin/java
[root@hadoop001 ~]# which ssh
/usr/bin/ssh
3、创建用户组及用户
[root@hadoop001 ~]# groupadd hadoop
[root@hadoop001 ~]# useradd hadoop -g hadoop
[root@hadoop001 ~]# id hadoop
uid=515(hadoop) gid=500(hadoop) groups=500(hadoop)
4、给刚创建的hadoop用户添加sudo权限,添加下面最后一行代码,保存退出
[root@hadoop001 ~]# vim /etc/sudoers
# Preserving HOME has security implications since many programs
# use it when searching for configuration files. Note that HOME
# is already set when the the env_reset option is enabled, so
# this option is only effective for configurations where either
# env_reset is disabled or HOME is present in the env_keep list.
#
Defaults always_set_home
Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
#
# Adding HOME to env_keep may enable a user to run unrestricted
# commands via sudo.
#
# Defaults env_keep += "HOME"
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
hadoop ALL=(ALL) ALL
5、将解压好的hadoop-2.8.3文件夹授权给hadoop用户(改完权限之后最好ll去看一下确认一下)
[root@hadoop001 software]# chown -R hadoop:hadoop hadoop-2.8.3
[root@hadoop001 software]# chown -R hadoop:hadoop hadoop-2.8.3/*
6、配置hadoop用户的ssh信任关系(配置完之后ssh localhost一下,需要输入一次yes)
[root@hadoop001 software]# su - hadoop
[hadoop@hadoop001 ~]$ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
Generating public/private rsa key pair.
Created directory '/home/hadoop/.ssh'.
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:
fa:f3:44:1d:a9:f7:6e:0c:d7:85:49:d5:29:d1:48:e2 hadoop@hadoop001
The key's randomart image is:
+--[ RSA 2048]----+
| ..o+.+|
| . .+.o.|
| Eo..o |
| o .o .|
| S o o ..|
| . . .... .|
| . . +. |
| ... .o |
| .o. .. |
+-----------------+
[hadoop@hadoop001 ~]$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[hadoop@hadoop001 ~]$ chmod 0600 ~/.ssh/authorized_keys
[hadoop@hadoop001 ~]$ ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is 61:84:22:77:3b:a0:b2:95:c0:4e:23:a2:16:55:00:6b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
[hadoop@hadoop001 ~]$
7、配置xml配置文件
[hadoop@hadoop001 ~]$ vim /opt/software/hadoop-2.8.3/etc/hadoop/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://192.168.226.138:9000</value>
</property>
</configuration>
[hadoop@hadoop001 ~]$ vim /opt/software/hadoop-2.8.3/etc/hadoop/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.replication</name>
<value>1</value>
</property>
</configuration>
8、启动准备,格式化文件系统
[hadoop@hadoop001 hadoop-2.8.3]$ bin/hdfs namenode -format
9、启动
[hadoop@hadoop001 hadoop-2.8.3]$ sbin/start-dfs.sh
如果报错: ERROR JAVA_HOME is not set and cloud not be found
[hadoop@hadoop001 hadoop-2.8.3]$ sbin/start-dfs.sh
Starting namenodes on [hadoop001]
The authenticity of host 'hadoop001 (192.168.226.138)' can't be established.
RSA key fingerprint is 61:84:22:77:3b:a0:b2:95:c0:4e:23:a2:16:55:00:6b.
Are you sure you want to continue connecting (yes/no)? yes
hadoop001: Warning: Permanently added 'hadoop001,192.168.226.138' (RSA) to the list of known hosts.
hadoop001: Error: JAVA_HOME is not set and could not be found.
localhost: Error: JAVA_HOME is not set and could not be found.
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 61:84:22:77:3b:a0:b2:95:c0:4e:23:a2:16:55:00:6b.
Are you sure you want to continue connecting (yes/no)? yse
Please type 'yes' or 'no': yes
0.0.0.0: Warning: Permanently added '0.0.0.0' (RSA) to the list of known hosts.
0.0.0.0: Error: JAVA_HOME is not set and could not be found.
[hadoop@hadoop001 hadoop-2.8.3]$
将${JAVA_HOME}改为你自己的jdk安装目录,即第二步中which java的结果中,bin之前的
/usr/java/jdk1.8.0_161
[hadoop@hadoop001 hadoop-2.8.3]$ vim /opt/software/hadoop-2.8.3/etc/hadoop/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=${JAVA_HOME}
10、启动成功之后并检查