[iyunv@localhost ~]# passwd hadoop
Changing password for user hadoop.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
//还要修改host文件
[iyunv@hadoop001 .ssh]# vim /etc/hosts
192.168.3.128 hadoop001
二、创建SSH无密码登录
单节点、集群都需要用到SSH登录,方便无障碍登录和通讯。
[hadoop@hadoop001 .ssh]$ cd ~/.ssh/
[hadoop@hadoop001 .ssh]$ 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:
97:75:b0:56:3b:57:8c:1f:b1:51:b6:d9:9f:77:f3:cf hadoop@hadoop001
The key's randomart image is:
+--[ RSA 2048]----+
| . .=*|
| +.+O|
| + +=+|
| + . o+|
| S o o+|
| . =|
| .|
| ..|
| E|
+-----------------+
[hadoop@hadoop001 .ssh]$ cat ./id_rsa.pub >> ./authorized_keys
[hadoop@hadoop001 .ssh]$ ll
total 12
-rw-rw-r--. 1 hadoop hadoop 398 Mar 14 14:09 authorized_keys
-rw-------. 1 hadoop hadoop 1675 Mar 14 14:09 id_rsa
-rw-r--r--. 1 hadoop hadoop 398 Mar 14 14:09 id_rsa.pub
[hadoop@hadoop001 .ssh]$ chmod 644 authorized_keys
[hadoop@hadoop001 .ssh]$ ssh hadoop001
Last login: Tue Mar 14 14:11:52 2017 from hadoop001
[hadoop@hadoop001 soft]$ java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
四、安装Hadoop
//安装到opt目录下
[iyunv@hadoop001 soft]# tar -zxf hadoop-2.7.3.tar.gz -C /opt/ 修改目录权限
[iyunv@hadoop001 opt]# ll
total 20
drwxr-xr-x. 9 root root 4096 Aug 17 2016 hadoop-2.7.3
[iyunv@hadoop001 opt]# chown -R hadoop:hadoop hadoop-2.7.3/
[iyunv@hadoop001 opt]# ll
total 20
drwxr-xr-x. 9 hadoop hadoop 4096 Aug 17 2016 hadoop-2.7.3
添加环境变量
[hadoop@hadoop001 bin]$ vim ~/.bash_profile
# hadoop
HADOOP_HOME=/opt/hadoop-2.7.3
PATH=$PATH:$HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export PATH
测试安装成功与否
[hadoop@hadoop001 bin]$ hadoop
Usage: hadoop [--config confdir] [COMMAND | CLASSNAME]
CLASSNAME run the class named CLASSNAME
or
where COMMAND is one of:
fs run a generic filesystem user client
version print the version
jar <jar> run a jar file
note: please use "yarn jar" to launch
YARN applications, not this command.
checknative [-a|-h] check native hadoop and compression libraries availability
distcp <srcurl> <desturl> copy file or directories recursively
archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive
classpath prints the class path needed to get the
credential interact with credential providers
Hadoop jar and the required libraries
daemonlog get/set the log level for each daemon
trace view and modify Hadoop tracing settings
Most commands print help when invoked w/o parameters.
单词统计
创建输入文件夹input放输入文件
[iyunv@hadoop001 /]# mkdir -p /data/input
//创建测试文件word.txt
[iyunv@hadoop001 /]# vim word.txt
Hi, This is a test file.
Hi, I love hadoop and love you .
//授权
[iyunv@hadoop001 /]# chown hadoop:hadoop /data/input/word.txt
//运行单词统计
[hadoop@hadoop001 hadoop-2.7.3]$ hadoop jar /opt/hadoop-2.7.3/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /data/input/word.txt /data/output/
//...中间日志省略
17/03/14 15:22:44 INFO mapreduce.Job: Counters: 30
File System Counters
FILE: Number of bytes read=592316
FILE: Number of bytes written=1165170
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
Map-Reduce Framework
Map input records=3
Map output records=14
Map output bytes=114
Map output materialized bytes=127
Input split bytes=90
Combine input records=14
Combine output records=12
Reduce input groups=12
Reduce shuffle bytes=127
Reduce input records=12
Reduce output records=12
Spilled Records=24
Shuffled Maps =1
Failed Shuffles=0
Merged Map outputs=1
GC time elapsed (ms)=0
Total committed heap usage (bytes)=525336576
Shuffle Errors
BAD_ID=0
CONNECTION=0
IO_ERROR=0
WRONG_LENGTH=0
WRONG_MAP=0
WRONG_REDUCE=0
File Input Format Counters
Bytes Read=59
File Output Format Counters
Bytes Written=85
执行成功,到output目录下看结果
[hadoop@hadoop001 output]$ vim part-r-00000
. 1
Hi, 2
I 1
This 1
a 1
and 1
file. 1
hadoop 1
is 1
love 2
test 1
you 1