我在VM里创建里两台虚拟机
master 172.16.205.6
slave1 172.16.205.7
都需要安装jdk
一、Linux安装jdk
第一步:解压jdk-8u162-linux-x64.tar.gz
tar -zxvf jdk-8u162-linux-x64.tar.gz -C /java
第二步:配置环境变量 ,修改~/.bash_profile
JAVA_HOME=/java/jdk1.8.0_162
export PATH=$JAVA_HOME/bin:$PATH
第三步:重新编译~/.bash_profile
source ~/.bash_profile
可以输入java -version查看版本信息 如果显示 说明安装成功。
二、需要Linux具有ssh环境
yum install ssh 命令用来在线安装ssh
linux 查看是否安装了ssh
ps -ef | grep ssh
[root@localhost Desktop]# ps -ef | grep ssh
root 1951 1 0 05:49 ? 00:00:00 /usr/sbin/sshd
root 25741 25724 0 06:36 pts/0 00:00:00 grep ssh
启动ssh
service sshd start
1>配置主机名
vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=guang1
2>设置ip和hostname的映射关系
vim /etc/hosts
172.16.205.6 guang1
172.16.205.6 localhost
3>配置ssh免密码登录
在主目录下执行命令:
ssh-keygen -t rsa (全部敲回车键)
回车后会在~/.ssh/下生成两个文件:id_rsa和id_rsa.pub这两个文件是成对出现的
进入~/.ssh/目录下,将id_rsa.pub追加到authorized_keys授权文件中,开始是没有authorized_keys文件的
进入~/.ssh文件夹,执行命令
cp id_rsa.pub authorized_keys 或者 cat id_rsa.pub >> authorized_keys
ssh免密登录测试
ssh localhost
ssh fengqing
( 注:当ssh远程登录到其它机器后,现在你控制的是远程的机器,需要执行退出命令才能重新控制本地主机)
配置master无密码登陆slave1
mater主机中输入命令复制一份公钥到home中,目的是要把副本放到slave1中
cp .ssh/id_rsa.pub ~/id_rsa_master.pub
把master的home目录下的id_rsa_master.pub拷到slave1的home下
slave1的home目录下分别输入命令
cat id_rsa_master.pub >> .ssh/authorized_keys
至此实现了mater对slave1的无密码登陆
[root@localhost /]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: f1:00:ed:04:24:c7:4c:17:55:9c:10:d4:bc:36:46:cc root@localhost.localdomain The key's randomart image is: +--[ RSA 2048]----+ | .=*oo+=X.. | | oooo E | | oo . . | | .+ = | | S .o . | | | | | | | | | +-----------------+ [root@localhost /]# cd ~/.ssh [root@localhost .ssh]# cp id_rsa.pub authorized_keys [root@localhost .ssh]#
指定JDK
解压缩hadoop-2.6.0-cdh5.7.0.tar.gz到指定目录
tar -zxvf hadoop-2.6.0-cdh5.7.0.tar.gz -C /apps
然后到这个路径下/apps/hadoop-2.6.0-cdh5.7.0/etc/hadoop找到hadoop-env.sh 指定jdk
export JAVA_HOME=/java/jdk1.8.0_162
core-site.xml
在/apps/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml文件中配置
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://guang1:8082</value>
</property>
<!--设置临时文件的位置-->
<property>
<name>hadoop.tmp.dir</name>
<value>/apps/tmp</value>
</property>
</configuration>
hdfs-site.xml
在/apps/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml文件中配置
<configuration>
<!--设置副本系数为1,默认为3-->
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
配置hadoop客户端的环境变量
vim ~/.bash_profile
HADOOP_HOME=/apps/hadoop-2.6.0-cdh5.7.0
export PATH=$HADOOP_HOME/bin:$PATH
格式化文件系统
在 /apps/hadoop-2.6.0-cdh5.7.0/bin目录下执行命令
hdfs namenode -format
启动namenode进程和datanode进程
在 /apps/hadoop-2.6.0-cdh5.7.0/sbin目录下执行命令
./start-dfs.sh
出错了!
18/12/10 07:25:49 WARN util.NativeCodeLoader: Unable to load native-hadoop
library for your platform... using builtin-java classes where applicable
原因:
Apache提供的hadoop本地库是32位的,而在64位的服务器上就会有问题,因此需要自己编译64位的版本。
1、首先找到对应自己hadoop版本的64位的lib包,可以自己手动去编译,但比较麻烦,也可以去网上找,好多都有已经编译好了的。
2、可以去网站:http://dl.bintray.com/sequenceiq/sequenceiq-bin/ 下载对应的编译版本
3、将准备好的64位的lib包解压到已经安装好的hadoop安装目录的lib/native 和 lib目录下:
tar -xvf hadoop-native-64-2.7.0.tar -C hadoop-2.7.2/lib/native
检测是否启动成功
执行命令:jps
或者打开浏览器(注意防火墙chkconfig iptables off永久关闭需要重启,service iptables stop是临时关闭,重启默认开启防火墙)
http://172.16.205.6:50070
[root@localhost sbin]# ./start-dfs.sh
Starting namenodes on [guang1]
guang1: namenode running as process 26794. Stop it first.
localhost: datanode running as process 26873. Stop it first.
Starting secondary namenodes [0.0.0.0]
0.0.0.0: Address 127.0.0.1 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
0.0.0.0: secondarynamenode running as process 27078. Stop it first.
[root@localhost sbin]# jps
27825 Jps
27078 SecondaryNameNode
26873 DataNode
26794 NameNode
[root@localhost sbin]#
Hadoop的详细命令介绍官网
http://hadoop.apache.org/docs/r2.7.6/hadoop-project-dist/hadoop-common/FileSystemShell.html
[root@localhost hadoop-2.6.0-cdh5.7.0]# hadoop fs -mkdir -p /usr/data/input
[root@guang1 data]# touch wc.input
[root@guang1 data]# ls
wc.input
[root@guang1 data]# vim wc.input
[root@localhost hadoop-2.6.0-cdh5.7.0]# hadoop fs -put /opt/data/wc.input /usr/data/input/wc.input
以下是测试mapreduce统计数量的demo的命令,红色的路径文件是需要put进hadoop的,后面的路径自动生成。
hadoop安装路径下执行:bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-x.x.x.jar wordcount /opt/data/wc.input output2