程序员人生 网站导航

Java之美[从菜鸟到高手演练]之Linux下Hadoop的完全分布式安装

栏目:服务器时间:2015-03-02 08:30:10
作者:2青

邮箱:xtfggef@gmail.com     微博:http://weibo.com/xtfggef

本来是想安装1个单节点的环境就行了,后来按装完了总觉得不够过瘾,因而今天继续研究1下,来1个完全散布式的集群安装。用到的软件和上1篇单节点安装Hadoop1样,以下:
  • Ubuntu 14.10 64 Bit Server Edition
  • Hadoop2.6.0
  • JDK 1.7.0_71
  • ssh
  • rsync

准备环境

仍然是VirtualBox + Ubuntu 14.10 64 Bit,只不过这次是3个节点,话不多说,下面开始配置准备,基础环境就不再赘述了,包括安装JDK,ssh,rsync等,可以参考上1篇。


master 192.168.1.118 nameNode
slave1 192.168.1.189 dataNode1
slave2 192.168.1.116 dataNode2

修改每一个机器的hosts文件,在/etc/hosts文件末尾添加以下配置:

192.168.1.118 master 192.168.1.189 slave1 192.168.1.116 slave2


2015年1月15日补充:

1. 修改每一个机器的hostname,在/etc/hostsname下,将master机器的hostname改成master,以此类推。

2. 赋予当前用户管理员权限。

3. 将IP地址改成静态IP,通过修改/etc/network/interfaces文件,添加以下配置:

auto eth0 iface eth0 inet static address 192.168.1.118 netmask 255.255.255.0 gateway 192.168.1.1

修改完需重启才能生效。

配置namenode对datanode的无密钥访问

直接在namenode控制台履行以下两行命令:

$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

进入namenode的用户根目录,再进入.ssh目录查看生成的文件:authorized_keys, id_dsa, id_dsa.pub



将authorized_keys文件分发到个datanode节点上:



验证:

ssh 192.168.1.189

ssh 192.168.1.116

ssh slave1

ssh slave2

如果不需要密码直接进入则OK,否则重新来配。

安装Hadoop

1. 从官网下载hadoop 2.6.0 tar.gz文件,然后解压到用户目录:tar -zxvf hadoop⑵.6.0.tar.gz.

2. 在解压后的hadoop⑵.6.0文件夹里创建tmp文件夹。

3. 配置环境变量

添加以下配置信息到/etc/profile文件末尾(每台机器都要配置)。

# set hadoop path export HADOOP_HOME=/home/adam/hadoop⑵.6.0 export PATH=$PATH:$HADOOP_HOME/bin

履行. /etc/profile或source /etc/profile使配置生效,然后履行hadoop version查看hadoop版本并且验证环境变量是不是配置成功。

4. 配置hadoop,进入目录/home/adam/hadoop⑵.6.0/etc/hadoop

a>. 编辑core-site.xml

<configuration>     <property>         <name>hadoop.tmp.dir</name>         <value>/home/adam/hadoop⑵.6.0/tmp</value>         <description>Abase for other temporary directories.</description>     </property>     <property>         <name>fs.defaultFS</name>         <value>hdfs://master:9000</value>     </property>     <property>         <name>io.file.buffer.size</name>         <value>4096</value>     </property> </configuration>

b>. 在hadoop-env.sh和yarn-env.sh里配置JAVA_HOME环境变量以下



3. 编辑hdfs-site.xml

<configuration> <property> <name>dfs.nameservices</name> <value>hadoop-cluster</value> </property> <property> <name>dfs.namenode.secondary.http-address</name> <value>master:50090</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:///home/adam/hadoop⑵.6.0/dfs/name</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:///home/adam/hadoop⑵.6.0/dfs/data</value> </property> <property> <name>dfs.replication</name> <value>1</value> </property> <property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property> </configuration>

4. 编辑mapred-site.xml

<configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> <property> <name>mapreduce.jobtracker.http.address</name> <value>master:50030</value> </property> <property> <name>mapreduce.jobhistory.address</name> <value>master:10020</value> </property> <property> <name>mapreduce.jobhistory.webapp.address</name> <value>master:19888</value> </property> </configuration>

5. 编辑yarn-site.xml

<configuration> <!-- Site specific YARN configuration properties --> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.resourcemanager.address</name> <value>master:8032</value> </property> <property> <name>yarn.resourcemanager.scheduler.address</name> <value>master:8030</value> </property> <property> <name>yarn.resourcemanager.resource-tracker.address</name> <value>master:8031</value> </property> <property> <name>yarn.resourcemanager.admin.address</name> <value>master:8033</value> </property> <property> <name>yarn.resourcemanager.webapp.address</name> <value>master:8088</value> </property> </configuration>

6. 编辑slaves文件添加以下两行:

slave1

slave2

7. 将hadoop文件夹复制到另个slave结点上


启动Hadoop

1. 格式化namenode

adam@ubuntu:~/hadoop⑵.6.0/bin$ ./hdfs namenode -format 15/01/14 19:29:58 INFO namenode.NameNode: STARTUP_MSG: /************************************************************ STARTUP_MSG: Starting NameNode STARTUP_MSG: host = ubuntu/60.191.124.254 STARTUP_MSG: args = [-format] STARTUP_MSG: version = 2.6.0 STARTUP_MSG: classpath = /home/adam/hadoop⑵.6.0/etc/hadoop:/home/adam/hadoop⑵.6.0/share/hadoop/common/lib/slf4j-log4j12⑴.7.5.jar:/home/adam/hadoop⑵.6.0/share/hadoop/common/lib/jsr305⑴.3.9.jar:/home/adam/h ... jar:/home/adam/hadoop⑵.6.0/share/hadoop/mapreduce/hadoop-mapreduce-client-app⑵.6.0.jar:/home/adam/hadoop⑵.6.0/share/hadoop/mapreduce/hadoop-mapreduce-client-core⑵.6.0.jar:/home/adam/hadoop⑵.6.0/share/hadoop/mapreduce/hadoop-mapreduce-client-shuffle⑵.6.0.jar:/home/adam/hadoop⑵.6.0/contrib/capacity-scheduler/*.jar STARTUP_MSG: build = https://git-wip-us.apache.org/repos/asf/hadoop.git -r e3496499ecb8d220fba99dc5ed4c99c8f9e33bb1; compiled by 'jenkins' on 2014⑴1⑴3T21:10Z STARTUP_MSG: java = 1.7.0_71 ************************************************************/ 15/01/14 19:29:58 INFO namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT] 15/01/14 19:29:58 INFO namenode.NameNode: createNameNode [-format] Formatting using clusterid: CID⑶f81e813⑹04e⑷d60⑼3b1⑼794d7c7c079 15/01/14 19:30:10 INFO namenode.FSNamesystem: No KeyProvider found. 15/01/14 19:30:10 INFO namenode.FSNamesystem: fsLock is fair:true 15/01/14 19:30:10 INFO blockmanagement.DatanodeManager: dfs.block.invalidate.limit=1000 15/01/14 19:30:10 INFO blockmanagement.DatanodeManager: dfs.namenode.datanode.registration.ip-hostname-check=true 15/01/14 19:30:10 INFO blockmanagement.BlockManager: dfs.namenode.startup.delay.block.deletion.sec is set to 000:00:00:00.000 15/01/14 19:30:10 INFO blockmanagement.BlockManager: The block deletion will start around 2015 Jan 14 19:30:10 15/01/14 19:30:10 INFO util.GSet: Computing capacity for map BlocksMap 15/01/14 19:30:10 INFO util.GSet: VM type = 64-bit 15/01/14 19:30:10 INFO util.GSet: 2.0% max memory 966.7 MB = 19.3 MB 15/01/14 19:30:10 INFO util.GSet: capacity = 2^21 = 2097152 entries 15/01/14 19:30:10 INFO blockmanagement.BlockManager: dfs.block.access.token.enable=false 15/01/14 19:30:10 INFO blockmanagement.BlockManager: defaultReplication = 1 15/01/14 19:30:10 INFO blockmanagement.BlockManager: maxReplication = 512 15/01/14 19:30:10 INFO blockmanagement.BlockManager: minReplication = 1 15/01/14 19:30:10 INFO blockmanagement.BlockManager: maxReplicationStreams = 2 15/01/14 19:30:10 INFO blockmanagement.BlockManager: shouldCheckForEnoughRacks = false 15/01/14 19:30:10 INFO blockmanagement.BlockManager: replicationRecheckInterval = 3000 15/01/14 19:30:10 INFO blockmanagement.BlockManager: encryptDataTransfer = false 15/01/14 19:30:10 INFO blockmanagement.BlockManager: maxNumBlocksToLog = 1000 15/01/14 19:30:10 INFO namenode.FSNamesystem: fsOwner = adam (auth:SIMPLE) 15/01/14 19:30:10 INFO namenode.FSNamesystem: supergroup = supergroup 15/01/14 19:30:10 INFO namenode.FSNamesystem: isPermissionEnabled = true 15/01/14 19:30:10 INFO namenode.FSNamesystem: Determined nameservice ID: hadoop-cluster 15/01/14 19:30:10 INFO namenode.FSNamesystem: HA Enabled: false 15/01/14 19:30:10 INFO namenode.FSNamesystem: Append Enabled: true 15/01/14 19:30:16 INFO util.GSet: Computing capacity for map INodeMap 15/01/14 19:30:16 INFO util.GSet: VM type = 64-bit 15/01/14 19:30:16 INFO util.GSet: 1.0% max memory 966.7 MB = 9.7 MB 15/01/14 19:30:16 INFO util.GSet: capacity = 2^20 = 1048576 entries 15/01/14 19:30:16 INFO namenode.NameNode: Caching file names occuring more than 10 times 15/01/14 19:30:16 INFO util.GSet: Computing capacity for map cachedBlocks 15/01/14 19:30:16 INFO util.GSet: VM type = 64-bit 15/01/14 19:30:16 INFO util.GSet: 0.25% max memory 966.7 MB = 2.4 MB 15/01/14 19:30:16 INFO util.GSet: capacity = 2^18 = 262144 entries 15/01/14 19:30:16 INFO namenode.FSNamesystem: dfs.namenode.safemode.threshold-pct = 0.9990000128746033 15/01/14 19:30:16 INFO namenode.FSNamesystem: dfs.namenode.safemode.min.datanodes = 0 15/01/14 19:30:16 INFO namenode.FSNamesystem: dfs.namenode.safemode.extension = 30000 15/01/14 19:30:16 INFO namenode.FSNamesystem: Retry cache on namenode is enabled 15/01/14 19:30:16 INFO namenode.FSNamesystem: Retry cache will use 0.03 of total heap and retry cache entry expiry time is 600000 millis 15/01/14 19:30:16 INFO util.GSet: Computing capacity for map NameNodeRetryCache 15/01/14 19:30:16 INFO util.GSet: VM type = 64-bit 15/01/14 19:30:16 INFO util.GSet: 0.029999999329447746% max memory 966.7 MB = 297.0 KB 15/01/14 19:30:16 INFO util.GSet: capacity = 2^15 = 32768 entries 15/01/14 19:30:16 INFO namenode.NNConf: ACLs enabled? false 15/01/14 19:30:16 INFO namenode.NNConf: XAttrs enabled? true 15/01/14 19:30:16 INFO namenode.NNConf: Maximum size of an xattr: 16384 15/01/14 19:30:16 INFO namenode.FSImage: Allocated new BlockPoolId: BP⑴507698623⑹0.191.124.254⑴421235016468 15/01/14 19:30:16 INFO common.Storage: Storage directory /home/adam/hadoop⑵.6.0/dfs/name has been successfully formatted. 15/01/14 19:30:17 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0 15/01/14 19:30:17 INFO util.ExitUtil: Exiting with status 0 15/01/14 19:30:17 INFO namenode.NameNode: SHUTDOWN_MSG: /************************************************************ SHUTDOWN_MSG: Shutting down NameNode at ubuntu/60.191.124.254 ************************************************************/

2. 启动Hadoop

hadoop/sbin start-all.sh或start-dfs.sh & start-yard.sh

3. 验证安装



 

启动Job History Server:

root@master:~/hadoop/sbin# ./mr-jobhistory-daemon.sh start historyserver


这样1个完全的散布式hadoop集群就装好了,步骤也不多,有兴趣的同学可以试1试,有甚么问题欢迎联系我:

微博:http://weibo.com/xtfggef

邮箱:xtfggef@gmail.com

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐