`
kavy
  • 浏览: 866050 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Hadoop集群及 Hive 安装

 
阅读更多

Hadoop安装指南 / Hive安装指南

 

Hadoop集群需要一个机器作为Master节点,其余的机器都是slave节点。

HIVE只需在Master节点中安装和配置即可。

 

配置Hadoop

Hadoop的配置比较简单,下面详细讲一下安装与配置步骤。

以配置Hadoop 0.20.2版本为例。

(1) 从hadoop官网上下载hadoop-0.20.2.tar.gz文件,并解压产生hadoop-0.20.2目录,将该目录到/opt/hadoop目录下(如果你解压缩到了其它目录中,注意后面要相应的修改配置项)。

输入命令建立软连接$ ln -s hadoop-0.20.2 hadoop (这样做的好处是如果改用其它版本的hadoop不用重新配置)

(2) Hadoop和Hive都需要机器名。用hostname命令修改本机的机器名,例如修改10.10.10.1的机器名为hadoop139需要键入 # hostname hadoop1

修改/etc/hosts文件,添加Hadoop集群中所有的机器名和Ip地址的对应关系。

Master节点和所有slave节点一定都要添加,否则会出问题。例如在我的所有hadoop机器的/etc/hosts文件都添加

10.10.10.1 hadoop1

10.10.10.2 hadoop2

10.10.10.3 hadoop3

10.10.10.4 hadoop4

10.10.10.5 hadoop5

10.10.10.6 hadoop6

10.10.10.7 hadoop7

(3) 由于Master节点的机器需要ssh无密码登录到所有slave节点,因此所有机器都需要如下配置。

在本文中Hadoop1是Master节点。

打开/etc/ssh/sshd_config文件,确保ssh使用的不是ssh2协议,否则将所有的Protocol 2修改成Protocol 1。

如果修改了该文件,用service sshd restart命令重启一下ssh服务。

键入以下命令

# cd ~/.ssh/

# ssh-keygen -t rsa1 -C "hadoop1" -f /root/.ssh/identity

# cat identity.pub >> authorized_keys

这时本机的公钥文件被存到了authorized_keys文件。

这时ssh localhost命令应该可以不需要输入密码就自动登录本机(如果ssh 本机IP成功,但ssh localhost失败,则可以打开/etc/hosts.allow文件并添加127.0.0.1)。

为了保证master不需要密码直接ssh到slave节点,所有slave机器要rsync下来master机器的/root/.ssh/identity.pub文件,并cat到本机的/root/.ssh/authorized_keys文件。

这时在master节点上用ssh+IP不输入密码直接可以登录slave机器。

(Hadoop需要SSH的无密访问。 Master机器访问Slaves机器)

(4) 修改环境变量

打开/etc/profile文件,在最后添加

export $HADOOP_HOME=/search/hadoop/hadoop

export PATH=$HADOOP_HOME/bin:$PATH

关闭,并运行$ source /etc/profile命令,则环境变量生效。

(5) 修改$HADOOP_HOME/conf/hadoop-env.sh配置文件的两个配置

export JAVA_HOME=配置本机jdk或者jre的路径

(Redhat如果没有jdk,可以yum install java-1.6.0-openjdk-devel,

注意必须是java1.6版本以上,否则hadoop无法正常运行)

#这里设定hadoop占用2G内存,可以根据机器配置来改

export HADOOP_HEAPSIZE=2000

(6) 修改$HADOOP_HOME/conf/hadoop-site.xml文件如下,注意fs.default.name和mapred.job.tracker配置项必须用master节点的机器名而不能IP。

否则运行HIVE时会遇到错误。

<!--[if !supportLists]-->1.  <!--[endif]--><?xml version="1.0"?>   

<!--[if !supportLists]-->2.  <!--[endif]--><?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  

<!--[if !supportLists]-->3.  <!--[endif]-->  

<!--[if !supportLists]-->4.  <!--[endif]--><configuration>   

<!--[if !supportLists]-->5.  <!--[endif]--><property>   

<!--[if !supportLists]-->6.  <!--[endif]-->    <name>fs.default.name</name>   

<!--[if !supportLists]-->7.  <!--[endif]-->    <value>hdfs://hadoop1:9000</value>   

<!--[if !supportLists]-->8.  <!--[endif]-->    <description>The name of the default file system. Either the literal string "local" or a host:port for DFS.</description>   

<!--[if !supportLists]-->9.  <!--[endif]--></property>   

<!--[if !supportLists]-->10. <!--[endif]--><property>   

<!--[if !supportLists]-->11. <!--[endif]-->    <name>mapred.job.tracker</name>   

<!--[if !supportLists]-->12. <!--[endif]-->    <value>hadoop1:9001</value>   

<!--[if !supportLists]-->13. <!--[endif]-->    <description>The host and port that the MapReduce job tracker runs at. If "local", then jobs are run in-process as a single map and reduc  

<!--[if !supportLists]-->14. <!--[endif]--></property>   

<!--[if !supportLists]-->15. <!--[endif]--><property>   

<!--[if !supportLists]-->16. <!--[endif]-->    <name>hadoop.tmp.dir</name>   

<!--[if !supportLists]-->17. <!--[endif]-->    <value>/search/hadoop/hadoop/tmp</value>   

<!--[if !supportLists]-->18. <!--[endif]-->    <description>A base for other temporary directories.</description>   

<!--[if !supportLists]-->19. <!--[endif]--></property>   

<!--[if !supportLists]-->20. <!--[endif]--><property>   

<!--[if !supportLists]-->21. <!--[endif]-->    <name>dfs.name.dir</name>   

<!--[if !supportLists]-->22. <!--[endif]-->    <value>/search/hadoop/hadoop/filesystem/name</value>   

<!--[if !supportLists]-->23. <!--[endif]-->    <description>Determines where on the local filesystem the DFS name node should store the name table. If this is a comma-delimited list of  

<!--[if !supportLists]-->24. <!--[endif]--></property>   

<!--[if !supportLists]-->25. <!--[endif]--><property>   

<!--[if !supportLists]-->26. <!--[endif]-->    <name>dfs.data.dir</name>   

<!--[if !supportLists]-->27. <!--[endif]-->    <value>/search/hadoop/hadoop/filesystem/data</value>   

<!--[if !supportLists]-->28. <!--[endif]-->    <description>Determines where on the local filesystem an DFS data node should store its blocks. If this is a comma-delimited list of dire  

<!--[if !supportLists]-->29. <!--[endif]--></property>   

<!--[if !supportLists]-->30. <!--[endif]--><property>   

<!--[if !supportLists]-->31. <!--[endif]-->    <name>dfs.replication</name>   

<!--[if !supportLists]-->32. <!--[endif]-->    <value>1</value>   

<!--[if !supportLists]-->33. <!--[endif]-->    <description>Default block replication. The actual number of replications can be specified when the file is created. The default is used   

<!--[if !supportLists]-->34. <!--[endif]--></property>   

<!--[if !supportLists]-->35. <!--[endif]--></configuration>  

 

(7) 修改所有机器的$HADOOP_HOME/conf/masters文件,指定了Master节点的IP;

修改所有机器的$HADOOP_HOME/conf/slaves文件,每行指定一个集群中slave节点的IP;

slaves文件示例如下

10.10.10.2

10.10.10.3

10.10.13.4

10.10.15.5

10.10.10.6

10.10.10.7

 

(8) 在Master节点上运行$ hadoop namenode -format 命令格式化namenode

 

(9) 在Master节点运行$HADOOP_HOME/bin/start-all.sh 启动hadoop。

(注意slave机器不用输入该命令,只需要在Master节点操作即可)

在shell中输入jps命令,查看启动的hadoop进程。例如

11304 DataNode

15763 Jps

11190 NameNode

11516 JobTracker

11636 TaskTracker

11437 SecondaryNameNode

注意Master节点中必须包括NameNode、SecondaryNameNode和JobTracker进程,

slave机器必须包括DataNode和TaskTracker进程才算启动成功。

补充:如果要停止,运行$HADOOP_HOME/bin/stop-all.sh

 

Hadoop查询接口

http://master机器IP:50070/dfshealth.jsp (HDFS运行情况)

http://master机器IP:50030/jobtracker.jsp (MapReduce运行情况)

Hadoop常用命令

Hadoop dfs –ls / 就是查看/目录下的内容,默认如果不填路径这就是当前用户路径;

Hadoop dfs –rmr xxx就是删除目录,还有很多命令看看就很容易上手;

Hadoop dfsadmin –report这个命令可以全局的查看DataNode的情况;

Hadoop job后面增加参数是对于当前运行的Job的操作,例如list,kill等;

Hadoop balancer就是前面提到的均衡磁盘负载的命令。

 

 HIVE配置

HIVE是基于hadoop分布式计算平台上的提供data warehouse的sql功能的一套软件。使得存储在hadoop里面的海量数据的汇总,即席查询简单化。hive提供了一套QL的查询语言,以sql为基础,使用起来很方便。Hadoop目录下实际上已经自带HIVE,但版本比较低,不推荐使用。

HIVE只需配置在Master节点,步骤如下

<!--[if !supportLists]-->(1)         <!--[endif]-->从官网下载hive-0.6.0-bin.tar.gz并解压缩产生hive-0.6.0-bin文件夹。

在$HADOOP_HOME/目录下建立名叫hive的软链接。

(2) 在/etc/profile增加环境变量

export HIVE_HOME=$HADOOP_HOME/hive

export PATH=$HIVE_HOME/bin:$PATH

(3) 运行如下命令

$ $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

(4) 这时已经可以通过命令行(CLI)使用HIVE了。但是这种方式只支持单用户,多用来测试。在实际应用中,往往要将HIVE的元数据(schemal)存入Mysql中。这样就可以支持多用户了。

<!--[if !supportLists]-->36. <!--[endif]--><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke join><!--[endif]-->

因此需要修改$HIVE_HOME/conf/hive-default.xml配置文件

配置项

javax.jdo.option.ConnectionURL

jdbc:mysql:///?createDatabaseIfNotExist=true

javax.jdo.option.ConnectionDriverName

com.mysql.jdbc.Driver

javax.jdo.option.ConnectionUserName

 

javax.jdo.option.ConnectionPassword

 

(参考文章http://www.mazsoft.com/blog/post/2010/02/01/Setting-up-HadoopHive-to-use-MySQL-as-metastore.aspx)

(5)从网上下载mysql-connector-java-5.1.11-bin.jar文件,并放到$HIVE_HOME/lib目录下,这时HIVE已经全部配置完了。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics