1. 程式人生 > >sqoop-1.4.7安裝(一)

sqoop-1.4.7安裝(一)

(一):簡介和環境說明

sqoop是apache旗下一款Hadoop和關係資料庫伺服器之間傳送資料”的工具。

  匯入資料:MySQL,Oracle匯入資料到Hadoop的HDFS、HIVE、HBASE等資料儲存系統;

  匯出資料:從Hadoop的檔案系統中匯出資料到關係資料庫

環境:centos7,hadoop-2.7.6,hbase-1.3.2,zookeeper-3.4.10

3臺Linux虛擬機器
# 主機名稱,ip地址
master: 192.168.61.132
slaver1: 192.168.61.130
slaver2: 192.168.61.131

下載地址:http://mirrors.hust.edu.cn/apache/sqoop/1.4.7/sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz 

(二):安裝部署

1.解壓檔案

cd /usr/local/services/

tar -zxvf sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz

mv sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz sqoop

2.修改環境變數

sudo vim /etc/profile

新增以下內容:

export SQOOP_HOME=/usr/local/sqoop-1.4.6

export PATH=$SQOOP_HOME/bin:$PATH

儲存檔案,執行source /etc/profile使環境變數生效。

檢驗生效方法:

sqoop version

3.修改sqoop-env.sh配置檔案

cd /usr/local/services/sqoop/conf/

cp sqoop-env-template.sh sqoop-env.sh

vi sqoop-env.sh

#Set path to where bin/hadoop is available
export HADOOP_COMMON_HOME=/usr/local/services/hadoop

#Set path to where hadoop-*-core.jar is available
export HADOOP_MAPRED_HOME=/usr/local/services/hadoop

#set the path to where bin/hbase is available
export HBASE_HOME=/usr/local/services/hbase

#Set the path to where bin/hive is available
#export HIVE_HOME=

#Set the path for where zookeper config dir is
export ZOOCFGDIR=/usr/local/services/zookeeper

4.修改configure-sqoop檔案

cd /usr/local/services/sqoop/bin/

vi configure-sqoop

註釋掉以下程式碼

#if [ -z "${HCAT_HOME}" ]; then
#  if [ -d "/usr/lib/hive-hcatalog" ]; then
#    HCAT_HOME=/usr/lib/hive-hcatalog
#  elif [ -d "/usr/lib/hcatalog" ]; then
#    HCAT_HOME=/usr/lib/hcatalog
#  else
#    HCAT_HOME=${SQOOP_HOME}/../hive-hcatalog
#    if [ ! -d ${HCAT_HOME} ]; then
#       HCAT_HOME=${SQOOP_HOME}/../hcatalog
#    fi
#  fi
#fi
#if [ -z "${ACCUMULO_HOME}" ]; then
#  if [ -d "/usr/lib/accumulo" ]; then
#    ACCUMULO_HOME=/usr/lib/accumulo
#  else
#    ACCUMULO_HOME=${SQOOP_HOME}/../accumulo
#  fi
#fi
 
## Moved to be a runtime check in sqoop.
#if [ ! -d "${HCAT_HOME}" ]; then
#  echo "Warning: $HCAT_HOME does not exist! HCatalog jobs will fail."
#  echo 'Please set $HCAT_HOME to the root of your HCatalog installation.'
#fi
 
#if [ ! -d "${ACCUMULO_HOME}" ]; then
#  echo "Warning: $ACCUMULO_HOME does not exist! Accumulo imports will fail."
#  echo 'Please set $ACCUMULO_HOME to the root of your Accumulo installation.'
#fi

5.放入資料庫連線jar包

(1)oracle:將ojdbc6.jar 放入/usr/local/services/sqoop/lib/下

cp ojdbc6.jar /usr/local/services/sqoop/lib/

(2)mysql:將mysql-connector-java-5.1.34.jar 放入/usr/local/services/sqoop/lib/下

cp mysql-connector-java-5.1.34.jar /usr/local/services/sqoop/lib/

6.啟動sqoop測試

sqoop list-tables --connect jdbc:oracle:thin:@192.168.61.1:1521:orcl --username user --password password

list-tables:顯示資料庫下的所有表名

orcl:你的資料庫

user:使用者名稱

password:密碼

結果展示:

(7):sqoop從oracle匯入hbase

前提:hadoop,hbase,zookeeper啟動成功

sqoop import --append --connect jdbc:oracle:thin:@192.168.61.1:1521:orcl --username user--password passowrd --m 1 --table BAYONET --columns ID,BAYONETID,BAYONETNAME --hbase-create-table --hbase-table Bayonet --hbase-row-key ID --column-family BayonetInfo

結果展示: