三台机器,一台master (角色:namenode, hbase master, zookeeper), 两台slave(s1,s2) (角色:datanode, hbase region server, zookeeper), 

每台机器上设置:

在/etc/hosts中设置名字解析:

192.168.1.2  master
192.168.1.3  s1
192.168.1.4  s2

三台机器设置用户名hadoop密码hadoop,并且设置三台机器无密码ssh互访

下载hadoop-1.0.4.tar.gz,zookeeper-3.4.3.tar.gz, hbase-0.94.0.tar.gz

在/opt/下mkdir hadoop,下面所有的安装包都解压到这里

********************************

hadoop

********************************

1> 在master机器上解压hadoop-1.0.4.tar.gz,cd conf,修改配置文件:

hadoop-env.sh, 设置export JAVA_HOME=/opt/las/current/jdk (你的jdk安装路径)

core-site.xml

<!-- Put site-specific property overrides in this file. -->

<configuration>
  <property>
          <name>fs.default.name</name>
          <value>hdfs://master:9000</value>
        </property>

        <property>
          <name>Hadoop.tmp.dir</name>
          <value>/tmp/Hadoop-root</value>
  </property>
</configuration>
notes: fs.default.name,设置namenode所在主机,端口号是9000


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>2</value>
  </property>
</configuration>

notes: dfs.replication,设置数据块的复制次数,默认是3,如果slave节点数少于3,则写成相应的1或者2


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>http://master:9001</value>
  </property>
</configuration>

notes: mapred.job.tracker,设置jobtracker所在机器,端口号9001


2> 修改conf/masters,内容设置为master, 修改conf/slaves,内容设置为:

s1

s2

3> 将解压以后并配置好的hadoop-1.0.4整个文件夹拷贝到两台slave上

4> 在master上,运行/bin/start-all.sh 并用jps命令查看如下:

[hadoop@master bin]$ /opt/las/current/jdk/bin/jps
22735 SecondaryNameNode
23068 Jps
22825 JobTracker
22568 NameNode

在s1上查看:

[hadoop@s1 logs]$  /opt/las/current/jdk/bin/jps
11201 TaskTracker
11097 DataNode
11319 Jps

在s2上查看:

[hadoop@s2 bin]$ /opt/las/current/jdk/bin/jps
29663 TaskTracker
29715 Jps
29561 DataNode


打开浏览器,输入http://192.168.1.2:50070 可以查看namenode,点击Live Nodes可以查看data node

输入http://192.168.1.2:50030查看master Hadoop Map/Reduce Administration

192.168.1.2是master的IP


*********************************************

zookeeper:

*********************************************

1>在master机器上解压zookeeper,cd conf,  cp zoo_sample.cfg zoo.cfg, 默认采用zoo.cfg作为配置文件

修改zoo.cfg:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181

server.1=s1:2888:3888
server.2=s2:2888:3888
server.3=master:2888:3888


2> 将解压并配置好的zookeeper-3.4.3整个文件夹scp到s1与s2

3> 在master的data目录/tmp/zookeeper(没有就手动创建)下,创建文件myid,内容为3, 同样,s1与s2内容分别为1和2

4> 分别在三台机器上启动zookeeper:

bin/zkServer.sh start,

通过命令./zkServer.sh status查看状态,一个为leader,其他为follower

log文件:bin/zookeeper.out


******************************************************

                                     hbase

******************************************************

1> 在master机器上 解压hbase-0.94.0.tar.gz ,

将hbase-0.94.0/lib下面的hadoop-core-1.0.2.jar 删除并替换为已经安装的hadoop-core-1.0.4.jar

2> 修改conf/hbase-env.sh 里面JAVA_HOME路径 并设置export HBASE_MANAGES_ZK=false,这样禁止hbase使用自带的zookeeper

3> hbase-site.xml:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://master:9000/hbase</value>
  </property>
  <property>
    <name>hbase.cluster.distributed</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.zookeeper.quorum</name>
    <value>master,s1,s2</value>
  </property>
</configuration>

4> 修改conf/regionservers,设置为

s1

s2

5> 将hbase-0.94修改后的整个文件加拷贝到s1, s2

6> 在master机器上运行.bin/start-hbase.sh,将会启动三台机器上的hbase

此时在master上运行jps命令:

[hadoop@master bin]$ /opt/las/current/jdk/bin/jps
22735 SecondaryNameNode
24604 Jps
23963 QuorumPeerMain
24479 HMaster
22825 JobTracker
22568 NameNode


s1上运行jps:

[las@3as03-guest1 hadoop]$ /opt/las/current/jdk/bin/jps
11953 Jps
11611 QuorumPeerMain
11201 TaskTracker
11097 DataNode
11892 HRegionServer

s2上运行jps:

[las@3as03-guest2 hadoop]$ /opt/las/current/jdk/bin/jps
30339 QuorumPeerMain
29663 TaskTracker
30739 HRegionServer
30810 Jps
29561 DataNode


在浏览器中打开192.168.1.2:60010可以看到hbase master的页面,打开192.168.1.3:60030或者192.168.1.4:60030 可以看到hbase region server的页面

如果页面打不开,则可能是hadoop安全模式的问题,可以查看log确定,如果是这个问题,可以通过下面的常见问题关掉。


整个系统启动过程为:hdoop, zookeeper, hbase,停止的过程相反


*************************

常见问题:

*************************

1> 在master上./start-all.sh以后,通过jps命令查看slave机器发现TaskTracker启动了,但是datanode没有启动,查看slave机器上的logs下的hadoop-xxx-datanode-xxx-xxx.log

ERROR org.apache.hadoop.hdfs.server.datanode.DataNode: java.io.IOException: Incompatible namespaceIDs in /tmp/hadoop-las/dfs/data: namenode namespaceID = 1837940173; datanode namespaceID = 637354847

解决方案:http://blog.csdn.net/wh62592855/article/details/5752199, 这里采用的是删掉/tmp下面的文件系统重新bin/hadoop namenode -format


2> 退出hbase的时候一直处于等待状态,查看log:

Waiting for dfs to exit safe mode...

解决方案:在hadoop的bin目录下执行 ./hadoop dfsadmin -safemode leave 退出安全模式


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐