Home  >  Article  >  Backend Development  >  php通过shell调用Hadoop的方法

php通过shell调用Hadoop的方法

WBOY
WBOYOriginal
2016-06-23 13:46:481038browse

1.php代码(index.php)

 <!-- <style> body{background-color:red} </style> --><!-- <style type="text/css"> --><!--  body { background:url(渐变绿.jpeg); --><!--       width:100%; --><!--       height:100%; } </style> --><?phpheader ('Content-type: text/html; charset=UTF8');#phpinfo();$jiaoben = $_GET['jiaoben'];echo "执行Hadoop的log信息:";$ret= system("sh /home/work/$jiaoben", $status);if($status != 0) { echo ' failed, status=' . "$status\n"; } else {	echo $ret;        echo "<br><br>";}?>


2.shell代码(hadoop.sh)

#!/bin/bashecho "wordCount test start"rm -rf ~/file_20141024mkdir ~/file_20141024cd ~/file_20141024echo "Hello World" > file1.txtecho "Hello China Beijing" > file2.txtcd /home/work/hadoop/bin ./hadoop dfs -rmr input_20141024./hadoop dfs -rmr output_20141024./hadoop fs -mkdir input_20141024#hadoop fs -chomod -R 777 /input_20141024./hadoop fs -put ~/file_20141024/file*.txt input_20141024./hadoop jar /home/work/hadoop/hadoop-examples-1.1.2.jar wordcount input_20141024 output_20141024./hadoop fs -ls output_20141024./hadoop fs -cat output_20141024/part-r-00000echo "wordCount test end"

3. 访问http://ip:8888/index.php?jiaoben=hadoop.sh

查询结果:

/user/work/output_20141024/part-r-00000 Beijing 1 China 1 Hello 2 World 1

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