In this chapter, we'll install a single-node Hadoop cluster backed by the Hadoop Distributed File System on Ubuntu.
Hadoop framework is written in Java!!
k@laptop:~$ cd ~# Update the source listk@laptop:~$ sudo apt-get update# The OpenJDK project is the default version of Java # that is provided from a supported Ubuntu repository.k@laptop:~$ sudo apt-get install default-jdkk@laptop:~$ java -versionjava version "1.7.0_65"OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1)OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
k@laptop:~$ sudo addgroup hadoopAdding group `hadoop' (GID 1002) ...Done.k@laptop:~$ sudo adduser --ingroup hadoop hduserAdding user `hduser' ...Adding new user `hduser' (1001) with group `hadoop' ...Creating home directory `/home/hduser' ...Copying files from `/etc/skel' ...Enter new UNIX password: Retype new UNIX password: passwd: password updated successfullyChanging the user information for hduserEnter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] Y
ssh has two main components:
- ssh : The command we use to connect to remote machines - the client.
- sshd : The daemon that is running on the server and allows clients to connect to the server.
The ssh is pre-enabled on Linux, but in order to start sshd daemon, we need to install sshfirst. Use this command to do that :
k@laptop:~$ sudo apt-get install ssh
This will install ssh on our machine. If we get something similar to the following, we can think it is setup properly:
k@laptop:~$ which ssh/usr/bin/sshk@laptop:~$ which sshd/usr/sbin/sshd
Hadoop requires SSH access to manage its nodes, i.e. remote machines plus our local machine. For our single-node setup of Hadoop, we therefore need to configure SSH access to localhost.
So, we need to have SSH up and running on our machine and configured it to allow SSH public key authentication.
Hadoop uses SSH (to access its nodes) which would normally require the user to enter a password. However, this requirement can be eliminated by creating and setting up SSH certificates using the following commands. If asked for a filename just leave it blank and press the enter key to continue.
k@laptop:~$ su hduserPassword: hduser@laptop:~$ ssh-keygen -t rsa -P ""Generating public/private rsa key pair.Enter file in which to save the key (/home/hduser/.ssh/id_rsa): Created directory '/home/hduser/.ssh'.Your identification has been saved in /home/hduser/.ssh/id_rsa.Your public key has been saved in /home/hduser/.ssh/id_rsa.pub.The key fingerprint is:50:6b:f3:fc:0f:32:bf:30:79:c2:41:71:26:cc:7d:e3 hduser@laptopThe key's randomart image is:+--[ RSA 2048]----+| .oo.o || . .o=. o || . + . o . || o = E || S + || . + || O + || O o || o.. |+-----------------+hduser@laptop:/home/k$ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
The second command adds the newly created key to the list of authorized keys so that Hadoop can use ssh without prompting for a password.
We can check if ssh works:
hduser@laptop:/home/k$ ssh localhostThe authenticity of host 'localhost (127.0.0.1)' can't be established.ECDSA key fingerprint is e1:8b:a0:a5:75:ef:f4:b4:5e:a9:ed:be:64:be:5c:2f.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'localhost' (ECDSA) to the list of known hosts.Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-40-generic x86_64)...
hduser@laptop:~$ wget http://mirrors.sonic.net/apache/hadoop/common/hadoop-2.6.0/hadoop-2.6.0.tar.gzhduser@laptop:~$ tar xvzf hadoop-2.6.0.tar.gz
We want to move the Hadoop installation to the /usr/local/hadoop directory using the following command:
hduser@laptop:~/hadoop-2.6.0$ sudo mv * /usr/local/hadoop[sudo] password for hduser: hduser is not in the sudoers file. This incident will be reported.
Oops!... We got:
"hduser is not in the sudoers file. This incident will be reported."
This error can be resolved by logging in as a root user, and then add hduser to sudo:
hduser@laptop:~/hadoop-2.6.0$ su kPassword: k@laptop:/home/hduser$ sudo adduser hduser sudo[sudo] password for k: Adding user `hduser' to group `sudo' ...Adding user hduser to group sudoDone.
Now, the hduser has root priviledge, we can move the Hadoop installation to the /usr/local/hadoop directory without any problem:
k@laptop:/home/hduser$ sudo su hduserhduser@laptop:~/hadoop-2.6.0$ sudo mv * /usr/local/hadoop hduser@laptop:~/hadoop-2.6.0$ sudo chown -R hduser:hadoop /usr/local/hadoop
The following files will have to be modified to complete the Hadoop setup:
- ~/.bashrc
- /usr/local/hadoop/etc/hadoop/hadoop-env.sh
- /usr/local/hadoop/etc/hadoop/core-site.xml
- /usr/local/hadoop/etc/hadoop/mapred-site.xml.template
- /usr/local/hadoop/etc/hadoop/hdfs-site.xml
1. ~/.bashrc:
Before editing the .bashrc file in our home directory, we need to find the path where Java has been installed to set the JAVA_HOME environment variable using the following command:
hduser@laptop update-alternatives --config javaThere is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaNothing to configure.
Now we can append the following to the end of ~/.bashrc:
hduser@laptop:~$ vi ~/.bashrc#HADOOP VARIABLES STARTexport JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64export HADOOP_INSTALL=/usr/local/hadoopexport PATH=$PATH:$HADOOP_INSTALL/binexport PATH=$PATH:$HADOOP_INSTALL/sbinexport HADOOP_MAPRED_HOME=$HADOOP_INSTALLexport HADOOP_COMMON_HOME=$HADOOP_INSTALLexport HADOOP_HDFS_HOME=$HADOOP_INSTALLexport YARN_HOME=$HADOOP_INSTALLexport HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/nativeexport HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"#HADOOP VARIABLES ENDhduser@laptop:~$ source ~/.bashrc
note that the JAVA_HOME should be set as the path just before the '.../bin/':
hduser@ubuntu-VirtualBox:~$ javac -versionjavac 1.7.0_75hduser@ubuntu-VirtualBox:~$ which javac/usr/bin/javachduser@ubuntu-VirtualBox:~$ readlink -f /usr/bin/javac/usr/lib/jvm/java-7-openjdk-amd64/bin/javac
2. /usr/local/hadoop/etc/hadoop/hadoop-env.sh
We need to set JAVA_HOME by modifying hadoop-env.sh file.
hduser@laptop:~$ vi /usr/local/hadoop/etc/hadoop/hadoop-env.shexport JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Adding the above statement in the hadoop-env.sh file ensures that the value of JAVA_HOME variable will be available to Hadoop whenever it is started up.
3. /usr/local/hadoop/etc/hadoop/core-site.xml:
The /usr/local/hadoop/etc/hadoop/core-site.xml file contains configuration properties that Hadoop uses when starting up.
This file can be used to override the default settings that Hadoop starts with.hduser@laptop:~$ sudo mkdir -p /app/hadoop/tmphduser@laptop:~$ sudo chown hduser:hadoop /app/hadoop/tmp
Open the file and enter the following in between the <configuration></configuration> tag:
hduser@laptop:~$ vi /usr/local/hadoop/etc/hadoop/core-site.xmlhadoop.tmp.dir /app/hadoop/tmp A base for other temporary directories. fs.default.name hdfs://localhost:54310 The name of the default file system. A URI whose scheme and authority determine the FileSystem implementation. The uri's scheme determines the config property (fs.SCHEME.impl) naming the FileSystem implementation class. The uri's authority is used to determine the host, port, etc. for a filesystem.
4. /usr/local/hadoop/etc/hadoop/mapred-site.xml
By default, the /usr/local/hadoop/etc/hadoop/ folder contains
/usr/local/hadoop/etc/hadoop/mapred-site.xml.template file which has to be renamed/copied with the name mapred-site.xml:hduser@laptop:~$ cp /usr/local/hadoop/etc/hadoop/mapred-site.xml.template /usr/local/hadoop/etc/hadoop/mapred-site.xml
The mapred-site.xml file is used to specify which framework is being used for MapReduce.
We need to enter the following content in between the <configuration></configuration> tag:mapred.job.tracker localhost:54311 The host and port that the MapReduce job tracker runs at. If "local", then jobs are run in-process as a single map and reduce task.
5. /usr/local/hadoop/etc/hadoop/hdfs-site.xml
The /usr/local/hadoop/etc/hadoop/hdfs-site.xml file needs to be configured for each host in the cluster that is being used.
It is used to specify the directories which will be used as the namenode and the datanode on that host.Before editing this file, we need to create two directories which will contain the namenode and the datanode for this Hadoop installation.
This can be done using the following commands:hduser@laptop:~$ sudo mkdir -p /usr/local/hadoop_store/hdfs/namenodehduser@laptop:~$ sudo mkdir -p /usr/local/hadoop_store/hdfs/datanodehduser@laptop:~$ sudo chown -R hduser:hadoop /usr/local/hadoop_store
Open the file and enter the following content in between the <configuration></configuration> tag:
hduser@laptop:~$ vi /usr/local/hadoop/etc/hadoop/hdfs-site.xmldfs.replication 1 Default block replication. The actual number of replications can be specified when the file is created. The default is used if replication is not specified in create time. dfs.namenode.name.dir file:/usr/local/hadoop_store/hdfs/namenode dfs.datanode.data.dir file:/usr/local/hadoop_store/hdfs/datanode
Now, the Hadoop file system needs to be formatted so that we can start to use it. The format command should be issued with write permission since it creates current directory
under /usr/local/hadoop_store/hdfs/namenode folder:hduser@laptop:~$ hadoop namenode -formatDEPRECATED: Use of this script to execute hdfs command is deprecated.Instead use the hdfs command for it.15/04/18 14:43:03 INFO namenode.NameNode: STARTUP_MSG: /************************************************************STARTUP_MSG: Starting NameNodeSTARTUP_MSG: host = laptop/192.168.1.1STARTUP_MSG: args = [-format]STARTUP_MSG: version = 2.6.0STARTUP_MSG: classpath = /usr/local/hadoop/etc/hadoop...STARTUP_MSG: java = 1.7.0_65************************************************************/15/04/18 14:43:03 INFO namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT]15/04/18 14:43:03 INFO namenode.NameNode: createNameNode [-format]15/04/18 14:43:07 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicableFormatting using clusterid: CID-e2f515ac-33da-45bc-8466-5b1100a2bf7f15/04/18 14:43:09 INFO namenode.FSNamesystem: No KeyProvider found.15/04/18 14:43:09 INFO namenode.FSNamesystem: fsLock is fair:true15/04/18 14:43:10 INFO blockmanagement.DatanodeManager: dfs.block.invalidate.limit=100015/04/18 14:43:10 INFO blockmanagement.DatanodeManager: dfs.namenode.datanode.registration.ip-hostname-check=true15/04/18 14:43:10 INFO blockmanagement.BlockManager: dfs.namenode.startup.delay.block.deletion.sec is set to 000:00:00:00.00015/04/18 14:43:10 INFO blockmanagement.BlockManager: The block deletion will start around 2015 Apr 18 14:43:1015/04/18 14:43:10 INFO util.GSet: Computing capacity for map BlocksMap15/04/18 14:43:10 INFO util.GSet: VM type = 64-bit15/04/18 14:43:10 INFO util.GSet: 2.0% max memory 889 MB = 17.8 MB15/04/18 14:43:10 INFO util.GSet: capacity = 2^21 = 2097152 entries15/04/18 14:43:10 INFO blockmanagement.BlockManager: dfs.block.access.token.enable=false15/04/18 14:43:10 INFO blockmanagement.BlockManager: defaultReplication = 115/04/18 14:43:10 INFO blockmanagement.BlockManager: maxReplication = 51215/04/18 14:43:10 INFO blockmanagement.BlockManager: minReplication = 115/04/18 14:43:10 INFO blockmanagement.BlockManager: maxReplicationStreams = 215/04/18 14:43:10 INFO blockmanagement.BlockManager: shouldCheckForEnoughRacks = false15/04/18 14:43:10 INFO blockmanagement.BlockManager: replicationRecheckInterval = 300015/04/18 14:43:10 INFO blockmanagement.BlockManager: encryptDataTransfer = false15/04/18 14:43:10 INFO blockmanagement.BlockManager: maxNumBlocksToLog = 100015/04/18 14:43:10 INFO namenode.FSNamesystem: fsOwner = hduser (auth:SIMPLE)15/04/18 14:43:10 INFO namenode.FSNamesystem: supergroup = supergroup15/04/18 14:43:10 INFO namenode.FSNamesystem: isPermissionEnabled = true15/04/18 14:43:10 INFO namenode.FSNamesystem: HA Enabled: false15/04/18 14:43:10 INFO namenode.FSNamesystem: Append Enabled: true15/04/18 14:43:11 INFO util.GSet: Computing capacity for map INodeMap15/04/18 14:43:11 INFO util.GSet: VM type = 64-bit15/04/18 14:43:11 INFO util.GSet: 1.0% max memory 889 MB = 8.9 MB15/04/18 14:43:11 INFO util.GSet: capacity = 2^20 = 1048576 entries15/04/18 14:43:11 INFO namenode.NameNode: Caching file names occuring more than 10 times15/04/18 14:43:11 INFO util.GSet: Computing capacity for map cachedBlocks15/04/18 14:43:11 INFO util.GSet: VM type = 64-bit15/04/18 14:43:11 INFO util.GSet: 0.25% max memory 889 MB = 2.2 MB15/04/18 14:43:11 INFO util.GSet: capacity = 2^18 = 262144 entries15/04/18 14:43:11 INFO namenode.FSNamesystem: dfs.namenode.safemode.threshold-pct = 0.999000012874603315/04/18 14:43:11 INFO namenode.FSNamesystem: dfs.namenode.safemode.min.datanodes = 015/04/18 14:43:11 INFO namenode.FSNamesystem: dfs.namenode.safemode.extension = 3000015/04/18 14:43:11 INFO namenode.FSNamesystem: Retry cache on namenode is enabled15/04/18 14:43:11 INFO namenode.FSNamesystem: Retry cache will use 0.03 of total heap and retry cache entry expiry time is 600000 millis15/04/18 14:43:11 INFO util.GSet: Computing capacity for map NameNodeRetryCache15/04/18 14:43:11 INFO util.GSet: VM type = 64-bit15/04/18 14:43:11 INFO util.GSet: 0.029999999329447746% max memory 889 MB = 273.1 KB15/04/18 14:43:11 INFO util.GSet: capacity = 2^15 = 32768 entries15/04/18 14:43:11 INFO namenode.NNConf: ACLs enabled? false15/04/18 14:43:11 INFO namenode.NNConf: XAttrs enabled? true15/04/18 14:43:11 INFO namenode.NNConf: Maximum size of an xattr: 1638415/04/18 14:43:12 INFO namenode.FSImage: Allocated new BlockPoolId: BP-130729900-192.168.1.1-142939339159515/04/18 14:43:12 INFO common.Storage: Storage directory /usr/local/hadoop_store/hdfs/namenode has been successfully formatted.15/04/18 14:43:12 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 015/04/18 14:43:12 INFO util.ExitUtil: Exiting with status 015/04/18 14:43:12 INFO namenode.NameNode: SHUTDOWN_MSG: /************************************************************SHUTDOWN_MSG: Shutting down NameNode at laptop/192.168.1.1************************************************************/
Note that hadoop namenode -format command should be executed once before we start using Hadoop.
If this command is executed again after Hadoop has been used, it'll destroy all the data on the Hadoop file system.
Now it's time to start the newly installed single node cluster.
We can use start-all.sh or (start-dfs.sh and start-yarn.sh)k@laptop:~$ cd /usr/local/hadoop/sbink@laptop:/usr/local/hadoop/sbin$ lsdistribute-exclude.sh start-all.cmd stop-balancer.shhadoop-daemon.sh start-all.sh stop-dfs.cmdhadoop-daemons.sh start-balancer.sh stop-dfs.shhdfs-config.cmd start-dfs.cmd stop-secure-dns.shhdfs-config.sh start-dfs.sh stop-yarn.cmdhttpfs.sh start-secure-dns.sh stop-yarn.shkms.sh start-yarn.cmd yarn-daemon.shmr-jobhistory-daemon.sh start-yarn.sh yarn-daemons.shrefresh-namenodes.sh stop-all.cmdslaves.sh stop-all.shk@laptop:/usr/local/hadoop/sbin$ sudo su hduserhduser@laptop:/usr/local/hadoop/sbin$ start-all.shhduser@laptop:~$ start-all.shThis script is Deprecated. Instead use start-dfs.sh and start-yarn.sh15/04/18 16:43:13 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicableStarting namenodes on [localhost]localhost: starting namenode, logging to /usr/local/hadoop/logs/hadoop-hduser-namenode-laptop.outlocalhost: starting datanode, logging to /usr/local/hadoop/logs/hadoop-hduser-datanode-laptop.outStarting secondary namenodes [0.0.0.0]0.0.0.0: starting secondarynamenode, logging to /usr/local/hadoop/logs/hadoop-hduser-secondarynamenode-laptop.out15/04/18 16:43:58 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicablestarting yarn daemonsstarting resourcemanager, logging to /usr/local/hadoop/logs/yarn-hduser-resourcemanager-laptop.outlocalhost: starting nodemanager, logging to /usr/local/hadoop/logs/yarn-hduser-nodemanager-laptop.out
We can check if it's really up and running:
hduser@laptop:/usr/local/hadoop/sbin$ jps9026 NodeManager7348 NameNode9766 Jps8887 ResourceManager7507 DataNode
The output means that we now have a functional instance of Hadoop running on our VPS (Virtual private server).
Another way to check is using netstat:
hduser@laptop:~$ netstat -plten | grep java(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)tcp 0 0 0.0.0.0:50020 0.0.0.0:* LISTEN 1001 1843372 10605/java tcp 0 0 127.0.0.1:54310 0.0.0.0:* LISTEN 1001 1841277 10447/java tcp 0 0 0.0.0.0:50090 0.0.0.0:* LISTEN 1001 1841130 10895/java tcp 0 0 0.0.0.0:50070 0.0.0.0:* LISTEN 1001 1840196 10447/java tcp 0 0 0.0.0.0:50010 0.0.0.0:* LISTEN 1001 1841320 10605/java tcp 0 0 0.0.0.0:50075 0.0.0.0:* LISTEN 1001 1841646 10605/java tcp6 0 0 :::8040 :::* LISTEN 1001 1845543 11383/java tcp6 0 0 :::8042 :::* LISTEN 1001 1845551 11383/java tcp6 0 0 :::8088 :::* LISTEN 1001 1842110 11252/java tcp6 0 0 :::49630 :::* LISTEN 1001 1845534 11383/java tcp6 0 0 :::8030 :::* LISTEN 1001 1842036 11252/java tcp6 0 0 :::8031 :::* LISTEN 1001 1842005 11252/java tcp6 0 0 :::8032 :::* LISTEN 1001 1842100 11252/java tcp6 0 0 :::8033 :::* LISTEN 1001 1842162 11252/java
$ pwd/usr/local/hadoop/sbin$ lsdistribute-exclude.sh httpfs.sh start-all.sh start-yarn.cmd stop-dfs.cmd yarn-daemon.shhadoop-daemon.sh mr-jobhistory-daemon.sh start-balancer.sh start-yarn.sh stop-dfs.sh yarn-daemons.shhadoop-daemons.sh refresh-namenodes.sh start-dfs.cmd stop-all.cmd stop-secure-dns.shhdfs-config.cmd slaves.sh start-dfs.sh stop-all.sh stop-yarn.cmdhdfs-config.sh start-all.cmd start-secure-dns.sh stop-balancer.sh stop-yarn.sh
We run stop-all.sh or (stop-dfs.sh and stop-yarn.sh) to stop all the daemons running on our machine:
hduser@laptop:/usr/local/hadoop/sbin$ pwd/usr/local/hadoop/sbinhduser@laptop:/usr/local/hadoop/sbin$ lsdistribute-exclude.sh httpfs.sh start-all.cmd start-secure-dns.sh stop-balancer.sh stop-yarn.shhadoop-daemon.sh kms.sh start-all.sh start-yarn.cmd stop-dfs.cmd yarn-daemon.shhadoop-daemons.sh mr-jobhistory-daemon.sh start-balancer.sh start-yarn.sh stop-dfs.sh yarn-daemons.shhdfs-config.cmd refresh-namenodes.sh start-dfs.cmd stop-all.cmd stop-secure-dns.shhdfs-config.sh slaves.sh start-dfs.sh stop-all.sh stop-yarn.cmdhduser@laptop:/usr/local/hadoop/sbin$ hduser@laptop:/usr/local/hadoop/sbin$ stop-all.shThis script is Deprecated. Instead use stop-dfs.sh and stop-yarn.sh15/04/18 15:46:31 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicableStopping namenodes on [localhost]localhost: stopping namenodelocalhost: stopping datanodeStopping secondary namenodes [0.0.0.0]0.0.0.0: no secondarynamenode to stop15/04/18 15:46:59 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicablestopping yarn daemonsstopping resourcemanagerlocalhost: stopping nodemanagerno proxyserver to stop
Let's start the Hadoop again and see its Web UI:
hduser@laptop:/usr/local/hadoop/sbin$ start-all.sh
http://localhost:50070/ - web UI of the NameNode daemon
SecondaryNameNode
(Note) I had to restart Hadoop to get this Secondary Namenode.
DataNode
原文链接