Home >Backend Development >PHP Tutorial >PHP调用SHELL下传本地文件到Hadoop的hdfs中

PHP调用SHELL下传本地文件到Hadoop的hdfs中

WBOY
WBOYOriginal
2016-06-13 10:38:271167browse

PHP调用SHELL上传本地文件到Hadoop的hdfs中

本来是用Thrift进行上传,但其上传效率之低,另人发指,只好选用其它方法。

?

环境:

php 运行环境为nginx + php-fpm

?

因为hadoop开启了权限控制,所以直接使用php调用shel进行上传时,没有权限。通过php执行命令看来,php运行的帐户和级均为nobody。因此,解决方法有两个:一,在hadoop的shell中创建目录,并把目录的所有者赋给nobody组的nobody用户。二,原来的目录权限放开,使用777。下面详讲操作步骤:

?

方法一:./hadoop fs -chown -R nobody:nobody /resources

注:/resources是用户目录,需要根据情况改变

?

方法二:./hadoop fs -chomod -R 777 /resources

注:/resources是用户目录,需要根据情况改变

?

php调用shell的方式:

public function uploadByShell($local, $hdfs) {						$shell =  "sh /usr/local/hadoop/hadoop-0.20.2/bin/hadoop fs -copyFromLocal " . $local ." " . $hdfs;			$shell .= "; sh /usr/local/hadoop/hadoop-0.20.2/bin/hadoop fs -chmod 777 " . $hdfs;			$res = null;			system($shell, $res);			$flag = false;			if ($res == "0") {				$flag = true;			}						return $flag;		}
?

?

?

?

?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn