1
votes

Has anybody got into a strange environment issue and been forced to use SU rather than SUDO when calling hadoop commands?

sudo su -c 'hadoop fs -ls /' hdfs
Found 4 items
drwxr-xr-x   - hdfs   hdfs          0 2014-02-11 12:33 /apps
drwx------   - mapred hdfs          0 2014-03-10 10:25 /mapred
drwxrwxrwx   - hdfs   hdfs          0 2014-03-10 10:26 /tmp
drwxr-xr-x   - hdfs   hdfs          0 2014-02-11 12:34 /user

The environment allows finding of the executable:

sudo -u hdfs 'hadoop' 
Usage: hadoop [--config confdir] COMMAND
where COMMAND is one of:
  namenode -format     format the DFS filesystem
...
  fs                   run a generic filesystem user client
...
...
Most commands print help when invoked w/o parameters.
sudo -u hdfs 'hadoop fs -ls /' 
sudo: hadoop fs -ls: command not found

I wondered if it was an environment issue, but this gave me no hints:

sudo su -c 'env' hdfs | sort >sudo_su.txt
sudo -u hdfs 'env' | sort >sudo.txt
diff sudo.txt sudo_su.txt
11a12
> PWD=/home/user
14c15,16
 SHLVL=1
> SUDO_COMMAND=/bin/su -c env hdfs
20a23
> _=/usr/bin/env
1
Normally, you shouldn't even be asked to run hadoop as a super user. Have you installed hadoop as another user than the currently logged in user (perhaps hdfs user)? Typically, in most tutorials, hadoop is installed by a user called 'hduser', who belongs to the 'hadoop' group.vefthym
Moreover, is $HADOOP_HOME/bin/ added to the $PATH variable? Have you tried to run these commands from within the above folder as hdfs?vefthym
both sudo and su allows command execution as any user - above I'm effectively executing the same command (or so I thought) one way as "substitute user" the other as "substitute user do". I want to run as sudo because I don't know the hdfs/mapred/hbase passwords and I need to run as a target user...rupert160
Regarding path variables, you'll note the output of the 'env' command there to prove that one environment was no more "able" than the other. EG the path is the same in both and yet "sudo su" works but "su" does not. Both commands are run as "my user" and su'd to the hdfs user as shown.rupert160

1 Answers

14
votes

Drop the quotes around your hadoop command:

sudo -u hdfs hadoop fs -ls /