Heim  >  Artikel  >  Backend-Entwicklung  >  PHP调用SHELL下传本地文件到Hadoop的hdfs中

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

WBOY
WBOYOriginal
2016-06-13 13:19:51859Durchsuche

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;
		}
?

?

?

?

?

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn