warning: thrift-0.9.0-28.1.i686.rpm: Header V3 DSA/SHA1 Signature, key ID a949b429: NOKEY error: Failed dependencies: libc.so.6 is needed by thrift-0.9.0-28.1.i686 libc.so.6(GLIBC_2.0) is needed by thrift-0.9.0-28.1.i686 libc.so.6(GLIBC_2.1) is needed by thrift-0.9.0-28.1.i686 libc.so.6(GLIBC_2.1.3) is needed by thrift-0.9.0-28.1.i686 libc.so.6(GLIBC_2.3) is needed by thrift-0.9.0-28.1.i686 libc.so.6(GLIBC_2.3.4) is needed by thrift-0.9.0-28.1.i686 libc.so.6(GLIBC_2.4) is needed by thrift-0.9.0-28.1.i686 libgcc_s.so.1 is needed by thrift-0.9.0-28.1.i686 libgcc_s.so.1(GCC_3.0) is needed by thrift-0.9.0-28.1.i686 libm.so.6 is needed by thrift-0.9.0-28.1.i686 libstdc++.so.6 is needed by thrift-0.9.0-28.1.i686 libstdc++.so.6(CXXABI_1.3) is needed by thrift-0.9.0-28.1.i686 libstdc++.so.6(CXXABI_1.3.1) is needed by thrift-0.9.0-28.1.i686 libstdc++.so.6(GLIBCXX_3.4) is needed by thrift-0.9.0-28.1.i686 libstdc++.so.6(GLIBCXX_3.4.11) is needed by thrift-0.9.0-28.1.i686 libstdc++.so.6(GLIBCXX_3.4.9) is needed by thrift-0.9.0-28.1.i686
#报错, 缺少相关依赖. #解决libc.so.6依赖:
[root@localhost tools]# yum list glibc* [root@localhost tools]# yum install glibc.i686
<?php // Load this lib require_once__DIR__ . '/ThriftSQL.phar'; // 1.Try out a Hive query $hive = new \ThriftSQL\Hive('192.168.8.207', 21050); $hiveTables = $hive ->setSasl(false) // To turn SASL auth off, on by default ->connect() ->queryAndFetchAll('SHOW TABLES'); print_r($hiveTables); // 2.Try out an Impala query $impala = new \ThriftSQL\Impala('192.168.8.207'); $impalaTables = $impala ->connect() ->queryAndFetchAll('SHOW TABLES'); print_r($impalaTables); // 3.Try out an Impala query $impalaDatas = $impala ->connect() ->queryAndFetchAll('select * from db_mcfx_log.t_log_sdk_log_user'); print_r($impalaDatas); // 4.Don't forget to clear the client and close socket. $hive->disconnect(); $impala->disconnect(); ?>
[root@localhost ~]# cd /home/xxx/php-7.1.3 [root@localhost php-7.1.3]# cd ext/odbc/ [root@localhost odbc]# /application/php/bin/phpize [root@localhost odbc]# ./configure --help [root@localhost odbc]# ./configure --with-php-config=/xxx/php7.1.3/bin/php-config --with-unixODBC=/usr/ [root@localhost odbc]# make [root@localhost odbc]# make install Installing shared extensions: /xxx/php7.1.3/lib/php/extensions/no-debug-non-zts-20160303/ root@localhost odbc]# ll /xxx/php7.1.3/lib/php/extensions/no-debug-non-zts-20160303/ total 5556 -rwxr-xr-x 1 root root 350680 Mar 24 15:42 memcached.so -rwxr-xr-x 1 root root 255310 Mar 24 15:00 memcache.so -rwxr-xr-x 1 root root 173215 Jun 12 09:24 odbc.so -rwxr-xr-x 1 root root 3020972 Mar 24 14:23 opcache.a -rwxr-xr-x 1 root root 1750437 Mar 24 14:23 opcache.so -rwxr-xr-x 1 root root 126680 May 23 14:04 pdo_odbc.so # 编辑php.ini加入odbc.so扩展 [root@localhost odbc]# vim /xxx/php/lib/php.ini extension = odbc.so # 重启php查看配置信息: [root@localhost odbc]# /etc/init.d/php-fpm restart [root@localhost odbc]# php -i |grep odbc odbc odbc.allow_persistent => On => On odbc.check_persistent => On => On odbc.default_cursortype => Static cursor => Static cursor odbc.default_db => no value => no value odbc.default_pw => no value => no value odbc.default_user => no value => no value odbc.defaultbinmode => return as is => return as is odbc.defaultlrl => return up to 4096 bytes => return up to 4096 bytes odbc.max_links => Unlimited => Unlimited odbc.max_persistent => Unlimited => Unlimited PDO drivers => mysql, sqlite, odbc LD_LIBRARY_PATH => /usr/local/lib:/opt/cloudera/impalaodbc/lib/64 PWD => /xxx/php-7.1.3/ext/odbc $SERVER['LD_LIBRARY_PATH'] => /usr/local/lib:/opt/cloudera/impalaodbc/lib/64 $_SERVER['PWD'] => /xxx/php-7.1.3/ext/odbc
# 注意, 如果configure编译的时候出现报错如下: checking for Adabas support... cp: cannot stat'/usr/local/lib/odbclib.a': No such file or directory configure: error: ODBC header file '/usr/local/incl/sqlext.h' not found!
Specify any global ODBC configuration here such as ODBC tracing. [ODBC Data Sources] #Cloudera Hive 32-bit=Cloudera ODBC Driver for Apache Hive 32-bit impala=Cloudera ODBC Driver for Impala 64-bit [impala]
Description: DSN Description. This key is not necessary andisonlyto give a description of the data source. Description=Cloudera ODBC Driver for Impala (64-bit) DSN
Driver: The location where the ODBC driver is installed to. Driver=/opt/cloudera/impalaodbc/lib/64/libclouderaimpalaodbc64.so
The DriverUnicodeEncoding setting isonly used for SimbaDM When setto1, SimbaDM runs in UTF-16mode. When setto2, SimbaDM runs in UTF-8mode. #DriverUnicodeEncoding=2
Values for HOST, PORT, KrbFQDN, and KrbServiceName should beset here. They can also be specified on the connection string. HOST=xxx PORT=xxx Database=default
The authentication mechanism. 0 - No authentication (NOSASL) 1 - Kerberos authentication (SASL) 2 - Username authentication (SASL) 3 - Username/password authentication (NOSASL or SASL depending on UseSASL configuration) AuthMech=0
Set to1to use SASL for authentication. Set to0to not use SASL. When using Kerberos authentication (SASL) or Username authentication (SASL) SASL is always used and this configuration is ignored. SASL is always not used for No authentication (NOSASL). UseSASL=0
Kerberos related settings. KrbFQDN= KrbRealm= KrbServiceName=
Username/password authentication with SASL settings. UID=hdfs PWD=
Set to0to disable SSL. Set to1to enable SSL. SSL=0 CAIssuedCertNamesMismatch=1 TrustedCerts=/opt/cloudera/impalaodbc/lib/64/cacerts.pem
General settings TSaslTransportBufSize=1000 RowsFetchedPerBlock=10000 SocketTimeout=0 StringColumnLength=32767 UseNativeQuery=0
修改/etc/odbcins.ini替换为如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[ODBC Drivers] Cloudera ODBC Driver for Impala 64-bit=Installed #[Cloudera ODBC Driver for Apache Hive 32-bit] #Description=Cloudera ODBC Driver for Apache Hive (32-bit) #Driver=/opt/cloudera/hiveodbc/lib/32/libclouderahiveodbc32.so
The option below isfor using unixODBC when compiled with -DSQL_WCHART_CONVERT. Execute 'odbc_config --cflags'to determine if you need to uncomment it. IconvEncoding=UCS-4LE [Cloudera ODBC Driver for Impala 64-bit] Description=Cloudera ODBC Driver for Impala (64-bit) Driver=/opt/cloudera/impalaodbc/lib/64/libclouderaimpalaodbc64.so
The option below isfor using unixODBC when compiled with -DSQL_WCHART_CONVERT. Execute 'odbc_config --cflags'to determine if you need to uncomment it. IconvEncoding=UCS-4LE
- Note that this default DriverManagerEncoding of UTF-32isfor iODBC. - unixODBC uses UTF-16 by default. - If unixODBC was compiled with -DSQL_WCHART_CONVERT, then UTF-32is the correct value. ## Execute 'odbc_config --cflags'to determine if you need UTF-32or UTF-16on unixODBC
- SimbaDM can be used with UTF-8or UTF-16. ## The DriverUnicodeEncoding setting will cause SimbaDM to run in UTF-8 when setto2or UTF-16 when setto1. DriverManagerEncoding=UTF-32 ErrorMessagesPath=/opt/cloudera/impalaodbc/ErrorMessages LogLevel=0 LogPath=
- Uncomment the ODBCInstLib corresponding to the Driver Manager being used. - Note that the path to your ODBC Driver Manager must be specified in LD_LIBRARY_PATH (LIBPATH for AIX). - Note that AIX hasa different format for specifying its shared libraries. Generic ODBCInstLib # iODBC #ODBCInstLib=libiodbcinst.so # SimbaDM / unixODBC ODBCInstLib=libodbcinst.so
[root@localhost config_odbc]# vim odbc/odbc.ini 【注意里面包含了ODBC连接hive和impala的配置】
[ODBC] # Specify any global ODBC configuration here such as ODBC tracing. [ODBC Data Sources] #Cloudera Hive 32-bit=Cloudera ODBC Driver for Apache Hive 32-bit hive=Cloudera ODBC Driver for Apache Hive 64-bit impala=Cloudera ODBC Driver for Impala 64-bit [hive] # Description: DSN Description. # This key is not necessary andisonlyto give a description of the data source. Description=Cloudera ODBC Driver for Apache Hive (64-bit) DSN # Driver: The location where the ODBC driver is installed to. Driver=/opt/cloudera/hiveodbc/lib/64/libclouderahiveodbc64.so # When using No Service Discovery, specify the IP address or host name of the Hive server. # When using ZooKeeper as the Service Discovery Mode, specify a comma-separated list of ZooKeeper # servers in the following format: # <zk_host1:zk_port1>,<zk_host2:zk_port2>,... HOST=192.168.11.9 # The TCP port Hive server is listening. This is not required when using ZooKeeper as the service # discovery modeas the port is specified in the HOST connection attribute. PORT=10000 # The name of the database schema to use when a schema is not explicitly specified in a query. Schema=default # Set to0to when connecting directory to Hive Server 2 (No Service Discovery). # Set to1todo Hive Server 2 service discovery using ZooKeeper. # Note service discovery is not support when using Hive Server 1. ServiceDiscoveryMode=0 # The namespace on ZooKeeper under which Hive Server 2 znodes are added. Required only when doing # HS2 service discovery with ZooKeeper (ServiceDiscoveryMode=1). ZKNamespace= # Set to1if you are connecting to Hive Server 1. Set to2if you are connecting to Hive Server 2. HiveServerType=2 # The authentication mechanism to use for the connection. # Set to0for No Authentication # Set to1for Kerberos # Set to2for User Name # Set to3for User Name and Password # Note only No Authentication is supported when connecting to Hive Server 1. AuthMech=2 # The Thrift transport to use for the connection. # Set to0for Binary # Set to1for SASL # Set to2for HTTP # Note for Hive Server 1only Binary can be used. ThriftTransport=1 # When this option is enabled (1), the driver does not transform the queries emitted by an # application, so the native query is used. # When this option is disabled (0), the driver transforms the queries emitted by an application and # converts them into an equivalent from in HiveQL. UseNativeQuery=0 # Set the UID with the user name to use to access Hive when using AuthMech 2to8. UID=hdfs # The following is settings used when using Kerberos authentication (AuthMech 1and10) # The fully qualified host name part of the of the Hive Server 2 Kerberos service principal. # For example if the service principal name of you Hive Server 2 is: # hive/myhs2.mydomain.com@EXAMPLE.COM # Then set KrbHostFQDN to myhs2.mydomain.com KrbHostFQDN=_HOST # The service name part of the of the Hive Server 2 Kerberos service principal. # For example if the service principal name of you Hive Server 2 is: # hive/myhs2.mydomain.com@EXAMPLE.COM # Then set KrbServiceName to hive KrbServiceName=hive # The realm part of the of the Hive Server 2 Kerberos service principal. # For example if the service principal name of you Hive Server 2 is: # hive/myhs2.mydomain.com@EXAMPLE.COM # Then set KrbRealm to EXAMPLE.COM KrbRealm= # Set to1to enable SSL. Set to0to disable. SSL=0 # Set to1to enable two-way SSL. Set to0to disable. You must enable SSL in order to # use two-way SSL. TwoWaySSL=0 # The file containing the client certificate in PEM format. This is required when using two-way SSL. ClientCert= # The client private key. This is used for two-way SSL authentication. ClientPrivateKey= # The password for the client private key. Password isonly required for password protected # client private key. ClientPrivateKeyPassword= [impala] # Description: DSN Description. # This key is not necessary andisonlyto give a description of the data source. Description=Cloudera ODBC Driver for Impala (64-bit) DSN # Driver: The location where the ODBC driver is installed to. Driver=/opt/cloudera/impalaodbc/lib/64/libclouderaimpalaodbc64.so # The DriverUnicodeEncoding setting isonly used for SimbaDM # When setto1, SimbaDM runs in UTF-16mode. # When setto2, SimbaDM runs in UTF-8mode. #DriverUnicodeEncoding=2 # Values for HOST, PORT, KrbFQDN, and KrbServiceName should beset here. # They can also be specified on the connection string. HOST=192.168.11.10 PORT=21050 Database=default # The authentication mechanism. # 0 - No authentication (NOSASL) # 1 - Kerberos authentication (SASL) # 2 - Username authentication (SASL) # 3 - Username/password authentication (NOSASL or SASL depending on UseSASL configuration) AuthMech=3 # Set to1to use SASL for authentication. # Set to0to not use SASL. # When using Kerberos authentication (SASL) or Username authentication (SASL) SASL is always used # and this configuration is ignored. SASL is always not used for No authentication (NOSASL). UseSASL=0 # Kerberos related settings. KrbFQDN= KrbRealm= KrbServiceName= # Username/password authentication with SASL settings. UID=hdfs PWD= # Set to0to disable SSL. # Set to1to enable SSL. SSL=0 CAIssuedCertNamesMismatch=1 TrustedCerts=/opt/cloudera/impalaodbc/lib/64/cacerts.pem # General settings TSaslTransportBufSize=1000 RowsFetchedPerBlock=10000 SocketTimeout=0 StringColumnLength=32767 UseNativeQuery=0
[root@localhost config_odbc]# vim odbc/odbcinst.ini 【注意里面包含了ODBC连接hive和impala的配置】
[ODBC Drivers] Cloudera ODBC Driver for Apache Hive 64-bit=Installed Cloudera ODBC Driver for Impala 64-bit=Installed #[Cloudera ODBC Driver for Apache Hive 32-bit] #Description=Cloudera ODBC Driver for Apache Hive (32-bit) #Driver=/opt/cloudera/hiveodbc/lib/32/libclouderahiveodbc32.so [Cloudera ODBC Driver for Apache Hive 64-bit] Description=Cloudera ODBC Driver for Apache Hive (64-bit) Driver=/opt/cloudera/hiveodbc/lib/64/libclouderahiveodbc64.so ## The option below isfor using unixODBC when compiled with -DSQL_WCHART_CONVERT. ## Execute 'odbc_config --cflags'to determine if you need to uncomment it. # IconvEncoding=UCS-4LE [Cloudera ODBC Driver for Impala 64-bit] Description=Cloudera ODBC Driver for Impala (64-bit) Driver=/opt/cloudera/impalaodbc/lib/64/libclouderaimpalaodbc64.so ## The option below isfor using unixODBC when compiled with -DSQL_WCHART_CONVERT. ## Execute 'odbc_config --cflags'to determine if you need to uncomment it. # IconvEncoding=UCS-4LE
[root@localhost config_odbc]# vim odbc/cloudera.impalaodbc.ini 【注意里面包含了ODBC连接hive和impala的配置】
[Driver] ## - Note that this default DriverManagerEncoding of UTF-32isfor iODBC. ## - unixODBC uses UTF-16 by default. ## - If unixODBC was compiled with -DSQL_WCHART_CONVERT, then UTF-32is the correct value. ## Execute 'odbc_config --cflags'to determine if you need UTF-32or UTF-16on unixODBC ## - SimbaDM can be used with UTF-8or UTF-16. ## The DriverUnicodeEncoding setting will cause SimbaDM to run in UTF-8 when setto2or UTF-16 when setto1. DriverManagerEncoding=UTF-32 ErrorMessagesPath=/opt/cloudera/impalaodbc/ErrorMessages LogLevel=0 LogPath= ## - Uncomment the ODBCInstLib corresponding to the Driver Manager being used. ## - Note that the path to your ODBC Driver Manager must be specified in LD_LIBRARY_PATH (LIBPATH for AIX). ## - Note that AIX hasa different format for specifying its shared libraries. # Generic ODBCInstLib # iODBC #ODBCInstLib=libiodbcinst.so # SimbaDM / unixODBC ODBCInstLib=libodbcinst.so # AIX specific ODBCInstLib # iODBC #ODBCInstLib=libiodbcinst.a(libiodbcinst.so.2) # SimbaDM #ODBCInstLib=libodbcinst.a(odbcinst.so) # unixODBC #ODBCInstLib=libodbcinst.a(libodbcinst.so.1)
创建配置cloudera.hiveodbc.ini
1 2 3 4 5 6 7
[root@localhost config_odbc]# vim odbc/cloudera.hiveodbc.ini 【注意里面包含了ODBC连接hive和impala的配置】
[root@localhost config_odbc]# isql -v 'impala' [S1000][unixODBC][Cloudera][ImpalaODBC] (100) Error from the Impala Thrift API: connect() failed: Connection timed out [ISQL]ERROR: Could not SQLConnect