那一天,人们终于回想起了被BUG支配的恐惧
Toggle navigation
Home
AboutMe
Links
Archives
Tags
Hadoop+Hive环境搭建
2017-02-22 23:27:42
867
0
0
weibo-007
#Hadoop+Hive环境搭建 ##JDK安装 由于国内城墙的原因,访问官网下载速度有点慢,这里csdn上下来资源。`jdk安装包`下载地址: >http://download.csdn.net/download/love254443233/9179483 下载下来上传到Linux服务器上,使用`rz`命令即可,如果没有这个命令,`安装rz`参照这篇文章 >http://blog.csdn.net/kobejayandy/article/details/13291655 1. 解压jdk-7u79-linux-x64.tar.gz ``` [root@S140530 ~]# tar zxvf jdk-7u79-linux-x64.tar.gz ``` 2. 在/root/.bash_profile中添加如下配置 ``` export JAVA_HOME=/root/jdk1.7.0_79 export PATH=$JAVA_HOME/bin:$PATH ``` 3. 使环境变量生效,执行以下命令 ``` [root@S140530 ~]# source ~/.bash_profile ``` 4. 安装验证,执行java命令 ``` [root@S140530 ~]# java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode) ``` ##Hadoop安装 ###下载解压 1. 下载Hadoop2.7.1 ``` wget "http://mirrors.hust.edu.cn/apache/hadoop/common/hadoop-2.7.1/hadoop-2.7.1.tar.gz" ``` 2. 复制hadoop-2.7.1.tar.gz 到/usr/hadoop目录下 ``` [root@S140530 hadoop]# makedir /usr/hadoop [root@S140530 hadoop]# cp hadoop-2.7.1.tar.gz /usr/hadoop/ ``` 3. 解压Hadoop-2.7.1.tar.gz ``` [root@S140530 hadoop]# tar zxvf /usr/hadoop/hadoop-2.7.1.tar.gz ``` 4. 建立以下目录,备用 ``` [root@S140530 hadoop]# mkdir /usr/hadoop/tmp [root@S140530 hadoop]# mkdir /usr/hadoop/hdfs [root@S140530 hadoop]# mkdir /usr/hadoop/hdfs/data [root@S140530 hadoop]# mkdir /usr/hadoop/hdfs/name ``` 5. 设置环境变量,vim ~/.bash_profile添加以下两行 ``` export HADOOP_HOME=/usr/hadoop/hadoop-2.7.1 export PATH=$PATH:$HADOOP_HOME/bin ``` 6. 使环境变量生效 ``` source ~/.bash_profile ``` ###Hadoop配置 1. 配置/usr/hadoop/hadoop-2.7.1/etc/hadoop/hadoop-env.sh,把原来的注释掉,添加JDK安装绝对路径 ``` #export JAVA_HOME=${JAVA_HOME} export JAVA_HOME=/root/jdk1.7.0_79 ``` 2. 配置/usr/hadoop/hadoop-2.7.1/etc/hadoop/yarn-env.sh,同样加入JDK绝对路径 ``` # export JAVA_HOME=/home/y/libexec/jdk1.6.0/ export JAVA_HOME=/root/jdk1.7.0_79 ``` 3. 配置/usr/hadoop/hadoop-2.7.1/etc/hadoop/core-site.xml ``` <property> <name>fs.default.name</name> <value>hdfs://localhost:9000</value> <description>HDFS的URI,文件系统://namenode标识:端口号</description> </property> <property> <name>hadoop.tmp.dir</name> <value>/usr/hadoop/tmp</value> <description>namenode上本地的hadoop临时文件夹</description> </property> ``` 4. 配置/usr/hadoop/hadoop-2.7.1/etc/hadoop/hdfs-site.xml ``` <configuration> <!—hdfs-site.xml--> <property> <name>dfs.name.dir</name> <value>/usr/hadoop/hdfs/name</value> <description>namenode上存储hdfs名字空间元数据 </description> </property> <property> <name>dfs.data.dir</name> <value>/usr/hadoop/hdfs/data</value> <description>datanode上数据块的物理存储位置</description> </property> <property> <name>dfs.replication</name> <value>1</value> <description>副本个数,配置默认是3,应小于datanode机器数量</description> </property> </configuration> ``` 5. 配置/usr/hadoop/hadoop-2.7.1/etc/hadoop/mapred-site.xml ``` <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration> ``` 6. 配置/usr/hadoop/hadoop-2.7.1/etc/hadoop/yarn-site.xml ``` <configuration> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.resourcemanager.webapp.address</name> <value>221.220.52.205:8099</value> </property> </configuration> ``` ###启动服务 1. 格式Namenode ``` [root@S140530 hadoop-2.7.1]bin/hdfs namenode ``` 注意,如果这一步出现WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 请按照这位兄台的答案操作 >https://zhidao.baidu.com/question/2267528668586222188.html 2. 启动NameNode 和 DataNode 守护进程 ``` [root@S140530 hadoop-2.7.1]# sbin/start-dfs.sh ``` 3. 启动ResourceManager 和 NodeManager 守护进程 ``` [root@S140530 hadoop-2.7.1]# sbin/start-yarn.sh ``` ###验证启动 ``` [root@S140530 hadoop-2.7.1]# jps 7465 NodeManager 4207 SecondaryNameNode 4062 DataNode 7969 NameNode 8402 Jps 8297 ResourceManager ``` 一定要看到上面的所有列表,如果有那个没启动,在Hadoop的log日志里面找找原因。 ##Hive安装 Hive就是Hadoop底层数据的SQL查询支持,Hive的元数据需要放在MySQL中,所以先安装MySQL ###MySQL安装 这里使用yum命令直接安装,如果已经安装了MySQL,可以忽略这一步 ``` [root@S140530 mysql]# yum install -y mysql-server mysql mysql-deve ``` 安装完成之后启动MySQL ``` [root@S140530 mysql]# service mysqld start ``` ###在MySQL中设置hive用户 1. 登录MySQL 默认情况下使用无密码的root用户登录 ``` [root@S140530 mysql]# /usr/bin/mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> ``` 出现MySQL命令提示符之后,执行以下SQL ``` mysql> insert into mysql.user(Host,User,Password) values("localhost","hive",password("hive")); mysql> create database hive; mysql> grant all on hive.* to hive@'%' identified by 'hive'; mysql> grant all on hive.* to hive@'localhost' identified by 'hive'; mysql> flush privileges; ``` 执行完成之后,测试刚才创建的hive账户,如果能登录成功,表示创建完成。 ``` [root@S140530 mysql]# mysql -uhive -phive ``` ###Hive的安装 准备环境做好之后,终于可以安装Hive了。 1. 下载hive安装包 ``` [root@S140530 ~]# wget "http://apache.fayea.com/hive/hive-1.1.1/apache-hive-1.1.1-bin.tar.gz" ``` 2. 将hive安装包拷贝到/usr/hadoop目录并解压 ``` [root@S140530] cp apache-hive-1.1.1-bin.tar.gz /usr/hadoop/ [root@S140530] tar /usr/hadoop/zxvf apache-hive-1.1.1-bin.tar.gz ``` 3. 添加环境变量 ``` export HIVE_HOME=/usr/hadoop/apache-hive-1.1.1-bin export PATH=$PATH:$HIVE_HOME/bin ``` 4. 让环境变量生效 ``` [root@S140530 hadoop]# source ~/.bash_profile ``` 5. 修改hive配置文件 /usr/hadoop/apache-hive-1.1.1-bin/conf/hive-site.xml 编写以下内容 ``` <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/hive?characterEncoding=UTF-8</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>hive</value> </property> </configuration> ``` 2. java的MySQL驱动 下载地址: ``` http://ftp.ntu.edu.tw/MySQL/Downloads/Connector-J/ ``` 记住,用高本版,笔者用5.1.40,否则也会出现MySQL连接问题。下载解压之后,将解压出来的jar文件放到Hive安装目录的lib目录下。 3. 启动hive ``` [root@S140530 apache-hive-1.1.1-bin]# hive hive> show databases; OK default Time taken: 2.326 seconds, Fetched: 1 row(s) ``` 表示hive启动成功
Pre:
Socket网络编程入门
Next:
MySQL索引
0
likes
867
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.