ArticleDirectory
- Option 1: from Unix Command Line
- Option 2: Get it from Apple website
- Setting up your environment
- Processing ing hadoop for OS X (and fixing some bugs)
Chances are good if you are a just starting out software engineer knowing mapreduce inside and out is as important now as knowing how to configure a LAMP stack was in the last decade. therefore most developers will want to have a local instance to learn and experiment without having to go down the route of virtualization.
Although there are a lot of competing mapreduce implementations out there, Apache hadoop is the leader, with most PAAs vendors such as Amazon and Microsoft supporting it.
Setting up Apache hadoop on Mac OS X follows the similar pattern to the official hadoop Single Node documentation on the Apache side,But there are some bugs and custom configuration for OS X lion that cocould trip you up, So this post shocould help you get started. here is a quick tutorial (with some gotcha configuration changes you need to make until some bugs are fixed by Apache) to get you started. if you have any updates or suggestions please drop me a line and I'll update.
Getting Java
Mac OS X no longer provides Java out of the box, but forcing it is fairly easy.
Option 1: from Unix Command Line
Just check your Java version on a command line, which will prompt OS X to ask if you 'd like to install Java.
$ Java-version
Option 2: Get it from Apple website
You can also download it directly from Apple by visiting here: http://support.apple.com/kb/dl1421
Getting hadoopsetting up your environment
Some people like putting hadoop under ~ /Library/hadoop. that's fine, but I am use to the/usr/local/of * nix world so I'll use that for $ hadoop_home. you can make changes as appropriate.
Edit your. bash_profile and insert the following:
Export hadoop_home =/usr/local/hadoop export java_home = $ (/usr/libexec/java_home) Export Path = $ path: $ hadoop_home/bin
Note that I have specifiedJava_homeTo point to a command which will dynamically find the correct Java in your OS X environment. this can be done both in your bash_profile and in hadoop-env.sh in your configuration. I recommend this to make sure any changes Apple (or perhaps Oracle once Apple gets out of the business of providing Java all together) makes in various updates does not break your Java configuration.
Download hadoop from Command Line
$ CD/usr/local/$ mkdir hadoop $ wget http://archive.cloudera.com/cdh/3/hadoop-0.20.2-cdh3u1.tar.gz $ tar xzvf hadoop-0.20.2-cdh3u1.tar.gz $ MV hadoop-0.20.2-cdh3u1./hadoop
Processing ing hadoop for OS X (and fixing some bugs)
Once installed, there will be three configuration files you'll want to edit. Learning what these files do in general is left up to the reader, but this will get you up to speed quick.
We will set up the following single node configuration:
- Sets the default file system as an HDFS instance
- Sets the path on the local filesystem that the hadoop daemons will use for persistence to something accessible by you
- Sets HDFS configuration so that HDFS will only try to store one copy of each file
- Sets map reduce properties to define the number of MAP and reduce slots that will be available on your box (you can play with these depending on your system resources)
Processing: hadoop-env.sh
In your command window, load the environment configuration file. you won't want to change much here, but some things will help you ensure you run right the first time and every time. I recommend making these changes.
VI/usr/local/hadoop/config/hadoop-env.sh
Uncomment # java_home and specify the command path to dynamically load your Java location as discussed above:
# The JAVA Implementation to use. required. Export java_home =$ (/usr/libexec/java_home)
Next, uncomment hadoop_heapsize and make it 2000. This is optional but recommended .:
# The maximum amount of heap to use, in MB. Default is 1000. Export hadoop_heapsize = 2000
Important: Fix configuration files to get around lion specific problems
OS X lion introduced a bug that affects people experience when first initializing their Name node storage. It typically appears as this error:
"Unable to load realm info from scdynamicstore"
This error is currently being tracked in Apache HADOOP-7489 bug. Readers may want to check if this is fixed before applying the below fix.
To fix this issue, simply add the following to your hadoop-env.sh file:
Export hadoop_opts = "-djava. Security. krb5.realm = ox. ac. uk-djava. Security. krb5.kdc = kdc0.ox. ac. uk: kdc1.ox. ac. uk"
To sum up, your hadoop-env.sh shocould have the following defined:
Export hadoop_opts = "-djava. security. krb5.realm = ox. AC. UK-djava. security. krb5.kdc = kdc0.ox. AC. UK: kdc1.ox. AC. UK "Export java_home = $ (/usr/libexec/java_home) Export hadoop_heapsize = 2000
With that file ready to go, let's move on to running ing your HDFS and map reduce XML files.
Processing: core-site.xml
A change from previous versions of Apache hadoop is that instead of putting all the configuration for your hadoop instance in to one XML file (hadoop-site.xml), you now have three configuration files you need to edit. this separation of concern is a good depression, but causes some extra work for us. first up is the core-site.xml file.
As stated, you need to pick a good place to run the local instance of your single node HDFS storage and setup the location for running the master HDFS instance. I also chose to dynamically inject the username in the temp directory in order to keep track of what account is writing to the HDFS store. this is good practice if you plan on running a local service account (or a few) to test different scenarios. it's not necessary though.Keep in mind that whatever tmp directory you point to, whatever service account you are using (or your own account) will need write access to the directory.
Your file shocould look something like this:
<Configuration> <property> <Name> hadoop. TMP. dir </Name> <value>/usr/local/tmp/hadoop-$ {user. name} </value> <description> a base for other temporary directories. </description> </property> <Name> FS. default. name </Name> <value> HDFS: // localhost: 8020 </value> </property> </configuration>
Processing: hdfs-site.xml
Now that we 've accomplished that, we need to setup some configuration for HDFS itself. the hdfs-site.xml is used to configure HDFS itself. since we are running a single node cluster on our Mac, we will want to specify for HDFS to only store one copy of the file:
<Configuration> <property> <Name> DFS. Replication </Name> <value> 1 </value> </property> </configuration>
Processing: mapred-site.xml
Next we need to do some custom configuration on the map reduce engine itself. we specify the job tracker location (usually just your HDFS port + 1, but you can use any open port) and also set the maximum map and reduce jobs that can be spawned. you can configure these depending on the size/speed of your system. I specified 2 here.
<Configuration> <property> <Name> mapred. job. tracker </Name> <value> localhost: 8021 </value> </property> <Name> mapred. tasktracker. map. tasks. maximum </Name> <value> 2 </value> </property> <Name> mapred. tasktracker. reduce. tasks. maximum </Name> <value> 2 </value> </property> </configuration>
Setup HDFS for the first time
We are almost done here, but one final step is to format the HDFS instance we 've specified. since we 've ve already squashed the nasty scdynamicstore bug in your hadoop-env.sh file, this shoshould work without issue. this is also a great way to test if the account you are running hadoop as actually has access to all the required directories.
$ Hadoop_home/bin/hadoop namenode-format
You shoshould see output like the following:
Brandons-MacBook-air: Local bbjwerner $ & nbsp; hadoop namenode-format warning: $ hadoop_home is deprecated. 11/10/23 00:30:26 info namenode. namenode: startup_msg: Re-format filesystem in/usr/local/tmp/hadoop-bbjwerner/dfs/name? (Y or N) Y <strong> & lt; -- Note: You have to use a capital "Y" here. dumb script. </strong> 11/10/23 00:30:28 info util. gset: VM type & nbsp; = 64-bit11/10/23 00:30:28 info util. gset: 2% max memory = 39.83375 mb11/10/23 00:30:28 info util. gset: capacity & nbsp; = 2 ^ 22 = 4194304 entries 11/10/23 00:30:28 info util. gset: Recommended = 4194304, actual = 4194304 11/10/23 00:30:28 info namenode. fsnamesystem: fsowner = bbjwerner 11/10/23 00:30:28 info namenode. fsnamesystem: supergroup = supergroup 11/10/23 00:30:28 info namenode. fsnamesystem: ispermissionenabled = true 11/10/23 00:30:28 info namenode. fsnamesystem: DFS. block. invalidate. limit = 100 11/10/23 00:30:28 info namenode. fsnamesystem: isaccesstokenenenabled = false accesskeyupdateinterval = 0 min (s), accesstokenlifetime = 0 min (s) 11/10/23 00:30:28 info namenode. namenode: caching file names occuring more than 10 times 11/10/23 00:30:29 info common. storage: Image File of size 115 saved in 0 seconds. <strong> 11/10/23 00:30:29 info common. storage: storage directory/usr/local/tmp/hadoop-bbjwerner/dfs/name has been successfully formatted. </strong> 11/10/23 00:30:29 info namenode. namenode: shutdown_msg: /*************************************** * ******************** shutdown_msg: shutting down the namenode at Brandons-MacBook-Air.local/10.0.1.31
With this complete, your setup of hadoop is ready! Now all we have to do is run a simple test to make sure it all works!
Startup hadoop with the specified ded scripts
You use to have to start each part of hadoop individually (datanode, namenode, jobtracker, tasktracker) but now they include a script that will start all the services at once.
$ Hadoop_home/bin/ start-all.sh
You will see each Service Startup. If there are no errors, you are ready to move on to testing out your hadoop instance!
Run hadoop with the specified ded examples jar files in the hadoop Distribution
To test out your single node, run a quick command from your command line to test it out. To see the available tests for hadoop, run the following command:
$ Hadoop jar $ hadoop_home/hadoop-examples-*. Jar
You will see a bunch of different cool tests. The easiest is pi. You can run it in this way:
$ Hadoop jar $ hadoop_home/hadoop-examples-*. Jar PI 10 100
You shoshould see output like the following:
Number of maps & nbsp; = 10 samples per map = 100 wrote input for map #0 wrote input for map #1 wrote input for map #2
Congratulations!
You now have a single node hadoop on OS X lion. Happy hacking!
Hardoop, OSX, Apple Who am I?
I am Brandon Werner. I love good friends, good coffee, and good ideas shared around a room. I work for Microsoft helping build the next identity platform in the cloud for azure.
Comments
- Hiroshi@gmail.com
22 Dec 2011 thank you for the great instruction! A couple of comments for your attention;
1) $ MV hadoop-0.20.2-cdh3u1. /hadoop: three steps before in your instruction, you have already created hadoop directory, this command will move hadoop-0.20.2-cdh3u1/under. /hadoop.
2) during formatting namenode and start-all.sh, I hit handle of permission error like, localhost: mkdir:/usr/local/hadoop/bin /.. /logs: Permission denied
How d O you set your account on MAC (Lion )? I used "sudo" with root password during the installation. /usr/local are is protected on my Mac.
thank you again for your help.
-Hiroshi
- Brandon Werner
27 dec 2011 it may be best just to sudo Su and run the entire process root to ensure anything spawned during the installation also has permission to the directory. lion has done a lot of confusing things to permissions in the Unix directory to "Protect" users, so your best bet is to take ownership of the entire/usr/local/directory recursively and then set 775 on them.
there is no reason in my mind why/usr/local/shouldn't be under ownership of the user in a single user machine.
- Will l
30 dec 2011 AMHello, have you been able to get hadoop eclipse plugin to work on OS X lion? For some reason in eclipse 3.7.1 with hadoop 0.20.205.0, the eclipse plugin cannot connect to the DFS and gives an error of "failed to login ". what I don't understand is why in hadoop is starting to deprecate the hadoop eclipse plugin. I tried building hadoop 1.0.0's eclipse plugin from the source directory but it doesn't seem to generate any jar files.
Thank you again for your help!
-
- Ryan
9 Jan 2012 pmHi Will, it looks like the plugin is missing some jar files and I think the manifest may be off too.