Run HDFS as sudo user - bash

Due to a script I am using to install Hadoop, I am having to run all commands as sudo. I am trying to start HDFS by typing "start-dfs.sh", but it says
sudo: start-dfs.sh: command not found
I typed the full path name i.e. sudo /home/ubuntu/hadoop-2.2.0/sbin/start-dfs.sh, but that did not work either. Does anyone know how I can start the HDFS service as sudo? Thanks in advance!

Related

JPS command shows only JPS

I installed hadoop and tried to run it. The terminal shows that everything has been started but when i run jps command it shows only jps. I am new to ubuntu and we need to use for academics can anyone help me run it.
I installed java using sudo apt-get install open-jdk
My usr/lib/jvm directory looks like this
The following are my hadoop configuration files:
Its probably due to the users you are using . I can see start-all.sh with different user and jps with a different user. Run both commands with the same user

Run gcloud without sudo

I'm on Mac OSX and I've always had to run the gcloud command with sudo. I can usually work around it, but it has started to cause me some issues. I tried following this answer here, but I am not sure where the gcloud command gets called from. It's not in /usr/bin.
I have found that my gcloud sdk is installed at /Users/Max/Desktop/google-cloud-sdk/, and I have tried adding /bin/gcloud and '/lib/gcloud.py' from that path. No luck! Any idea how I can give NOPASSWD permissions to this command?
I'm on macOS and my issue was that my google-cloud-sdk install folder and it's config folder at ~/.config/gcloud were owned by root. The fix is to sudo chown -R <your-username> google-cloud-skd and sudo chown -R <your-username> ~/.config/gcloud. And done: no more sudo.
I was able to resolve this issue myself. This article was very helpful. Ultimately, you just have to add sudo privileges to the gcloud command. You will have to give those permissions by running sudo visudo and adding a line in the following format:
<yourusername> ALL=NOPASSWD: <command1>, <command2>
Mine line ended up looking like this:
Max ALL=NOPASSWD: /Users/Max/Desktop/google-cloud-sdk/bin/gcloud
The part that tripped me up was figuring out where the gcloud command was installed. You have to add that path at the end of the permissions. You can find out where it is installed by running which gcloud.

How do I start MongoDB in a script?

I'm trying to create a script to start different things. Whenever I add the below to the script and run it, I get a message: "mongod: unrecognized service". I can use it in the terminal, but not through the script.
sudo service mongod start
I got it to start just using sudo service mongod start. The .sh file was created in Windows. Once I deleted it and created a .sh file in Linux, it ran.
Try
sudo service mongodb start
mongod/mongodb depends on Linux version

elasticsearch can't start with an non-root user

I am using elasticsearch as a search engine for my website.After I downloaded the elasticsearch I use the command ./bin/elasticsearch
I got an error
org.elasticsearch.bootstrap.StartupException:
java.lang.RuntimeException: can not run elasticsearch as root
I google it and run the command
groupadd esgroup
useradd esuser -g esgroup -p espassword
chown -R esuser:esgroup elasticsearch
and I switch to esuser but I cant cd /root
bash: cd: /root: Permission denied
so I have to switch to root user and stay at /root/elasticsearch/ and change to esuser
then I run the command
./bin/elasticsearch
this time I get a different error
Error: Could not find or load main classorg.elasticsearch.bootstrap.Elasticsearch
I already install java-1.8.0-openjdk-devel and the java -version javac command works
I am using centos6 x64
Is there something I miss?
please download & install the whole elasticsearch zip as a non-root user instead of trying to fiddle with permissions inside of the /root/ directory (where also data & logs are written to).
if you dont want to deal with such things, the easiest way might be to use one of the existing packages.

connect failed mongo db on mac osx

i'm trying to learn mongo db on my mac. I installed mondgo db using homebrew and it appeard successful. I created the dir /data/db. when I type mongo into the terminal I get:
Error: couldn't connect to server [a bunch of numbers] at src/mongo/shell/mongo.js:145 exception:connect failed
I looked at the following answer on SO: Installing and Running MongoDB on OSX
in the check answer it says:
1) Start a terminal for your mongo server
2)Go to mongo/bin directory
What does it mean to start a terminal for your server? does that mean just open up a new terminal window?
Where can I find the mongo/bin directory?
Any other suggestions on getting mondoDB up and running would be appreciated.
you should read the documentation here: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
And follow the instructions.
In this case the [bunch of numbers] are the hostname/ip and port number that the binary mongo has tried to connect to. What it's telling you is that there is no mongod binary listening on the hostname and port that mongo is trying to connect to.
You will need to start mongod before you are able to connect to it with a mongo shell. The documentation above outlines this further.
If you use homebrew the mongodb binaries will automatically be put on your path which means you won't need to cd into another directory like mongo/bin.
Good luck.
Probably you run the mongodb first time. Based on the documentation you must follow a few steps and then you are ready to go.
First, create main db directory:
sudo mkdir -p /data/db
Make sure that you have a read and write permission on that directory:
sudo chown `id -u` /data/db
And to listen to default port, run:
mongod
Finally keep in mind that after the run "mongod" command do not close console tab. Open a new tab (Cmd + T) and run other commands on the new window. To close the mongod session simply hit the Ctrl + C on the previous tab.
when everything mentioned above did not work. I did the following thing (in Mac)
cd ~
mkdir -p data/db
After creating directory in home(which will be definitely allowed) most imp command is below
mongod --dbpath ~/data/db &
So that it could take the path of db which was in home directory (as we are not able to create in / dir.
To avoid it running frequently, put the above command in .bash_profile file in home directory so that it will automatically run the above command whenever we try to use terminal in Mac
Note: Whenever we open the terminal it will execute the above command so that we can access the mongodb (I understand this should be taken place in background but it works fine)
We need to press enter/return key to get the regular command line terminal and continue doing our work
These steps worked for me well on Mac, you can give a shot, make sure you install brew first and put these lines in terminal line by line:
brew update
brew install mongodb
brew install mongodb --with-openssl
brew install mongodb --devel
sudo mkdir -p /data/db
sudo chown -R [your username] /data/db
(Replace with your username with what you can get by typing whoami in the terminal)
mongod
Run you app, for example localhost:8000

Resources