Prerequisites
- OS: Linux (RHEL 7.9)
- $ sudo yum install wget
- OpenJDK 64-Bit 1.8.0_292
- Hadoop: Cloudera (CDH 6.1.1)
- LDAP and Kerberos KDC
- MIT Kerberos configured
- krb5.conf
- hiveimpalatester.keytab
- SSL configured
- certs.jks
- Cloudera JDBC drivers:
References
- Cloudera drivers:
- SQLLine:
Hive/Impala SQLLine Tester
prepare directory
mkdir sqllinetester && cd sqllinetester
download SQLLine with-dependencies
wget https://repo1.maven.org/maven2/sqlline/sqlline/1.11.0/sqlline-1.11.0-jar-with-dependencies.jar
chmod +x sqlline-1.11.0-jar-with-dependencies.jar
download Hive JDBC driver
wget https://repository.cloudera.com/artifactory/cdh-build/Hive/HiveJDBC42/2.6.15.1018/HiveJDBC42-2.6.15.1018.jar
chmod +x HiveJDBC42-2.6.15.1018.jar
download Impala JDBC driver
wget https://repository.cloudera.com/artifactory/cdh-build/Impala/ImpalaJDBC42/2.6.15.1017/ImpalaJDBC42-2.6.15.1017.jar
chmod +x ImpalaJDBC42-2.6.15.1017.jar
obtain TGT in ticket cache
# kinit -kt <path-to-keytab> <client-principal>
kinit -kt /etc/security/keytabs/hiveimpalatester.keytab hiveimpalatester
execute SQLLine with the jars in the classpath
java -cp "./*" sqlline.SqlLine
check if JDBC drivers are loaded
sqlline> !scan
scan complete in 84ms
3 driver classes found
Compliant Version Driver Class
no 2.6 com.cloudera.hive.jdbc.HS1Driver
no 2.6 com.cloudera.hive.jdbc.HS2Driver
no 2.6 com.cloudera.impala.jdbc.Driver
# class names:
# com.cloudera.impala.jdbc.Driver
# com.cloudera.hive.jdbc.HS2Driver
connect to Hive via Hive JDBC
sqlline> !connect jdbc:hive2://<hs2_node>:10000/default;AuthMech=1;ssl=1;sslTrustStore=/<path>/certs.jks;KrbRealm=<krb_realm>;KrbHostFQDN=_HOST;KrbServiceName=hive;KrbAuthType=2;
# When you authenticate via Kerberos, sqlline will ask for username/password. When prompted, just press Enter and Enter.
0: jdbc:hive2://<hs2_node> show tables;
connect to Impala via Impala JDBC
sqlline> !connect jdbc:impala://<impala-load-balancer>:21050/default;AuthMech=1;ssl=1;sslTrustStore=/<path>/certs.jks;KrbRealm=<krb_realm>;KrbHostFQDN=_HOST;KrbServiceName=impala;KrbAuthType=2;
# When you authenticate via Kerberos, sqlline will ask for username/password. When prompted, just press Enter and Enter.
0: jdbc:impala://<impala-load-balancer> show tables;
exit SQLLine
sqlline> !quit
Additional Info
AuthMech
- 0: no authentication
- 1: Kerberos
- 2: user name
- 3: user name and password
- 4: user name and password with SSL
KrbAuthType
- 0: To configure the driver to automatically detect which method to use for obtaining the Subject, set the KrbAuthType property to 0. Alternatively, do not set the KrbAuthType property.
- 1: Or, to create a LoginContext from a JAAS configuration and then use the Subject associated with it, set the KrbAuthType property to 1.
- 2: Or, to create a LoginContext from a Kerberos ticket cache and then use the Subject associated with it, set the KrbAuthType property to 2.