欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php连接hive各种问题记录

程序员文章站 2022-04-26 17:19:05
...

一、hive方面 hive有三种模式:cli、hwi、hiveserver; cli:即shell命令行 hwi:是通过浏览器访问 hiveserver:也就是JDBC/ODBC接口 其中hwi没有用到 深入浅出学hive:http://sishuok.com/forum/blogPost/list/6220.html(初学hive,这个系列介绍的很不错)

一、hive方面

hive有三种模式:cli、hwi、hiveserver;

cli:即shell命令行

hwi:是通过浏览器访问

hiveserver:也就是JDBC/ODBC接口

其中hwi没有用到

深入浅出学hive:http://sishuok.com/forum/blogPost/list/6220.html(初学hive,这个系列介绍的很不错)

启动hiveserver:

1.org.apache.thrift.transport.TTransportException: Could not create ServerSocket on address 0.0.0.0/0.0.0.0:10000.

可能原因:默认端口10000已被占用

查看端口是否被占用: netstat -ntulp | grep ':10000'

发现被一个java进程占用

解决方法:另起端口开启hiveserver:hive --service hiveserver -p 10001

2.启动hiveserver卡住

网上一些博客解释说是已经在运行,不用担心http://www.cnblogs.com/sh91/archive/2012/08/03/2621911.html

启动hive(cli)

1.执行语句出错(例如show tables)

FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

可能原因:metadata相关,也就是和连接mysql有关了(采用mysql作为hive的元数据库)

采用debug模式启动hive cli:hive -hiveconf hive.root.logger=DEBUG,console

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Caused by: java.net.ConnectException: 骁豢妤(这边有点乱码问题,是windows下的ssh软件造成的)

Caused by: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient

Caused by: java.lang.reflect.InvocationTargetException

Caused by: javax.jdo.JDOFatalDataStoreException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
NestedThrowables:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


二、mysql方面

登陆mysql出错:mysql -uhive -p

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

查看mysql运行状态:/etc/rc.d/init.d/mysqld status

发现mysql已停

root权限下启动mysql:service mysqld start(失败);、etc/init.d/mysqld start(也失败)

提示:Another MySQL daemon already running with the same unix socket.

关闭所有mysqld进程:killall -9 mysqld

考虑卸载原装mysql:http://www.jb51.net/os/RedHat/1146.html http://www.2cto.com/os/201108/100257.html http://blog.csdn.net/monkey_d_meng/article/details/5573610

查找mysql相关包:rpm -qa|grep mysql
mysql-server-5.1.71-1.el6.i686 变成not installed(why???)
mysql-connector-java-5.1.17-6.el6.noarch OK!
mysql-5.1.71-1.el6.i686 OK!
libdbi-dbd-mysql-0.8.3-5.1.el6.i686 OK!
mysql-libs-5.1.71-1.el6.i686 变成not installed(why???)
mod_auth_mysql-3.0.0-11.el6_0.1.i686 OK!
mysql-connector-odbc-5.1.5r1144-7.el6.i686 OK!
php-mysql-5.3.3-26.el6.i686 OK!
mysql-devel-5.1.71-1.el6.i686 OK!
qt-mysql-4.6.2-26.el6_4.i686 OK!
删除相关包的命令: rpm -e --nodeps (包名)
接下来删除mysql: rm -fr /usr/lib/mysql rm -fr /usr/include/mysql(/usr/include目录下没有mysql)
rm -f /etc/my.cnf rm -rf /var/lib/mysql
验证: sudo yum -y remove mysql-5.1.71-1.el6.i686
提示:Loaded plugins: refresh-packagekit, security
Setting up Remove Process
No Match for argument: mysql-5.1.71-1.el6.i686
Package(s) mysql-5.1.71-1.el6.i686 available, but not installed.
No Packages marked for removal
证明已经删除成功!

再根据官方说明(http://dev.mysql.com/doc/refman/5.6/en/linux-installation-rpm.html)查找了相关目录,都已经没有mysql

接下来,手动安装自己的mysql
mysql官方推荐:

The recommended way to install MySQL on RPM-based Linux distributions that useglibc is by using the RPM packages provided by MySQL. There are two methods for doing so: for EL6-based platforms and Fedora 18 and 19, this can be done using the MySQL Yum repository (seediv 2.5.1, “Installing MySQL on Linux Using the MySQL Yum Repository” for details)

因此,通过rpm来安装,按照官网教程进行安装

安装成功,终于可以正常启动mysql了!

再重新为hive创建用户跟数据库就可以了(注意和配置文件hive-site.xml对应)

3.php连接相关

前提:开启hadoop(2.2.0版本改为start-dfs.sh和start-yarn.sh)

开启hiveserver(当然mysql也是要开起来)

php文件放在/wamp/www/下

在浏览器输入/localhost/hiveconnect.php就可以看到了

问题:

输入url,一直等待localhost,hive日志内容只有session相关信息

解决:

TException TSocket tiomeout:

这个问题最后并没有解决,只是发现hive大多数用于内网应用,于是直接往内网发展,连接一切正常。

4.hadoop方面

启动hadoop:start-dfs.sh start-yarn.sh

各个进程正常启动,但是之后发生问题,nodemanager shutdown:

org.apache.hadoop.yarn.exceptions.YarnRuntimeException: org.apache.hadoop.net.ConnectTimeoutException: Call From sipedi-idc-gysj/220.250.64.225 to 0.0.0.0:8031 failed on socket timeout exception: org.apache.hadoop.net.ConnectTimeoutException: 20000 millis timeout while waiting for channel to be ready for connect. ch : java.nio.channels.SocketChannel[connection-pending remote=0.0.0.0/0.0.0.0:8031];

这个问题也是出现在外网服务器上,和PHP连接的问题一样,改到内网应用,就没有再出现,但是估计这个问题应该是跟服务器的linux版本以及hadoop的具体配置有关,具体YARN的运行机制等到寒假再研究。