《Programming Hive》读书笔记(一)Hadoop和hive环境搭建,hadoophive


《Programming Hive》读书笔记(一)Hadoop和Hive环境搭建
            先把基本的技术和工具学好,才能更高效地思考和工作。
 

Chapter 1.Introduction 简介

Chapter 2.Getting Started 环境配置

 

Hadoop版本会更新,以官方安装教程为准

http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/SingleCluster.html#Standalone_Operation

 

For most of the book, it won’t matterwhich mode you’re using. We’llassume you’re

working on a personal machine in local mode and we’ll discussthe cases where the

mode matters.

 

When working with small data sets, usinglocal mode execution

will make Hive queries much faster. Settingthe property set

hive.exec.mode.local.auto=true;willcause Hive to use this mode more

aggressively, even when you are runningHadoop in distributed or pseudodistributed

mode. To always use this setting, add thecommand to

your $HOME/.hiverc file (see “The.hiverc File” on page 36).

 

对于Hadoop的不同模式,他们在不同的使用情境下性能也是各异的。

少量的数据,用local mode模式性能会更好。

 

 

两个Hadoop程序例子:

1 hadoop jarshare/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.1.jarwordcount input output

这是wordcount词频统计程序。

 

2 hadoop jarshare/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.1.jargrep input output 'dfs[a-z.]+'

这是grep程序,类似linux下的命令。

其中,input为输入目录,output为输出目录。输入目录需要先创建,输出目录不需要创建,且不能已存在。

 

Hive的官方安装

https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-InstallingHivefromaStableRelease

 

其实Hadoop和hive的安装就是解压和配置环境变量。

不过hive需要创建两个目录才能正确运行

$ $HADOOP_HOME/bin/hadoop fs -mkdir       /tmp
  $ $HADOOP_HOME/bin/hadoop fs -mkdir       /user/hive/warehouse
  $ $HADOOP_HOME/bin/hadoop fs -chmod g+w   /tmp
  $ $HADOOP_HOME/bin/hadoop fs -chmod g+w   /user/hive/warehouse

不用hdfs也可以,本地模式直接创建。

另外mkdir需要加上-p才能一次创建多层目录

 

Linux需要注意的是,你用普通用户运行hive,如果hive程序需要在某些目录创建文件或者目录但是没有权限,那么就会运行出错。

比如上面的tmp和warehouse目录。

还有,在当前目录运行hive命令,

会自动在当前目录创建

-rw-rw-r-- 1 linger linger  678 Nov 12 00:03derby.log

drwxrwxr-x 5 linger linger 4096 Nov 12 00:03 metastore_db/

一个文件,一个目录。

如果hive在当前目录没有创建的权限,又会出错。

 

另外发现/etc/profile是用户登录时会自动生效的,

临时生效办法可以 source /etc/profile

另外,root没有登录,所以注销或者重启后,sudo su进入root,发现/etc/profile还是没有生效,目前的解决方法是用source了。不过能用普通用户先用普通用户,用普通用户得注意权限不足的问题。


额外资料:

http://wangshuxing123-126-com.iteye.com/blog/695653

chmod是Linux下设置文件权限的命令,后面的数字表示不同用户或用户组的权限。

一般是三个数字:
第一个数字表示文件所有者的权限
第二个数字表示与文件所有者同属一个用户组的其他用户的权限
第三个数字表示其它用户组的权限。

     权限分为三种:读(r=4),写(w=2),执行(x=1 。 综合起来还有可读可执行(rx=5=4+1)、可读可写(rw=6=4+2)、可读可写可执行(rwx=7=4+2+1)。

     所以,chmod 755 设置用户的权限为:

 

1.文件所有者可读可写可执行                                  --7

2.与文件所有者同属一个用户组的其他用户可读可执行 --5 
3.其它用户组可读可执行                                       --5

 

常见用法:

Chmod –R 777 target_dir

Chmod –R 755 target_dir



本文作者:linger 本文链接:http://blog.csdn.net/lingerlanlan/article/details/41025431


   

相关内容