Installing Hadoop 2.4 on Ubuntu 14.04
Hey all,
Another of my ‘getting my new operating system set up with all the bits of kit I use’ – this time we’ll be on Hadoop (and HDFS). There’s a very strong chance that this post will end up a lot like Sean’s post – Hadoop from spare-change. If there are any differences it’ll be for these reasons three:
1.) He was using Ubuntu Server 13.04 not Ubuntu Desktop 14.04
2.) He was using Hadoop 2.2 not Hadoop 2.4
3.) He was setting up a whole bunch of nodes – I’m stuck with this oft-abused laptop
Anywho – on with the show.
Step 1:
Download Hadoop from Apache: I’ll be using this mirror but I trust that if you’re not in England, you can likely find a more suitable one:
http://mirror.ox.ac.uk/sites/rsync.apache.org/hadoop/common/hadoop-2.4.0/hadoop-2.4.0.tar.gz
If you’re trying to stick to the terminal/don’t have a GUI then go with this:
wget http://mirror.ox.ac.uk/sites/rsync.apache.org/hadoop/common/hadoop-2.4.0/hadoop-2.4.0.tar.gz
Find your way to wherever you downloaded the tar.gz file and untar it using the following command:
tar -xzf hadoop-2.4.0.tar.gz
Sorry if I’m teaching you to suck eggs – everybody has to start somewhere right?
Has it worked up till here?
Run the following command in the same directory you ran the above tar command:
ls | grep hadoop | grep -v *.gz
If there’s at least one line returned (ideally hadoop-2.4.0) then you’re good up till here.
Step 2:
Let’s move everything into a more appropriate directory:
sudo mv hadoop-2.4.0/ /usr/local
cd /usr/local
sudo ln -s hadoop-2.4.0/ hadoop
We create that link to allow us to write scripts/programs that interact with Hadoop that won’t need changing if we upgrade our Hadoop version. All we’ll do is install the new version and point the Hadoop folder to the new version instead. Ace.
Has it worked up to here?
Run this command anywhere:
whereis hadoop
If the output is:
hadoop: /usr/local/hadoop
you may proceed.
Step 3:
Righty, now we’ll be setting up a new user and permissions and all that guff. I’ll steal directly from Michael Noll’s tutorial here and go with:
sudo addgroup hadoop
sudo adduser --ingroup hadoop hduser
sudo adduser hduser sudo
sudo chown -R hduser:hadoop /usr/local/hadoop/
Has it worked up to here?
Type:
ls -l /home/ | grep hadoop
If you see a line then you’re in the money.
Step 4:
SSH is a biggy – possibly not so much for the single node tutorial but when we were setting up our first cluster, SSH problems probably accounted for about 90% of all head-scratching with the remaining 10% being nits.
su - hduser
sudo apt-get install ssh
ssh-keygen -t rsa -P ""
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
So we switch to our newly created user, generate an SSH key and get it added to our authorized keys. Unfortunately, Hadoop and ipv6 don’t play nice so we’ll have to disable it – to do this you’ll need to open up /etc/sysctl.conf
and add the following lines to the end:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
Fair warning – you’ll need sudo privileges to modify the file so might want to open up your file editor like this:
sudo apt-get install gksu
gksu gedit /etc/sysctl.conf
If you’re set on using terminal then this’ll do it:
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
Rumour has it that at this point you can run
sudo service networking restart
and kapeesh – ipv6 is gone. However, Atheros and Ubuntu seem to have a strange sort of ‘not working’ thing going on and so that command doesn’t work with my wireless driver. If the restart fails, just restart the computer and you should be good.
(if you’re terminal only : sudo shutdown -r now
)
Has it worked up to here?
If you’re stout of heart, attempt the following:
su - hduser
ssh localhost
If that’s worked you be greeted with a message along the lines of ‘Are you sure you want to continue connecting?’ The answer you’re looking for at this point is ‘yes’.
If it hasn’t worked at this point run the following command:
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
If the value returned is 0 then you’ve still not got ipv6 disabled – have a re-read of that section and see if you’ve missed anything.
Step 5:
I’m going to assume a clean install of Ubuntu on your machine (because that’s what I’ve got) – if this isn’t the case, it’s entirely likely you’ll already have Java installed. If so, find your JAVA_HOME (lots of tutorials on this online) and use that for the upcoming instructions. I’m going to be installing Java from scratch:
sudo apt-get update
sudo apt-get install default-jdk
Given a bit of luck, you’ll now have Java on your computer (I do on mine) and you’ll be able to set your environment variables. Open up your bashrc file:
su - hduser
gksu gedit .bashrc
and add the following lines:
export HADOOP_HOME=/usr/local/hadoop
export JAVA_HOME=/usr
and follow up with this command:
source ~/.bashrc
If you’ve deviated from any of the instructions above, those lines are likely to be different. You can find what your java home should be by running the following command:
which java | sed -e 's/\(.*\)\/bin\/java/\1/g'
Your Hadoop home will be wherever you put it in step 2.
Has it worked up to here?
So many different ways to test – let’s run our first Hadoop command:
/usr/local/hadoop/bin/hadoop version
If that worked with no error (and gave you your Hadoop version) then you’re laughing.
Step 6:
Configuration of Hadoop (and associated bits and bobs) – we’re going to be editing a bunch of files so pick your favourite file editor and get to work. First things first though, you’re going to want some place for HDFS to save your files. If you’ve going to be storing anything big/bought external storage for this purpose now is the time to deviate from this tutorial. Otherwise, this should do it:
su - hduser
mkdir /usr/local/hadoop/data
Now for the file editing:
(only necessary when running a multi-node cluster, but let’s do it in case we ever get more nodes to add)
1.) /usr/local/hadoop/etc/hadoop/hadoop-env.sh
Change export JAVA_HOME=${JAVA_HOME} to match the JAVA_HOME you set in your bashrc (for us JAVA_HOME=/usr
).
Also, change this line:
export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true
to be
export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true -Djava.library.path=$HADOOP_PREFIX/lib"
And finally, add the following line:
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_PREFIX}/lib/native
2.) /usr/local/hadoop/etc/hadoop/yarn-env.sh
Add the following lines:
export HADOOP_CONF_LIB_NATIVE_DIR=${HADOOP_PREFIX:-"/lib/native"}
export HADOOP_OPTS="-Djava.library.path=$HADOOP_PREFIX/lib"
3.) /usr/local/hadoop/etc/hadoop/core-site.xml
Change the whole file so it looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
|
<? xml version = "1.0" encoding = "UTF-8" ?> <? xml-stylesheet type = "text/xsl" href = "configuration.xsl" ?> < configuration > < property > < name >fs.default.name</ name > </ property > < property > < name >hadoop.tmp.dir</ name > < value >/usr/local/hadoop/data</ value > </ property > </ configuration > |
4.) /usr/local/hadoop/etc/hadoop/mapred-site.xml
Change the whole file so it looks like this:
1
2
3
4
5
6
7
8
9
|
<? xml version = "1.0" ?> <? xml-stylesheet type = "text/xsl" href = "configuration.xsl" ?> < configuration > < property > < name >mapreduce.framework.name</ name > < value >yarn</ value > </ property > </ configuration > |
5.) /usr/local/hadoop/etc/hadoop/hdfs-site.xml
Change the whole file so it looks like this:
1
2
3
4
5
6
7
8
9
|
<? xml version = "1.0" encoding = "UTF-8" ?> <? xml-stylesheet type = "text/xsl" href = "configuration.xsl" ?> < configuration > < property > < name >dfs.replication</ name > < value >3</ value > </ property > </ configuration > |
6.) /usr/local/hadoop/etc/hadoop/yarn-site.xml
Change the whole file so it looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<? xml version = "1.0" ?> < configuration > < property > < name >yarn.nodemanager.aux-services</ name > < value >mapreduce_shuffle</ value > </ property > < property > < name >yarn.nodemanager.aux-services.mapreduce_shuffle.class</ name > < value >org.apache.hadoop.mapred.ShuffleHandler</ value > </ property > < property > < name >yarn.resourcemanager.resource-tracker.address</ name > < value >localhost:8025</ value > </ property > < property > < name >yarn.resourcemanager.scheduler.address</ name > < value >localhost:8030</ value > </ property > < property > < name >yarn.resourcemanager.address</ name > < value >localhost:8050</ value > </ property > </ configuration > |
Annnd we’re done :) Sorry about that – if I could guarantee that you’d be using the same file paths and OS as me then I’d let you wget those files from a Github somewhere but alas, I think that’s likely to cause more headaches than it solves. Don’t worry, we’re nearly there now :)
Has it worked up to here?
Run the following command:
/usr/local/hadoop/bin/hadoop namenode -format
If that works, you’re 20% of the way there.
Then, run:
/usr/local/hadoop/sbin/start-dfs.sh
If that seems to work without throwing up a bunch of errors:
/usr/local/hadoop/sbin/start-yarn.sh
If that’s worked, you can safely say you’ve got Hadoop running on your computer :)Get it on the LinkedIn as a strength as soon as possible ;)
Conclusion
Now you’ve got Hadoop up and running on your computer, what can you do? Well, unfortunately with that single node and single hard disk, not much you couldn’t have done without it. However, if you’re just getting started with Linux and Hadoop you’ll have hopefully learnt a bit on the way to setting up your cluster.