-
Notifications
You must be signed in to change notification settings - Fork 0
Home
下载jdk1.8.0_51,解压缩之后,在~/.bashrc文件中配置JAVA_HOME
export JAVA_HOME=/usr/jdk1.8.0_51
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
配置完成之后时候source ~/.bashrc使之立即生效
ubuntu自带openssh-client,所以只需要安装openssh-server,由于版本的不同,使用apt-get install的时候需要先remove当前版本的client,然后安装server。
安装完openssh之后需要配置ssh无密码登录。首先使用ssh登录本机
ssh localhost
首次登录会有密码提示,输入完密码就可以登录到本机了。利用ssh-keygen生成密钥,然后将密钥加入到授权中,然后进行如下操作
$ exit # 退出刚才的 ssh localhost
$ cd ~/.ssh/ # 若没有该目录,请先执行一次ssh localhost
$ ssh-keygen -t rsa # 会有提示,都按回车就可以
$ cat ./id_rsa.pub >> ./authorized_keys # 加入授权
此时使用ssh localhost就能无密码登录到本机了
Hadoop2.7.2可以通过官网http://www-eu.apache.org/dist/hadoop/common/hadoop-2.7.2/ 下载,下载直接选择编译好的版本tar.gz,而不选择src.tar.gz源码。 我选择将hadoop2.7.2安装在/usr/下,直接解压即可。
即使不配置分布式环境,也可以在单机的环境下跑Hadoop自带的实例,运行./bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0.jar
可以看到自带的所有实例,包括wordcount、terasort、join、grep 等。例如运行grep实例:
$ cd /usr/hadoop-2.7.2
$ mkdir ./input
$ cp ./etc/hadoop/*.xml ./input
$ ./bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-*.jar grep ./input ./output 'dfs[a-z.]+'
$ cat ./output/*
首先配置hadoop的JAVA_HOME,使用vim打开/etc/hadoop/hadoop-env.sh,修改为export JAVA_HOME = /usr/jdk1.8.0_51
,切记使用绝对路径,使用${JAVA_HOME}是行不通的。
Hadoop 的配置文件位于 /usr/hadoop-2.7.2/etc/hadoop/ 中,伪分布式需要修改2个配置文件 core-site.xml 和 hdfs-site.xml 。Hadoop的配置文件是 xml 格式,每个配置以声明 property 的 name 和 value 的方式来实现。
修改core-site.xml文件,添加:
<property>
<name>hadoop.tmp.dir</name>
<value>file:/usr/hadoop-2.7.2/tmp</value>
<description>Abase for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
修改hdfs-site.xml文件,添加:
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/usr/hadoop-2.7.2/tmp/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/usr/hadoop-2.7.2/tmp/dfs/data</value>
</property>
完成这两个文件的配置之后,格式化namenode:
$ ./bin/hdfs namenode -format
接着开启 NameNode 和 DataNode 守护进程:
$ ./sbin/start-dfs.sh
启动完成后,可以通过命令 jps 来判断是否成功启动,若成功启动则会列出如下进程: “NameNode”、”DataNode” 和 “SecondaryNameNode”(如果 SecondaryNameNode 没有启动,请运行 sbin/stop-dfs.sh 关闭进程,然后再次尝试启动尝试)。如果没有 NameNode 或 DataNode ,那就是配置不成功。 成功启动后,可以访问 Web 界面 http://localhost:50070 查看 NameNode 和 Datanode 信息,还可以在线查看 HDFS 中的文件。
首先修改配置文件mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
其次修改yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
<configuration>
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>128</value>
<description>Minimum limit of memory to allocate to each container request at the Resource Manager.</description>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>2048</value>
<description>Maximum limit of memory to allocate to each container request at the Resource Manager.</description>
</property>
<property>
<name>yarn.scheduler.minimum-allocation-vcores</name>
<value>1</value>
<description>The minimum allocation for every container request at the RM, in terms of virtual CPU cores. Requests lower than this won't take effect, and the specified value will get allocated the minimum.</description>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-vcores</name>
<value>2</value>
<description>The maximum allocation for every container request at the RM, in terms of virtual CPU cores. Requests higher than this won't take effect, and will get capped to this value.</description>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>4096</value>
<description>Physical memory, in MB, to be made available to running containers</description>
</property>
<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>4</value>
<description>Number of CPU cores that can be allocated for containers.</description>
</property>
</configuration>
注意:以上是配置yarn的内存空间,非常重要。
然后就可以启动yarn了,./sbin/start-yarn.sh
,然后开启历史服务器./sbin/mr-jobhistory-daemon.sh start historyserver
,开始之后可以通过http://localhost:8088/cluster来查看任务
首先删除本地input和output目录,./bin/hdfs dfs -mkdir -p input
会在用户目录/usr/txy/下新建一个input目录,每个用户在hdfs中都会以用户名对应一个文件夹,比如/usr/txy,把本地文件复制到hdfs中:
$ ./bin/hdfs dfs -put ./etc/hadoop/*.xml input
$ ./bin/hdfs dfs -ls input
运行程序并查看结果,也可以将结果拷贝到本地之后查看
$ ./bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-*.jar grep input output 'dfs[a-z.]+'
$ ./bin/hdfs dfs -cat output/*
$ ./bin/hdfs dfs -get output ./output
$ cat ./output/*