程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> 用php實現對HDFS的操作

用php實現對HDFS的操作

編輯:PHP綜合

用php實現對HDFS的操作,大體步驟如下:

wget https://dist.apache.org/repos/dist/release/thrift/0.9.0/thrift-0.9.0.tar.gz    
tar zxvf thrift-0.9.0.tar.gz    
cd thrift-0.9.0    
find / -name 'bootstrap.sh'
yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel   
/tmp/thrift-0.9.0/contrib/fb303/bootstrap.sh    
./configure -prefix=/usr/local/thrift    
make //安裝期間網絡不可中斷    
make install    
cp -R ./lib/php/ /usr/local/thrift/lib/    
cp -R /tmp/hadoop-1.0.4/src/contrib/thriftfs/gen-php/ /usr/local/thrift/lib/php/src/packages/hadoopfs/    
cd ./lib/php/src/ext/thrift_protocol/    
yum install php-devel    
/usr/bin/phpize    
./configure    
make    
make test    
make install    
vim /etc/php.ini    
cd /tmp/hadoop-1.0.4/src/contrib/thriftfs/scripts/    
/tmp/hadoop-1.0.4/src/contrib/thriftfs/scripts/start_thrift_server.sh

在修改了/tmp/hadoop-1.0.4/src/contrib/thriftfs/scripts/start_thrift_server.sh文件中對TOP和CLASSPATH行後,甚至更換了thrift版本到0.2.0依然出現如下錯誤(運行上述21行的結果)。

[root@srv211 hadoop-1.0.4]# /tmp/hadoop-1.0.4/src/contrib/thriftfs/scripts/start_thrift_server.sh 59256    
log4j:ERROR Could not instantiate class [org.apache.hadoop.log.metrics.EventCounter].    
java.lang.ClassNotFoundException: org.apache.hadoop.log.metrics.EventCounter    
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)    
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)    
        at java.security.AccessController.doPrivileged(Native Method)    
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)    
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)    
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)    
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)    
        at java.lang.Class.forName0(Native Method)    
        at java.lang.Class.forName(Class.java:186)    
        at org.apache.log4j.helpers.Loader.loadClass(Loader.java:179)    
        at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:320)    
        at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:121)    
        at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:664)    
        at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)    
        at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)    
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)    
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)    
        at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)    
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)    
        at org.apache.log4j.Logger.getLogger(Logger.java:105)    
        at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:289)    
        at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:109)    
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)    
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)    
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)    
        at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1116)    
        at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914)    
        at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)    
        at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)    
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:704)    
        at org.apache.hadoop.thriftfs.HadoopThriftServer$HadoopThriftHandler.<clinit>(HadoopThriftServer.java:41)    
        at org.apache.hadoop.thriftfs.HadoopThriftServer.<init>(HadoopThriftServer.java:592)    
        at org.apache.hadoop.thriftfs.HadoopThriftServer.main(HadoopThriftServer.java:612)    
log4j:ERROR Could not instantiate appender named "EventCounter".    
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration    
        at org.apache.hadoop.thriftfs.HadoopThriftServer$HadoopThriftHandler.<init>(HadoopThriftServer.java:125)    
        at org.apache.hadoop.thriftfs.HadoopThriftServer.<init>(HadoopThriftServer.java:592)    
        at org.apache.hadoop.thriftfs.HadoopThriftServer.main(HadoopThriftServer.java:612)    
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration    
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)    
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)    
        at java.security.AccessController.doPrivileged(Native Method)    
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)    
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)    
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)    
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)    
        ... 3 more    
[root@srv211 hadoop-1.0.4]#

從網上查找了一些方法(其中包括修改/tmp/hadoop-1.0.4/conf/log4j.properties文件,把log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter替換成log4j.appender.EventCounter=org.apache.hadoop.log.metrics.jvm.EventCounter)試了試都不行。

既然別人的可以,自己的卻不可以。那就要考慮軟件環境問題了。與承載Hadoop的操作系統應該是關系不大。可能的就是Hadoop的版本和java SDK的版本了。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved