php通过shell调用Hadoop的方法

7 篇文章 0 订阅
7 篇文章 0 订阅

1.php代码(index.php)

<!DOCTYPE html>
<html>
 
<!-- <style> body{background-color:red} </style> -->
<!-- <style type="text/css"> -->
<!--  body { background:url(渐变绿.jpeg); -->
<!--       width:100%; -->
<!--       height:100%; } </style> -->
<body>
<?php
header('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>";
}

?>
</body>
</html>


2.shell代码(hadoop.sh)

#!/bin/bash
echo "wordCount test start"
rm -rf ~/file_20141024
mkdir ~/file_20141024
cd ~/file_20141024
echo "Hello World" > file1.txt
echo "Hello China Beijing" > file2.txt
cd /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-00000
echo "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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值