Taking Importing Data from Oracle to HBase as an example, this section introduces how to use the sqoop-shell tool to create and start Loader jobs in the interaction mode and batch mode.
The Loader client has been installed and configured.
cd /opt/hadoopclient/Loader/loader-tools-1.99.3/sqoop-shell/conf
vi client.properties
server.url=10.0.0.1:21351 # simple or kerberos authentication.type=simple # true or false use.keytab=true authentication.user= authentication.password= client.principal=oracle/hadoop@<system domain name> # keytab file client.keytab.file=./conf/login/oracle.keytab
Log in to FusionInsight Manager and choose System > Permission > Domain and Mutual Trust. The value of Local Domain is the current system domain name.
source /opt/hadoopclient/bigdata_env
cd /opt/hadoopclient/Loader/loader-tools-1.99.3/sqoop-shell
./sqoop2-shell
The preceding commands obtain authentication information by reading the configuration file.
Alternatively, you can also use the password or Kerberos authentication.
Run the following command to authenticate login using the password mode:
./sqoop2-shell -uk false -u username -p encryptedPassword
Run the following command to authenticate login using the Kerberos mode:
./sqoop2-shell -uk true -k user.keytab -s userPrincipal
Welcome to sqoop client Use the username and password authentication mode Authentication success. Sqoop Shell: Type 'help' or '\h' for help. sqoop:000>
show connector
The following information is displayed:
+----+----------------------------+----------------+----------------------------------------------------------------------+ | Id | Name | Version | Class | +----+----------------------------+----------------+----------------------------------------------------------------------+ | 1 | generic-jdbc-connector | XXX | org.apache.sqoop.connector.jdbc.GenericJdbcConnector | | 2 | ftp-connector | XXX | org.apache.sqoop.connector.ftp.FtpConnector | | 3 | hdfs-connector | XXX | org.apache.sqoop.connector.hdfs.HdfsConnector | | 4 | oracle-connector | XXX | org.apache.sqoop.connector.oracle.OracleConnector | | 5 | mysql-fastpath-connector | XXX | org.apache.sqoop.connector.mysql.MySqlConnector | | 6 | sftp-connector | XXX | org.apache.sqoop.connector.sftp.SftpConnector | | 7 | oracle-partition-connector | XXX | org.apache.sqoop.connector.oracle.partition.OraclePartitionConnector | +----+----------------------------+----------------+----------------------------------------------------------------------+
The preceding information indicates that the Oracle connector ID is 4.
create connection -c connector ID
For example, if the connector ID is 4, run the following command:
create connection -c 4
sqoop:000> create connection -c 4 Creating connection for connector with id 4 Please fill following values to create new connection object Name: oracle14 Oracle connection configuration JDBC connection string: jdbc:oracle:thin:@189.120.84.106:1521:orcl Username: oracledba Password: ********** JDBC connection properties: There are currently 0 values in the map: entry# New connection was successfully created with validation status FINE and persistent id 3 sqoop:000>
The preceding information indicates that the connection ID is 3.
create job -x connection ID -t import --trans absolute path of job-config/oracle-hbase.json
For example, if the connection ID is 3, run the following command:
create job -x 3 -t import --trans /opt/hadoopclient/Loader/loader-tools-1.99.3/loader-tool/job-config/oracle-hbase.json
The following information is displayed:
sqoop:000> create job -x 3 -t import --trans /opt/hadoopclient/Loader/loader-tools-1.99.3/loader-tool/job-config/oracle-to-hbase.json Creating job for connection with id 3 Please fill following values to create new job object Name: run Database target Table name: test Columns: Conditions: Data split method: 0 : ROWID 1 : PARTITION Choose: Table Partitions: Data split allocation method: 0 : ROUNDROBIN 1 : SEQUENTIAL 2 : RANDOM Choose: JDBC fetch size: Output configuration Storage type: 0 : HDFS 1 : HBASE_BULKLOAD 2 : HBASE_PUTLIST 3 : HIVE 4 : SPARK Choose: 1 HBase instance: HBase Clear data before import : false Throttling resources Extractors: 10 Extractor size: New job was successfully created with validation status FINE and persistent id 7 sqoop:000>
The preceding information indicates that the job ID is 7.
start job -j job ID -s
For example, if the job ID is 7, run the following command:
start job -j 7 -s
Displaying the
information indicates that the job is started successfully.Submission details Job ID: 7 Server URL: https://10.0.0.0:21351/loader/ Created by: admintest Creation date: 2019-12-04 16:37:34 CST Lastly updated by: admintest 2019-12-04 16:37:34 CST: BOOTING - Progress is not available 2019-12-04 16:37:42 CST: BOOTING - 0.00 % 2019-12-04 16:37:42 CST: BOOTING - 0.00 % 2019-12-04 16:37:57 CST: RUNNING - 0.00 % 2019-12-04 16:38:12 CST: RUNNING - 45.00 % 2019-12-04 16:38:12 CST: RUNNING - 45.00 % 2019-12-04 16:38:27 CST: SUCCEEDED
cd /opt/hadoopclient/Loader/loader-tools-1.99.3/sqoop-shell/conf
server.url=10.0.0.1:21351 # simple or kerberos authentication.type=simple # true or false use.keytab=true authentication.user= authentication.password= client.principal=hdfs/hadoop.@<system domain name>@<system domain name> # keytab file client.keytab.file=./conf/login/hdfs.keytab
cd /opt/hadoopclient/Loader/loader-tools-1.99.3/sqoop-shell
vi batchCommand.sh
An example of batchCommand.sh is displayed as follows:
View parameters create connection -c 4 --help // Create a connector create connection -c 4 -name oracle-connection --connector-connection-oracleServerIp 10.0.0.1 --connector-connection-oracleServerPort 22 --connector-connection-oracleUser root --connector-connection-oraclePassword xxxxx Create a job create job -t import -x 3 --connector-file-inputPath /opt/tempfile --connector-file-fileFilter * --framework-output-outputDirectory /user/loader/1 --framework-output-storageType HBase --framework-throttling-extractorSize 120 --framework-output-fileType TEXT_FILE --connector-file-splitType FILE -name test Start a job start job -j 7 -s
xxxxx is the password for the connector.
./sqoop2-shell batchCommand.sh
The commands above authenticate login by reading configuration files. Alternatively, you can attach the authentication information to the command, that is, use the password mode or Kerberos mode to authenticate login.
Run the following command to authenticate login using the password mode:
./sqoop2-shell -uk false -u username -p encryptedPassword batchCommand.sh
Run the following command to authenticate login using the Kerberos mode:
./sqoop2-shell -uk true -k user.keytab -s userPrincipal batchCommand.sh
Displaying the SUCCEEDED information indicates that the job is started successfully.
Welcome to sqoop client Use the username and password authentication mode Authentication success. sqoop:000> create connection -c 4 --help usage: Show connection viparameters: --connector-connection-oraclePassword <arg> --connector-connection-oracleServerIp <arg> --connector-connection-oracleServerPort <arg> --connector-connection-oracleUser <arg> --framework-security-maxConnections <arg> --name <arg> ===> FINE sqoop:000> create connection -c 4 -name oracle-connection --connector-connection-oracleServerIp 10.0.0.1 --connector-connection-oracleServerPort 22 --connector-connection-oracleUser root --connector-connection-oraclePassword xxxxx Creating connection for connector with id 4 New connection was successfully created with validation status FINE and persistent id 3 ===> FINE sqoop:000> create job -t import -x 3 --connector-file-inputPath /opt/tempfile --connector-file-fileFilter * --framework-output-outputDirectory /user/loader/1 --framework-output-storageType HDFS --framework-throttling-extractorSize 120 --framework-output-fileType TEXT_FILE --connector-file-splitType FILE -name test Creating job for connection with id 3 New job was successfully created with validation status FINE and persistent id 7 ===> FINE Submission details Job ID: 7 Server URL: https://10.0.0.0:21351/loader/ Created by: admintest Creation date: 2019-12-04 16:37:34 CST Lastly updated by: admintest 2019-12-04 16:37:34 CST: BOOTING - Progress is not available 2019-12-04 16:37:42 CST: BOOTING - 0.00 % 2019-12-04 16:37:42 CST: BOOTING - 0.00 % 2019-12-04 16:37:57 CST: RUNNING - 0.00 % 2019-12-04 16:38:12 CST: RUNNING - 45.00 % 2019-12-04 16:38:12 CST: RUNNING - 45.00 % 2019-12-04 16:38:27 CST: SUCCEEDED
Run the following command to create a connection:
./sqoop2-shell -c "create connection -c 4 -name oracle-connection --connector-connection-oracleServerIp 10.0.0.1 --connector-connection-oracleServerPort 22 --connector-connection-oracleUser root --connector-connection-oraclePassword xxxxx"
You can also use the password mode or Kerberos mode to attach the authentication information to the command.
Run the following command to authenticate login using the password mode:
./sqoop2-shell -uk false -u username -p encryptedPassword -c "create connection -c 4 -name oracle-connection --connector-connection-oracleerverIp 10.0.0.1 --connector-connection-oracleServerPort 22 --connector-connection-oracleUser root --connector-connection-oraclePassword xxxxx"
Run the following command to authenticate login using the Kerberos mode:
./sqoop2-shell -uk true -k user.keytab -s userPrincipal -c "create connection -c 4 -name oracle-connection --connector-connection-oracleServerIp 10.0.0.1 --connector-connection-oracleServerPort 22 --connector-connection-oracleUser root --connector-connection-oraclePassword xxxxx"
Displaying the FINE information indicates the connection is created successfully.
Welcome to sqoop client Use the username and password authentication mode Authentication success. sqoop:000> create connection -c 4 -name oracle-connection --connector-connection-oracleServerIp 10.0.0.1 --connector-connection-oracleServerPort 22 --connector-connection-oracleUser root --connector-connection-oraclePassword xxxxx Creating connection for connector with id 4 New connection was successfully created with validation status FINE and persistent id 3 ===> FINE