Execute hadoop jar from PHP Server fails. Permissi

2019-06-02 11:32发布

问题:

I am trying to execute a jar file to do a simple query on my HBase database, from a PHP Server, so i can print the results to a webpage.

PHP Server in configured with same username as hadoop user, and same group too.

The PHP exec command is:

exec("bash /usr/local/hadoop/bin/hadoop  jar myjar.jar my.package.MyClass   2> php_error.log", $result);

I get this exception when i try to exec the command(in the php_error.log):

Exception in thread "main" java.io.IOException: Permission denied
    at java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.io.File.createTempFile(File.java:1879)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:115)

I know its related to permissions, but even with 777 on my HDFS, and on hadoop installation folders, it doesnt work.

Any ideas? Thank you.

Also, where this temp file wants to be created? Hadoop dir? hdfs? Where?

Edit: running this locally, it works perfectly! no permission errors! hadoop jar myjar.jar my.package.MyClass

回答1:

Your PHP is ok. The problem is, that the command you are running is trying to copy the file to the hadoop.tmp.dir. It's default location is /tmp/hadoop-${user.name}. You have to give the permissions to that folder too, or the full /tmp/hadoop directory recursively

Edit:

Figured out that apache isn't a valid user in that case. The solution is to create a new user, add it to hadoop group, set permissions to jar, and hadoop.tmp.dir and change the webpage owner to the created user