分分钟搞定Hadoop-1.2.1集群
--Linux下搭建Hadoop-1.2.1集群
10分钟搞定Hadoop-1.2.1集群系列(1) http://chwshuang.iteye.com/blog/2037102
10分钟搞定Hadoop-1.2.1集群系列(2) http://chwshuang.iteye.com/blog/2037530
在搭建Hadoop集群前,请做好准备工作,准备工作做好,10分钟就能看到集群环境。
一、搭建环境(前提条件)
系统:CentOS6.4 64bit
软件环境:JDK1.6.0_45 Linux安装JDK请参考其他网络文章
其他:sshd免密码登录环境 请参考此文章 http://chwshuang.iteye.com/admin/blogs/2015040
下载软件包:
hadoop-1.2.1.tar.gz 下载地址 http://mirrors.cnnic.cn/apache/hadoop/common/hadoop-1.2.1/hadoop-1.2.1.tar.gz
zookeeper-3.4.6.tar.gz 下载地址 http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
hbase-0.94.17.tar.gz 下载地址 http://mirrors.cnnic.cn/apache/hbase/hbase-0.94.17/hbase-0.94.17.tar.gz
服务器列表:
服务器别名 | 服务器地址 | 服务器说明 |
myhadoop1 | 192.168.1.111 | 主NameNode服务器 |
myhadoop2 | 192.168.1.112 | 从Datanode服务器 |
myhadoop3 | 192.168.1.113 | 从Datanode服务器 |
二、搭建流程
1. 添加用户 -- (以root用户在每台服务器上执行)
(1)执行添加用户命令
useradd -d /home/myhadoop -s /bin/bash -m myhadoop
(2)执行如下命令,为用户“myhadoop”设置密码。
passwd myhadoop
(3)您需要根据系统的提示输入两次密码“1234QWER”,然后通过以下命令进入主目录
[root@hadoop1 ~]# useradd -d /home/myhadoop -s /bin/bash -m myhadoop
[root@hadoop1 ~]# passwd myhadoop
Changing password for user myhadoop.
New password:
BAD PASSWORD: it is too simplistic/systematic
Retype new password:
passwd: all authentication tokens updated successfully.
[root@hadoop1 ~]#
2. 修改主机名称 -- hostname添加集群服务器别名IP关系 -- (以root用户在每台服务器上执行)
需要修改3个地方,如果只修改hostname 指令这一处,重启电脑后还是会变回来。/etc/hosts主机文件, 这个地方修改是给DNS解析用的,单独修改也不行。只有三个地方同时修改才能算修改完成。修改完成后重启服务器。
【1】 hostname 指令中修改。
直接输入hostname查看主机名是不是hadoop,如果不是,输入“hostname myhadoop1” 再输入 “hostname” 进行验证
[root@hadoop1 ~]# hostname
hadoop1
[root@hadoop1 ~]# hostname myhadoop1
[root@hadoop1 ~]# hostname
myhadoop1
[root@hadoop1 ~]#
【2】使用 vim /etc/sysconfig/network 修改网络配置中主机名,将修改 HOSTNAME=myhadoop1, 如果是192.168.1.112就改为HOSTNAME=myhadoop2
[root@hadoop1 ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=myhadoop1
【3】使用 vim /etc/hosts 修改主机文件中本机名称,修改192.168.1.101后面的名称为 myhadoop1。其他以此类推。
[root@hadoop1 ~]# vim /etc/hosts
127.0.0.1 localhost
192.168.1.111 myhadoop1
192.168.1.112 myhadoop2
192.168.1.113 myhadoop3
#::1 localhost6.localdomain6 localhost6
【4】重启服务器
以root 用户登录后,输入 reboot
3. 安装
安装前需要配置,在配置时,只需要配置111这一台服务器,配置完成后,把111配置好的hadoop目录拷贝到其他服务器就可以了。
【1】 安装包解压、配置 -- (以刚刚创建的myhadoop用户登录服务器)
(1) wget 下载
在/home/myhadoop目录输入以下命令下载:
wget http://mirrors.cnnic.cn/apache/hadoop/common/hadoop-1.2.1/hadoop-1.2.1.tar.gz
wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
wget http://mirrors.cnnic.cn/apache/hbase/hbase-0.94.17/hbase-0.94.17.tar.gz
(2)如个使用第一种方式发现速度很慢,可以使用其他方式下载,然后上传到服务器
将hadoop-1.2.1.tar.gz、zookeeper-3.4.6.tar.gz、hbase-0.94.17.tar.gz安装包拷贝到/home/myhadoop目录下
(3)授权
如果是root用户下载的就需要使用以下方式进行授权
[root@myhadoop1 myhadoop]# ll --- 先查看刚刚下载的文件权限
total 136864
-rw-rw--w-. 1 root root 63851630 Jul 23 2013 hadoop-1.2.1.tar.gz
-rw-rw--w-. 1 root root 58592781 Feb 26 09:31 hbase-0.94.17.tar.gz
-rw-rw--w-. 1 root root 17699306 Feb 20 20:04 zookeeper-3.4.6.tar.gz
[root@myhadoop1 myhadoop]# chown myhadoop.myhadoop * ---将文件的所有者和组设置为myhadoop
[root@myhadoop1 myhadoop]# ll
total 136864
-rw-rw--w-. 1 myhadoop myhadoop 63851630 Jul 23 2013 hadoop-1.2.1.tar.gz
-rw-rw--w-. 1 myhadoop myhadoop 58592781 Feb 26 09:31 hbase-0.94.17.tar.gz
-rw-rw--w-. 1 myhadoop myhadoop 17699306 Feb 20 20:04 zookeeper-3.4.6.tar.gz
[root@myhadoop1 myhadoop]# chmod 775 * --- 将文件的读写、执行权限打开
[root@myhadoop1 myhadoop]# ll
total 136864
-rwxrwxr-x. 1 myhadoop myhadoop 63851630 Jul 23 2013 hadoop-1.2.1.tar.gz
-rwxrwxr-x. 1 myhadoop myhadoop 58592781 Feb 26 09:31 hbase-0.94.17.tar.gz
-rwxrwxr-x. 1 myhadoop myhadoop 17699306 Feb 20 20:04 zookeeper-3.4.6.tar.gz
[root@myhadoop1 myhadoop]#
(4)以myhadoop用户登录,解压压缩包
[root@myhadoop1 myhadoop]# su myhadoop -- root用户切换到myhadoop用户
[myhadoop@myhadoop1 ~]$ ls
hadoop-1.2.1.tar.gz hbase-0.94.17.tar.gz zookeeper-3.4.6.tar.gz
[myhadoop@myhadoop1 ~]$ tar -xzf hadoop-1.2.1.tar.gz --- 解压
[myhadoop@myhadoop1 ~]$ tar -xzf hbase-0.94.17.tar.gz
[myhadoop@myhadoop1 ~]$ tar -xzf zookeeper-3.4.6.tar.gz
[myhadoop@myhadoop1 ~]$ ll
total 136876
drwxr-xr-x. 15 myhadoop myhadoop 4096 Jul 23 2013 hadoop-1.2.1
-rwxrwxr-x. 1 myhadoop myhadoop 63851630 Jul 23 2013 hadoop-1.2.1.tar.gz
drwxr-xr-x. 10 myhadoop myhadoop 4096 Feb 19 07:42 hbase-0.94.17
-rwxrwxr-x. 1 myhadoop myhadoop 58592781 Feb 26 09:31 hbase-0.94.17.tar.gz
drwxr-xr-x. 10 myhadoop myhadoop 4096 Feb 20 18:58 zookeeper-3.4.6
-rwxrwxr-x. 1 myhadoop myhadoop 17699306 Feb 20 20:04 zookeeper-3.4.6.tar.gz
[myhadoop@myhadoop1 ~]$
(5) 设置环境变量 -- 以root 用户设置
[myhadoop@myhadoop1 ~]$ exit --- 如果是root用户登录到myhadoop用户,直接退出就到root用户下了
exit
[root@myhadoop1 myhadoop]# vim /etc/profile --- 要修改的环境配置文件
## -------------------JAVA HADOOP PATH------------------------##
JAVA_HOME=/usr/java/jdk1.6.0_45
HADOOP_HOME=/home/myhadoop/hadoop-1.2.1
PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export JAVA_HOME PATH HADOOP_HOME
export HADOOP_HOME_WARN_SUPPRESS=1 --- 此配置是用来解决hadoop启动警告
##----------------------- hbase ------------------------------##
export HBASE_HOME=/home/myhadoop/hbase-0.94.17
export PATH=$PATH:$HBASE_HOME/bin
##------------------------ zookeeper -------------------------##
ZK_HOME=/home/myhadoop/zookeeper-3.4.6
PATH=$ZK_HOME/bin:$PATH
export PATH ZK_HOME
[root@myhadoop1 myhadoop]# source /etc/profile --- 让配置立即生效
【2】 安装hadoop
需要配置hadoop-env.sh、core-site.xml
(1)配置 -- 修改启动文件 hadoop-1.2.1/conf/hadoop-env.sh
[root@myhadoop1 myhadoop]# su myhadoop --- 以myhadoop用户进行配置
[myhadoop@myhadoop1 ~]$ ls
hadoop-1.2.1 hadoop-1.2.1.tar.gz hbase-0.94.17 hbase-0.94.17.tar.gz zookeeper-3.4.6 zookeeper-3.4.6.tar.gz
[myhadoop@myhadoop1 ~]$ vim hadoop-1.2.1/conf/hadoop-env.sh
# The java implementation to use. Required.
export JAVA_HOME=/usr/java/jdk1.6.0_45
(2) 配置主配置文件 hadoop-1.2.1/conf/core-site.xml
[myhadoop@myhadoop1 ~]$ vim hadoop-1.2.1/conf/core-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://192.168.1.111:9000</value>
</property>
</configuration>
(3)修改hdfs配置文件hadoop-1.2.1/conf/hdfs-site.xml
[myhadoop@myhadoop1 ~]$ vim hadoop-1.2.1/conf/hdfs-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.replication</name>
<value>3</value> <!-- 表示3个从服务器 -->
</property>
</configuration>
(4)配置任务调度服务配置hadoop-1.2.1/conf/mapred-site.xml
[myhadoop@myhadoop1 ~]$ vim hadoop-1.2.1/conf/mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>192.168.1.111:9001</value> <!-- 配置到主服务器9001端口 -->
</property>
</configuration>
(5)配置主服务器地址 hadoop-1.2.1/conf/masters
[myhadoop@myhadoop1 ~]$ vim hadoop-1.2.1/conf/masters
192.168.1.111
(6)配置从服务器地址hadoop-1.2.1/conf/slaves
[myhadoop@myhadoop1 ~]$ vim hadoop-1.2.1/conf/slaves
192.168.1.111
192.168.1.112
192.168.1.113
(7)格式化节点服务器 -- 注意:如果执行过程出现ERROR信息必须解决后重新格式化
[myhadoop@myhadoop1 ~]$ cd hadoop-1.2.1/bin/ --- 进入bin执行文件目录
[myhadoop@myhadoop1 bin]$ hadoop namenode -format --- 执行节点格式化
14/03/27 10:46:39 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = myhadoop1/192.168.1.111
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 1.2.1
STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.2 -r 1503152; compiled by 'mattf' on Mon Jul 22 15:23:09 PDT 2013
STARTUP_MSG: java = 1.6.0_45
************************************************************/
14/03/27 10:46:39 INFO util.GSet: Computing capacity for map BlocksMap
14/03/27 10:46:39 INFO util.GSet: VM type = 64-bit
14/03/27 10:46:39 INFO util.GSet: 2.0% max memory = 1013645312
14/03/27 10:46:39 INFO util.GSet: capacity = 2^21 = 2097152 entries
14/03/27 10:46:39 INFO util.GSet: recommended=2097152, actual=2097152
14/03/27 10:46:40 INFO namenode.FSNamesystem: fsOwner=myhadoop
14/03/27 10:46:40 INFO namenode.FSNamesystem: supergroup=supergroup
14/03/27 10:46:40 INFO namenode.FSNamesystem: isPermissionEnabled=true
14/03/27 10:46:40 INFO namenode.FSNamesystem: dfs.block.invalidate.limit=100
14/03/27 10:46:40 INFO namenode.FSNamesystem: isAccessTokenEnabled=false accessKeyUpdateInterval=0 min(s), accessTokenLifetime=0 min(s)
14/03/27 10:46:40 INFO namenode.FSEditLog: dfs.namenode.edits.toleration.length = 0
14/03/27 10:46:40 INFO namenode.NameNode: Caching file names occuring more than 10 times
14/03/27 10:46:41 INFO common.Storage: Image file /tmp/hadoop-myhadoop/dfs/name/current/fsimage of size 114 bytes saved in 0 seconds.
14/03/27 10:46:41 INFO namenode.FSEditLog: closing edit log: position=4, editlog=/tmp/hadoop-myhadoop/dfs/name/current/edits
14/03/27 10:46:41 INFO namenode.FSEditLog: close success: truncate to 4, editlog=/tmp/hadoop-myhadoop/dfs/name/current/edits
14/03/27 10:46:41 INFO common.Storage: Storage directory /tmp/hadoop-myhadoop/dfs/name has been successfully formatted.
14/03/27 10:46:41 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at myhadoop1/192.168.1.111
************************************************************/
[myhadoop@myhadoop1 bin]$
(8)拷贝hadoop-1.2.1到其他服务器
[myhadoop@myhadoop1 ~]$ cd ~ --- 进入myhadoop主目录 输入以下命令拷贝
[myhadoop@myhadoop1 ~]$ scp -r hadoop-1.2.1 myhadoop@myhadoop2:~
[myhadoop@myhadoop1 ~]$ scp -r hadoop-1.2.1 myhadoop@myhadoop3:~
拷贝过程不需要输入密码,如果出现提示输入密码,应该就是免密码登录没有设置好导致的
(9)启动和停止集群 在主服务器上输入:start-all.sh 启动集群, 输入jps可以看到启动的服务
[myhadoop@myhadoop1 ~]$ start-all.sh
starting namenode, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-namenode-myhadoop1.out
192.168.1.112: starting datanode, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-datanode-myhadoop2.out
192.168.1.113: starting datanode, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-datanode-myhadoop3.out
192.168.1.111: starting datanode, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-datanode-myhadoop1.out
192.168.1.111: starting secondarynamenode, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-secondarynamenode-myhadoop1.out
starting jobtracker, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-jobtracker-myhadoop1.out
192.168.1.112: starting tasktracker, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-tasktracker-myhadoop2.out
192.168.1.113: starting tasktracker, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-tasktracker-myhadoop3.out
192.168.1.111: starting tasktracker, logging to /home/myhadoop/hadoop-1.2.1/libexec/../logs/hadoop-myhadoop-tasktracker-myhadoop1.out
[myhadoop@myhadoop1 ~]$ jps
3749 DataNode
3629 NameNode
3972 JobTracker
4102 TaskTracker
4149 Jps
3872 SecondaryNameNode
[myhadoop@myhadoop1 ~]$
在从服务器上输入:jps可以看到节点服务和任务调度服务已经启动
[myhadoop@myhadoop2 ~]$ jps
3690 Jps
3607 TaskTracker
3502 DataNode
[myhadoop@myhadoop2 ~]$
在主服务器上输入stop-all.sh就可以关闭整个集群
[myhadoop@myhadoop1 ~]$ stop-all.sh
stopping jobtracker
192.168.1.112: stopping tasktracker
192.168.1.111: stopping tasktracker
192.168.1.113: stopping tasktracker
stopping namenode
192.168.1.112: stopping datanode
192.168.1.111: stopping datanode
192.168.1.113: stopping datanode
192.168.1.111: stopping secondarynamenode
[myhadoop@myhadoop1 ~]$
(10)查看
通过浏览器进行查看: http://192.168.1.111:50070/ 查看hadoop运行状态。
如果某些地址看不了,应该是windows下的hosts文件没有配置主机IP和主机名映射导致的,比如windows7下,就修改C:\Windows\System32\drivers\etc\hosts这个文件,加入主机名和IP映射
192.168.1.111 hadoop1
192.168.1.112 hadoop2
192.168.1.113 hadoop3