Oracle JDBC 连接hive

manual: https://docs.cloudera.com/documentation/enterprise/5-6-x/topics/cdh_ig_hive_metastore_configure.html

 

 第一步

安装环境:CENOS8

1)安装JDBC DRIVER

Oracle Database 19c (19.6) JDBC Driver & UCP Downloads

https://www.oracle.com/database/technologies/appdev/jdbc-ucp-19-6-c-downloads.html

 因为下载的是18c的express edition,所以点击18c行下载对应的drivers:https://www.oracle.com/database/technologies/appdev/jdbc-ucp-183-downloads.html

 名称:ojdbc8-full.tar.gz

 [root@bigdata Downloads]# tar zxf ojdbc8-full.tar.gz

[root@bigdata Downloads]# cd ojdbc8-full/

[root@bigdata ojdbc8-full]# cp ojdbc8.jar /home/admin/Downloads/apache-hive-2.3.7/lib

[root@bigdata lib]# pwd
/home/admin/Downloads/apache-hive-2.3.7/lib

[root@bigdata lib]# ls |grep ojdbc
ojdbc8.jar

后来添加了ojdbc6.jar 不知道有没有影响

第二步

2)安装oracle express edition

安装教程:https://docs.oracle.com/en/database/oracle/oracle-database/18/xeinl/procedure-installing-oracle-database-xe.html

下载安装包:https://www.oracle.com/database/technologies/appdev/xe.html

oracle-database-xe-18c-1.0-1.x86_64.rpm

在CentOS8,需要设置个参数才能看到sharefolder。输入:

/usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o subtype=vmhgfs-fuse,allow_other

[root@bigdata] cd /mnt/hgfs/ShareFolder

下载oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm

# curl -o oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm

安装oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm

# yum -y localinstall oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm
执行报错
[root@bigdata ShareFolder]# yum -y localinstall oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm Last metadata expiration check: 0:07:08 ago on Wed 20 May 2020 07:36:26 PM CST. Error: Problem: conflicting requests - nothing provides compat-libcap1 needed by oracle-database-preinstall-18c-1.0-1.el7.x86_64 - nothing provides compat-libstdc++-33 needed by oracle-database-preinstall-18c-1.0-1.el7.x86_64 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

   如何解决 缺少2个需要的package? 

网友方案,但是我没有完全采纳。ref1:https://community.oracle.com/thread/4303249,其实只要把缺的包安装下就好了。

1)google compat-libcap1,有很多资源。我下载了compat-libcap1-1.10-7.el7.x86_64.rpm。

https://www.rpmfind.net/linux/rpm2html/search.php?query=compat-libcap1

[root@bigdata ShareFolder]# rpm -ivh compat-libcap1-1.10-7.el7.x86_64.rpm

同理:下载compat-libstdc++-33: compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm

[root@bigdata ShareFolder]# rpm -ivh compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm

 再次执行 yum -y localinstall oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm 安装成功!

Installed:
  oracle-database-preinstall-18c-1.0-1.el7.x86_64           ksh-20120801-253.el8_1.x86_64       
  sysstat-11.7.3-2.el8.x86_64                               libaio-devel-0.3.112-1.el8.x86_64   
  lm_sensors-libs-3.4.0-20.20180522git70f7e08.el8.x86_64    make-1:4.2.1-9.el8.x86_64           

Complete!
如果没有运行xx-preinstall-xxx.rpm,直接运行oracle-database-xe-xx.rpm会报错,如下:
[root@bigdata ShareFolder]
# yum -y localinstall oracle-database-xe-18c-1.0-1.x86_64.rpm Last metadata expiration check: 0:08:33 ago on Wed 20 May 2020 07:36:26 PM CST. Error: Problem: conflicting requests - nothing provides oracle-database-preinstall-18c needed by oracle-database-xe-18c-1.0-1.x86_64 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

安装oracle-database-xe-18c-1.0-1.x86_64.rpm 

 [root@bigdata ShareFolder]# yum -y localinstall oracle-database-xe-18c-1.0-1.x86_64.rpm 

[INFO] Executing post installation scripts...
[INFO] Oracle home installed successfully and ready to be configured.
To configure Oracle Database XE, optionally modify the parameters in '/etc/sysconfig/oracle-xe-18c.conf' and then execute '/etc/init.d/oracle-xe-18c configure' as root.

  Verifying        : oracle-database-xe-18c-1.0-1.x86_64                                     1/1 

Installed:
  oracle-database-xe-18c-1.0-1.x86_64                                                            

Complete!  安装成功!
[root@localhost ShareFolder]#  /etc/init.d/oracle-xe-18c configure

The location '/opt/oracle' specified for database files has insufficient space. Database creation needs at least '4.5GB' disk space. Specify a different database file destination that has enough space in the configuration file '/etc/sysconfig/oracle-xe-18c.conf'.

 有点小意外,磁盘空间不够了,用gparted可视化工具增加10G磁盘空间。 Ref 2:https://www.jianshu.com/p/1d020b01177c

yum install epel-release

yum install gparted

Gpart使用方法请google一下。

lvextend /dev/mapper/cl-root -L +2G
fsadm resize /dev/mapper/cl-root 19G
[root@bigdata displayFolder]#  /etc/init.d/oracle-xe-18c configure
Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. 
Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts: Confirm the password: Configuring Oracle Listener. Listener configuration succeeded. Configuring Oracle Database XE. Enter SYS user password: **** Enter SYSTEM user password: ***** Enter PDBADMIN User Password: ***** Prepare for db operation 7% complete Copying database files

29% complete
Creating and starting Oracle instance
30% complete
31% complete
34% complete

38% complete

41% complete
43% complete
Completing Database Creation
47% complete
50% complete
Creating Pluggable Databases
54% complete
71% complete
Executing Post Configuration Actions
93% complete
Running Custom Scripts
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/XE.
Database Information:
Global Database Name:XE
System Identifier(SID):XE
Look at the log file "/opt/oracle/cfgtoollogs/dbca/XE/XE.log" for further details.


Connect to Oracle Database using one of the connect strings:
Pluggable database: bigdata/XEPDB1
Multitenant container database: bigdata
Use https://localhost:5500/em to access Oracle Enterprise Manager for Oracle Database XE

登录mozilla,需要安装flash后,浏览ORACLE Enterprise Manager Database Express 18c:https://localhost:5500/em 

需要运行下面这句话,才能进入网站。

SQL> exec dbms_xdb_config.SetGlobalPortEnabled(TRUE)  --You should enable global port for EM Express to Manage a CDB and the PDBs

 

 ref-Linux如何安装flash:https://jingyan.baidu.com/album/90bc8fc8b7b6a7f653640cab.html?picindex=2

[root@bigdata dbhomeXE]# pwd
/opt/oracle/product/18c/dbhomeXE

配置一下.bash_profile

[root@bigdata /]# cat /home/oracle/.bash_profile
# .bash_profile
export ORACLE_BASE=/opt/oracle/
export ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
export ORACLE_SID=XE
export PATH=$ORACLE_HOME/bin:$PATH

cd <oracle_home>in

sqlplus / as sysdba

cd <oracle_home>in

lsnrctl status 

[root@bigdata bin]# sqlplus system@localhost:1521/XEPDB1

登录报错:

SQL> conn /as sysdba  
;ERROR:
ORA-01017: invalid username/password; logon denied

解决方案:

1)In order for you to connect as sysdba with no password, your OS user needs to be a member of a special group. On Windows - it's called ora_dba

2)或者su - oracle

[oracle@bigdata ~]$ sqlplus / as sysdba

Connected.

 更改oracle密码:

SQL> alter user sys identified by "1QAZxsw2";

User altered.

SQL> alter user system identified by "1QAZxsw2";

User altered.

第三步:

Create the Metastore database and user account

schema很重要 

[root@bigdata oracle]# cd $HIVE_HOME/scripts/metastore/upgrade/oracle

 /home/admin/Downloads/apache-hive-2.3.7/scripts/metastore/upgrade/oracle

[root@bigdata oracle]# ls | grep hive-schema
hive-schema-0.10.0.oracle.sql
hive-schema-0.11.0.oracle.sql
hive-schema-0.12.0.oracle.sql
hive-schema-0.13.0.oracle.sql
hive-schema-0.14.0.oracle.sql
hive-schema-0.9.0.oracle.sql
hive-schema-1.1.0.oracle.sql
hive-schema-1.2.0.oracle.sql
hive-schema-1.3.0.oracle.sql
hive-schema-2.0.0.oracle.sql
hive-schema-2.1.0.oracle.sql
hive-schema-2.2.0.oracle.sql
hive-schema-2.3.0.oracle.sql  <-----

 SQL> @/usr/lib/hive/scripts/metastore/upgrade/oracle/hive-schema-2.3.0.oracle.sql

 @/home/admin/Downloads/apache-hive-2.3.7/scripts/metastore/upgrade/oracle/hive-schema-2.3.0.oracle.sql 

 我的oracle默认连接CBD, 大家根据实际情况处理。

$ sqlplus "sys as sysdba"
select *from v$pdbs;
CBD下:
SQL> CREATE USER C##hive identified by hive; 
grant connect to C##hive; 
grant all privileges to C##hive;

PDB下:
alter session set container = XEPDB1;
因为安装好后,默认启动在Container db(cdb)下,所以切换到pdb(pluggable db)。
-- switch to the corresponding pluggable databases via the alter session command --alter session set container=CDB$ROOT;
【为什么alter session?】因为在Container db下,create user
hive 时报错:ERROR at line 1:ORA-65096: invalid common user or role name.
Ref: https://dbtut.com/index.php/2019/10/31/how-to-connect-to-container-database-cdb-and-pluggable-databases-pdb-in-oracle-12c/
-------------------------------------------------------------------------
SQL> CREATE USER hive identified by hive;
grant connect to hive; 
grant all privileges to hive;


  in the /opt/mapr/hive//hive-<version>/conf/hive-site.xml file.

Suppose an Oracle database running on myhost and the user account hiveuser with the password mypassword, set the following properties (overwriting any existing values) in the hive-site.xml file:
<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:oracle:thin:@//myhost/metastore</value>
</property>
 
<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>oracle.jdbc.OracleDriver</value>
</property>
 
<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>hiveuser</value>
</property>
 
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>mypassword</value>
</property>
 
<property>
  <name>hive.metastore.uris</name>
  <value>thrift://<n.n.n.n>:9083</value>
  <description>IP address (or fully-qualified domain name) and port of the metastore host</description>
</property>
<n.n.n.n> 记得改成ip

Run schemaTool to create the initial DB structure.

/opt/mapr/hive/hive-<version>/bin/schematool -dbType oracle -initSchema
[root@bigdata bin]# pwd
/home/admin/Downloads/apache-hive-2.3.7/bin
[root@bigdata bin]# schematool -dbType oracle -initSchema
or
/home/admin/Downloads/apache-hive-2.3.7/bin/schematool -dbType oracle -initSchema
 

以下报错,是因为

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/admin/Downloads/apache-hive-2.3.7/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/admin/Downloads/hadoop-2.10.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL:     jdbc:oracle:thin:@//localhost/XE
Metastore Connection Driver :     oracle.jdbc.OracleDriver
Metastore connection User:     hive
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
Underlying cause: java.sql.SQLException : ORA-01017: invalid username/password; logon denied

SQL Error code: 1017
Use --verbose for detailed stacktrace.

 解决:hive-site.xml中将用户改为CDB的C##hive。

<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>C##hive</value>
</property>
[oracle@bigdata oracle]$ /home/admin/Downloads/apache-hive-2.3.7/bin/schematool -dbType oracle -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/admin/Downloads/apache-hive-2.3.7/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/admin/Downloads/hadoop-2.10.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL:     jdbc:oracle:thin:@//localhost/XE
Metastore Connection Driver :     oracle.jdbc.OracleDriver
Metastore connection User:     C##hive
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.oracle.sql
Initialization script completed
schemaTool completed

ref: https://mapr.com/docs/61/Hive/Config-RemoteOracleDBForHiveMetastore.html

 第四步

配置SQL DEVELOPER

工具-首选项-数据库-第三发JDBC驱动程序

 

 配置完毕!

成功!~~

其他Hive问题:

SQLDeveloper链接hive报错

状态: 失败 -测试失败: [Cloudera][HiveJDBCDriver](500164) Error initialized or created transport for authentication: java.net.ConnectException: Connection refused: connect.

 一般是hiveserver2没有跑起来,或者beeline没有起来

我自己碰到的是imetastore的问题。

  $ hive --service metastore

 hiveserver2跑起来后,localhost:10002就能展示网页。

beeline> !connect jdbc:hive2://localhost:10000/

其他ORACLE安装问题:

根据ref1中所述,需要yum install很多个文件,其实不用,比如下面这个安装就不用执行,它里面没有compat-libstdc++-33的包。

[root@bigdata ShareFolder]# yum install -y gcc-c++

Installed:
gcc-c++-8.3.1-4.5.el8.x86_64 cpp-8.3.1-4.5.el8.x86_64 
gcc-8.3.1-4.5.el8.x86_64 isl-0.16.1-6.el8.x86_64 
libstdc++-devel-8.3.1-4.5.el8.x86_64 glibc-devel-2.28-72.el8_1.1.x86_64 
glibc-headers-2.28-72.el8_1.1.x86_64 kernel-headers-4.18.0-147.8.1.el8_1.x86_64 
libxcrypt-devel-4.1.1-4.el8.x86_64

 ================================

自用请忽略:

D:Downloadshive_jdbc_2.5.202.5.20.1060ClouderaHiveJDBC-2.5.20.1060ClouderaHiveJDBC41-2.5.20.1060

Ref 3:EPEL:https://fedoraproject.org/wiki/EPEL

Ref 4:官方安装文档:https://docs.oracle.com/en/database/oracle/oracle-database/18/xeinw/database-express-edition-installation-guide-microsoft-windows.pdf

https://cwiki.apache.org/confluence/display/Hive/AdminManual+Metastore+Administration

原文地址:https://www.cnblogs.com/watermarks/p/12925794.html