[2011-09-21] Hadoop and HBase 配置汇总

本文详细介绍了在Hadoop和HBase环境下进行配置的方法,包括master和slave节点的配置,以及如何正确设置HBase的配置文件和class路径,确保程序在Hadoop上正常运行。
Hadoop

conf/masters

hadoop-master


conf/slaves

hadoop-master
hadoop-slave1
hadoop-slave2


conf/hadoop-env.sh

export JAVA_HOME=/home/michael/lib/jdk1.6.0_27


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


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>hadoop-master:54311</value>
</property>
</configuration>


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://hadoop-master:54310</value>
</property>
</configuration>



HBase

conf/hbase-env.sh

export JAVA_HOME=/home/michael/lib/jdk1.6.0_27
export HBASE_MANAGES_ZK=true


conf/hbase-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://hadoop-master:54310/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.master</name>
<value>hdfs://hadoop-master:6000</value>
</property>

<property>
<name>hbase.zookeeper.quorum</name>
<value>yq-cl-svr3</value>
</property>
</configuration>


conf/regionservers

hadoop-master
hadoop-slave1
hadoop-slave2


将两个conf都配置好以后,复制到其他机器即可

update 2011-09-22:

为了让我们写的程序能够在hadoop上正常运行,需要将hbase的配置文件和CLASSPATH添加到hadoop的配置中

首先是配置文件

ln -s ../hbase-0.90.3-cdh3u1/conf/hbase-site.xml conf/hbase-site.xml

然后添加hbase的classpath到hadoop
conf/hadoop-env.sh

export JAVA_HOME=/home/michael/lib/jdk1.6.0_27
export HBASE_HOME=/home/michael/cdh/hbase-0.90.3-cdh3u1
export HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath`


很有用的Tip:
bin/hadoop classpath 和 bin/hbase classpath 可以查看相应的classpath
### 构建基于HadoopHBase的共享单车数据分析系统的架构设计 #### 1. 系统概述 为了有效管理和分析共享单车的数据,可以采用Hadoop生态系统中的多个组件来构建一个高效的大数据分析平台。该平台不仅能够处理大规模的日志数据,还能支持实时查询和复杂的数据分析操作。 #### 2. 数据采集层 在数据采集阶段,可以通过Flume收集来自不同源(如移动应用程序、GPS设备等)产生的原始骑行记录和其他相关联的信息。这些信息会被传输到临时缓冲区等待进一步处理[^2]。 ```bash agent.sources = r1 agent.sinks = k1 agent.channels = c1 agent.sources.r1.type = netcat agent.sources.r1.bind = localhost agent.sources.r1.port = 44444 agent.sinks.k1.type = hdfs agent.sinks.k1.hdfs.path = /user/flume/bike_data/ agent.sinks.k1.hdfs.fileType = DataStream agent.sinks.k1.hdfs.writeFormat = Text agent.channels.c1.type = memory agent.channels.c1.capacity = 1000 agent.channels.c1.transactionCapacity = 100 agent.sources.r1.channels = c1 agent.sinks.k1.channel = c1 ``` 此配置文件定义了一个简单的Flume agent用于接收并保存至HDFS上的自行车行程日志。 #### 3. 存储与管理 对于结构化较好的历史骑行事件,推荐使用HBase作为主要数据库;而对于非结构性较强的元数据或其他辅助资料,则更适合存放在Hive表内以便于后续统计汇总。此外,在某些情况下也可以考虑利用HDFS直接存储未经加工过的原始文件副本以备不时之需[^1]。 - **HBase 表结构** - `rowkey`: 组合键,可能包含时间戳+单车ID/用户ID等形式。 - 列族:基本信息(bike_info)、位置轨迹(location_trace) ```sql CREATE TABLE IF NOT EXISTS bike_trips ( row_key STRING, bike_info CF, location_trace CF ); ``` #### 4. 大规模离线批处理 借助MapReduce框架执行周期性的ETL任务,比如清理异常值、补充缺失字段或是聚合统计数据。这有助于提高在线服务性能的同时也便于长期趋势研究。 ```java public class BikeTripMapper extends Mapper<LongWritable, Text, NullWritable, MapWritable> { @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String[] fields = value.toString().split(","); // Process each field and emit results... } } ``` 上述Java代码片段展示了如何编写自定义映射器类来进行初步过滤及预处理工作。 #### 5. 实时流式计算 通过集成Apache Storm或Spark Streaming实现近似即时响应的功能模块,例如监控热点区域流量变化情况并向运维人员发送预警通知。 ```scala val ssc = new StreamingContext(sparkConf, Seconds(1)) ssc.socketTextStream("localhost", 9999).foreachRDD { rdd => val sqlContext = SQLContext.getOrCreate(rdd.sparkContext) import org.apache.spark.sql.functions._ import sqlContext.implicits._ val df = rdd.toDF() .withColumn("timestamp", unix_timestamp($"time")) // Perform real-time analysis on the DataFrame 'df' } ssc.start() // Start the computation ssc.awaitTermination() // Wait for the computation to terminate ``` 这段Scala脚本说明了怎样设置基本的Spark Streaming环境,并准备对输入流做简单的时间戳解析。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值