昨日实现了用java对HDFS的操作(创建、删除、重命名目录,创建、删除、重命名文件),今天打算用php实现对HDFS的同样操作。
大体步骤如下:
 
   
   
   
   
  1. wget https://dist.apache.org/repos/dist/release/thrift/0.9.0/thrift-0.9.0.tar.gz 
  2. tar zxvf thrift-0.9.0.tar.gz 
  3. cd thrift-0.9.0 
  4. find / -name 'bootstrap.sh' 
  5. yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel
  6. /tmp/thrift-0.9.0/contrib/fb303/bootstrap.sh 
  7. ./configure -prefix=/usr/local/thrift 
  8. make //安装期间网络不可中断 
  9. make install 
  10. cp -R ./lib/php/ /usr/local/thrift/lib/ 
  11. cp -R /tmp/hadoop-1.0.4/src/contrib/thriftfs/gen-php/ /usr/local/thrift/lib/php/src/packages/hadoopfs/ 
  12. cd ./lib/php/src/ext/thrift_protocol/ 
  13. yum install php-devel 
  14. /usr/bin/phpize 
  15. ./configure 
  16. make 
  17. make test 
  18. make install 
  19. vim /etc/php.ini 
  20. cd /tmp/hadoop-1.0.4/src/contrib/thriftfs/scripts/ 
  21. /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行的结果)。
   
   
   
   
  1. [root@srv211 hadoop-1.0.4]# /tmp/hadoop-1.0.4/src/contrib/thriftfs/scripts/start_thrift_server.sh 59256 
  2. log4j:ERROR Could not instantiate class [org.apache.hadoop.log.metrics.EventCounter]. 
  3. java.lang.ClassNotFoundException: org.apache.hadoop.log.metrics.EventCounter 
  4.         at java.net.URLClassLoader$1.run(URLClassLoader.java:366
  5.         at java.net.URLClassLoader$1.run(URLClassLoader.java:355
  6.         at java.security.AccessController.doPrivileged(Native Method) 
  7.         at java.net.URLClassLoader.findClass(URLClassLoader.java:354
  8.         at java.lang.ClassLoader.loadClass(ClassLoader.java:423
  9.         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308
  10.         at java.lang.ClassLoader.loadClass(ClassLoader.java:356
  11.         at java.lang.Class.forName0(Native Method) 
  12.         at java.lang.Class.forName(Class.java:186
  13.         at org.apache.log4j.helpers.Loader.loadClass(Loader.java:179
  14.         at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:320
  15.         at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:121
  16.         at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:664
  17.         at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647
  18.         at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544
  19.         at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440
  20.         at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476
  21.         at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471
  22.         at org.apache.log4j.LogManager.(LogManager.java:125
  23.         at org.apache.log4j.Logger.getLogger(Logger.java:105
  24.         at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:289
  25.         at org.apache.commons.logging.impl.Log4JLogger.(Log4JLogger.java:109
  26.         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
  27.         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57
  28.         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45
  29.         at java.lang.reflect.Constructor.newInstance(Constructor.java:525
  30.         at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1116
  31.         at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914
  32.         at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604
  33.         at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336
  34.         at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:704
  35.         at org.apache.hadoop.thriftfs.HadoopThriftServer$HadoopThriftHandler.(HadoopThriftServer.java:41
  36.         at org.apache.hadoop.thriftfs.HadoopThriftServer.(HadoopThriftServer.java:592
  37.         at org.apache.hadoop.thriftfs.HadoopThriftServer.main(HadoopThriftServer.java:612
  38. log4j:ERROR Could not instantiate appender named "EventCounter"
  39. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration 
  40.         at org.apache.hadoop.thriftfs.HadoopThriftServer$HadoopThriftHandler.(HadoopThriftServer.java:125
  41.         at org.apache.hadoop.thriftfs.HadoopThriftServer.(HadoopThriftServer.java:592
  42.         at org.apache.hadoop.thriftfs.HadoopThriftServer.main(HadoopThriftServer.java:612
  43. Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration 
  44.         at java.net.URLClassLoader$1.run(URLClassLoader.java:366
  45.         at java.net.URLClassLoader$1.run(URLClassLoader.java:355
  46.         at java.security.AccessController.doPrivileged(Native Method) 
  47.         at java.net.URLClassLoader.findClass(URLClassLoader.java:354
  48.         at java.lang.ClassLoader.loadClass(ClassLoader.java:423
  49.         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308
  50.         at java.lang.ClassLoader.loadClass(ClassLoader.java:356
  51.         ... 3 more 
  52. [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的版本了。