1. centos7.6 最小化安装、
2. hadoop3.2.0
3. jdk1.8.0_201
4. yum install rsync -y
5. ssh:最小化安装的系统中已有ssh,不用安装
[root@localhost ~]# yum install rsync -y
[root@localhost /]# systemctl stop firewalld.service
下面的命令是禁止防火墙开机启动
[root@localhost /]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost /]# mkdir software
通过winSCP将jdk(jdk-8u201-linux-x64.tar.gz)和hadoop(hadoop-3.2.0.tar.gz)拷贝到/software目录下
[root@localhost software]# ll -h
total 513M
-rw-r–r--. 1 root root 330M Jan 24 17:54 hadoop-3.2.0.tar.gz
-rw-r–r--. 1 root root 183M Jan 19 15:22 jdk-8u201-linux-x64.tar.gz
[root@localhost software]# tar -zxvf jdk-8u201-linux-x64.tar.gz
…
[root@localhost software]# ls
hadoop-3.2.0.tar.gz jdk1.8.0_201 jdk-8u201-linux-x64.tar.gz
export JAVA_HOME=/software/jdk1.8.0_201
export PATH=$JAVA_HOME/bin:$PATH
[root@localhost software]# source /etc/profile
[root@localhost software]# java -version
java version “1.8.0_201”
Java™ SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot™ 64-Bit Server VM (build 25.201-b09, mixed mode)
表示java安装成功
[root@localhost software]# tar -zxvf hadoop-3.2.0.tar.gz
[root@localhost software]# ls
hadoop-3.2.0 hadoop-3.2.0.tar.gz jdk1.8.0_201 jdk-8u201-linux-x64.tar.gz
export JAVA_HOME=/software/jdk1.8.0_201
[root@localhost software]# cd hadoop-3.2.0
[root@localhost hadoop-3.2.0]# bin/hadoop version
Hadoop 3.2.0
Source code repository https://github.com/apache/hadoop.git -r e97acb3bd8f3befd27418996fa5d4b50bf2e17bf
Compiled by sunilg on 2019-01-08T06:08Z
Compiled with protoc 2.5.0
From source with checksum d3f0795ed0d9dc378e2c785d3668f39
This command was run using /software/hadoop-3.2.0/share/hadoop/common/hadoop-common-3.2.0.jar
表示hadoop可以运行了
[root@localhost hadoop-3.2.0]# mkdir input
[root@localhost hadoop-3.2.0]# cp etc/hadoop/*.xml input
[root@localhost hadoop-3.2.0]# ls input
capacity-scheduler.xml hadoop-policy.xml httpfs-site.xml kms-site.xml yarn-site.xml
core-site.xml hdfs-site.xml kms-acls.xml mapred-site.xml
[root@localhost hadoop-3.2.0]# bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.0.jar grep input output 'dfs[a-z.]+'
[root@localhost hadoop-3.2.0]# ll output
total 4
-rw-r–r--. 1 root root 11 Jan 25 14:55 part-r-00000
-rw-r–r--. 1 root root 0 Jan 25 14:55 _SUCCESS
[root@localhost hadoop-3.2.0]# cat output/part-r-00000
1 dfsadmin
[root@localhost hadoop-3.2.0]# rm -vfr input output
[root@localhost hadoop-3.2.0]# ssh localhost
The authenticity of host ‘localhost (::1)’ can’t be established.
ECDSA key fingerprint is SHA256:MJxZUIDNbbnlfxCU+l2usvsIsbc6/NTJ06j/TO4g8G0.
ECDSA key fingerprint is MD5:d1:8f:94:dd:80:e2:cf:6b:a7:45:74:e3:6b:2f:f2:0a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘localhost’ (ECDSA) to the list of known hosts.
root@localhost’s password:
Last login: Fri Jan 25 14:30:29 2019 from 192.168.114.1
解释: 看到如上内容说明还不能免密码登录
[root@localhost ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
[root@localhost ~]# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[root@localhost ~]# chmod 0600 ~/.ssh/authorized_keys
[root@localhost hadoop-3.2.0]# ssh localhost
Last login: Fri Jan 25 15:04:51 2019 from localhost
解释: 说明可以免密码登录了
[root@localhost hadoop-3.2.0]# bin/hdfs namenode -format
2019-01-25 15:09:23,273 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = localhost/127.0.0.1
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 3.2.0
…
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at localhost/127.0.0.1
************************************************************/
HDFS_DATANODE_USER=root
HADOOP_SECURE_DN_USER=root
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root
[root@localhost hadoop-3.2.0]# sbin/start-dfs.sh
WARNING: HADOOP_SECURE_DN_USER has been replaced by HDFS_DATANODE_SECURE_USER. Using value of HADOOP_SECURE_DN_USER.
Starting namenodes on [localhost]
Last login: Fri Jan 25 15:07:02 CST 2019 from localhost on pts/1
Starting datanodes
Last login: Fri Jan 25 15:14:50 CST 2019 on pts/0
Starting secondary namenodes [localhost.localdomain]
Last login: Fri Jan 25 15:14:53 CST 2019 on pts/0
localhost.localdomain: Warning: Permanently added ‘localhost.localdomain’ (ECDSA) to the list of known hosts.
http://192.168.114.134:9870
可以看到hadoop的信息
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -mkdir /user
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -mkdir /user/root
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -ls
什么也没有
[root@localhost hadoop-3.2.0]# mkdir input
[root@localhost hadoop-3.2.0]# cp etc/hadoop/*.xml input
[root@localhost hadoop-3.2.0]# ls input
capacity-scheduler.xml hadoop-policy.xml httpfs-site.xml kms-site.xml yarn-site.xml
core-site.xml hdfs-site.xml kms-acls.xml mapred-site.xml
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -put input input1
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -ls
Found 1 items
drwxr-xr-x - root supergroup 0 2019-01-25 15:24 input1
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -ls input1
Found 9 items
-rw-r–r-- 1 root supergroup 8260 2019-01-25 15:24 input1/capacity-scheduler.xml
-rw-r–r-- 1 root supergroup 884 2019-01-25 15:24 input1/core-site.xml
-rw-r–r-- 1 root supergroup 11392 2019-01-25 15:24 input1/hadoop-policy.xml
-rw-r–r-- 1 root supergroup 868 2019-01-25 15:24 input1/hdfs-site.xml
-rw-r–r-- 1 root supergroup 620 2019-01-25 15:24 input1/httpfs-site.xml
-rw-r–r-- 1 root supergroup 3518 2019-01-25 15:24 input1/kms-acls.xml
-rw-r–r-- 1 root supergroup 682 2019-01-25 15:24 input1/kms-site.xml
-rw-r–r-- 1 root supergroup 758 2019-01-25 15:24 input1/mapred-site.xml
-rw-r–r-- 1 root supergroup 690 2019-01-25 15:24 input1/yarn-site.xml
[root@localhost hadoop-3.2.0]# bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.0.jar grep input1 output 'dfs[a-z.]+'
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -ls
Found 2 items
drwxr-xr-x - root supergroup 0 2019-01-25 15:24 input1
drwxr-xr-x - root supergroup 0 2019-01-25 15:26 output
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -ls output
Found 2 items
-rw-r–r-- 1 root supergroup 0 2019-01-25 15:26 output/_SUCCESS
-rw-r–r-- 1 root supergroup 29 2019-01-25 15:26 output/part-r-00000
[root@localhost hadoop-3.2.0]# bin/hdfs dfs -cat output/part-r-00000
1 dfsadmin
1 dfs.replication
这里可以看到搜索的结果.
[root@localhost hadoop-3.2.0]# sbin/stop-dfs.sh
WARNING: HADOOP_SECURE_DN_USER has been replaced by HDFS_DATANODE_SECURE_USER. Using value of HADOOP_SECURE_DN_USER.
Stopping namenodes on [localhost]
Last login: Fri Jan 25 15:14:57 CST 2019 on pts/0
Stopping datanodes
Last login: Fri Jan 25 15:30:53 CST 2019 on pts/0
Stopping secondary namenodes [localhost.localdomain]
Last login: Fri Jan 25 15:30:54 CST 2019 on pts/0