1、基本环境篇
操作系统:Ubuntu 16.04 LTS
Hadoop:2.9
2、安装及配置mysql
(1)安装mysql
$ sudo apt-get update
$ sudo apt-get install mysql-server
(2)启动mysql
$ service mysql start
(3)设置mysql开启自启动
$ sudo update-rc.d mysql enable
(4)为Hive的metastore创建元数据库
进入mysql shell:
$ mysql -u root -p
创建hive的metastore数据库:
mysql> create database hive;
为hive的metastore创建用户:
mysql> create user 'hive'@'localhost' identified by 'Hive12@!';
mysql> revoke all privileges,grant option from 'hive'@'localhost';
mysql> grant all privileges on hive.* to 'hive'@'localhost';
mysql> flush privileges;
3、安装及配置Hive
(1)安装Hive
下载后将Hive安装到/usr/local:
$ sudo tar -zxf ~/下载/apache-hive-1.2.2-bin.tar.gz -C /usr/local
$ cd usr/local
$ sudo mv apache-hive-1.2.2-bin.tar.gz hive
$ sudo chown -R hadoop:hadoop hive //hadoop:hadoop 为当前登录用户组及用户
(2)配置Hive环境变量:
$ sudo vim ~/.bashrc
在文件最前方添加如下内容:
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin
export HADOOP_HOME=/usr/local/hadoop
//若已添加,此处不须重复添加
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$HIVE_HOME/lib/*
(3)修改/usr/local/hive/conf下配置文件
$ cd /usr/local/hive/conf
$ sudo mv hive-default.xml.template hive-default.xml
$ sudo vim hive-site.xml
添加如下内容:
javax.jdo.option.ConnectionURL
jdbc:mysql://localhost:3306/hive
JDBC connect string for a JDBC metastore
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
javax.jdo.option.ConnectionUserName
hive
username to use against metastore database
javax.jdo.option.ConnectionPassword
Hive12@!
password to use against metastore database
datanucleus.autoCreateSchema
false
datanucleus.fixedDatastore
true
datanucleus.autoStartMechanism
SchemaTable
hive.metastore.uris
thrift://n.n.n.n:9083
IP adress or fully-qualified domain name of the metastore host
hive.metastore.schema.verification
true
(4)为hive添加mysql-jdbc连接驱动
下载mysql jdbc包,并将其解压后复制到 /usr/local/hive/lib下:
$ tar -zxf ~/下载/mysql-connector-java-5.1.46.tar.gz
$ cd ~/下载/mysql-connector-java-5.1.46
$ cp mysql-connector-java-5.1.46-bin.jar /usr/local/hive/lib
(5)使用schematool进行metastore初始化
$ schematool -dbType mysql -initSchema
(6)启动metastore server
$ cd /usr/local/hive/bin
$ hive --service metastore
(7)启动hive
$ hive
(8)创建hive数据库
hive> create database oracledb;
4、安装及配置sqoop
(1)下载并安装sqoop:
$ sudo tar -zxf ~/下载/sqoop-1.4.7.tar.gz -C /usr/local
$ cd /usr/local
$ sudo mv sqoop-1.4.7 sqoop
(3)配置环境变量:
$ sudo vim ~/.bashrc
在文件中添加:
export SQOOP_HOME=/usr/local/sqoop
export PATH=$PATH:$SQOOP_HOME/bin
使环境变量生效:
$ source ~/.bashrc
(4)配置sqoop:
$ cd /usr/local/sqoop/conf
$ sudo mv sqoop-env-template.sh sqoop-env.sh
$ sudo vim sqoop-env.sh
便捷文件将设置以下行的注释去掉,并添加路径:
export HADOOP_COMMON_HOME=/usr/local/hadoop
export HADOOP_MAPRED_HOME=/usr/local/hadoop
export HBASE_HOME=/usr/local/hbase
export HIVE_HOME=/usr/local/hive
export ZOOCFGDIR=/usr/local/zookeeper
5、下载并配置Oracle的java连接驱动
(1)下载并将oracle的java驱动包复制到sqoop安装路径下的lib目录下。
6、将Oracle数据导入到Hive
$ cd /usr/local/sqoop/bin
$ sqoop import --hive-import --connect jdbc:oracle:thin:@172.18.9.25:1521:iesdb --username=ies_ms --password=iesapp --table KAIGUAN --hive-database oracledb -m 1