赞
踩
Start-dfs.sh
命令,会启动哪几个线程?每个线程分别有什么作用?Zookeeper在HBase中有哪些作用?
- 保存 Meta 表位置、记录并监听 Master 主备状态
CAP是一致性(Consistency)、可用性(Availability)和分区容错性(Partition Tolerance)。
MySQL(关系型数据库)
MongoDB(分布式非关系型数据库)
Redis(键值型非关系型数据库)
hdfs dfs -ls /
hdfs dfs -mkdir -p /tmp/test_hdfs
-p
参数允许创建多级目录,如果父目录不存在则会一并创建。在 /tmp
下创建名为 test_hdfs
的目录hdfs dfs -put testfile.zip /tmp/test_hdfs
testfile.zip
文件上传到HDFS的 /tmp/test_hdfs
目录下。create ‘exam_info’, ‘info’
exam_info
的表,并定义一个名为 info
的列族。put ‘exam_info’, ‘123001’, ‘info:name’, ‘Elle’
exam_info
表中插入数据。将 123001
作为行键,info:name
作为列名,Elle
作为该列的值。get ‘exam_info’, ‘123001’, ‘info:name’
exam_info
表中检索数据。获取行键为 123001
的记录中,列名为 info:name
的值。scan ‘exam_info’, {COLUMNS => ‘info:name’}
exam_info
表,只返回列族 info
中列名为 name
的数据。delete all ‘exam_info’, ‘123001’
exam_info
表中行键为 123001
的所有数据。HDFS代码命令解释题目
FileSystem fs = FileSystem.get(new URI("hdfs://192.168.1.2:9000"), new Configuration(), "root");
fs.deleteOnExit("/java");
deleteOnExit
方法,标记文件系统中的 /java
目录,在JVM退出时自动删除该目录。Hbase命令解释题
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
Table table = connection.getTable(TableName.valueOf("student"));
Put put = new Put("2022001".getBytes());
put.addColumn("info".getBytes(), "name".getBytes(), "Kate".getBytes());
table.put(put);
table.close();
student
的表的实例,创建一个 Put
对象来插入数据,指定行键为 2022001
,列族为 info
,列名为 name
,值为 Kate
。Put
对象通过 table.put()
方法插入到表中,并关闭表连接。数据采集层
实时处理层
数据存储层
业务应用层
数据分析层
Amber 2000
Lily 2001
Lesile 2001
Kate 2000
Mike 2001
Jason 1999
Rachel 1999
//ExamMapper.java import java.io.IOException; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; public class ExamMapper extends Mapper<LongWritable, Text, Text, IntWritable> { //记住父类参数 @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { //将年份提取作为key,value为1 Text year =new Text(); //key String str = value.toString(); //整行内容 String[] parts = str.split(" "); // 数据以空格分隔 String birthYear = parts[1]; // 出生年份是第二个字段 year.set(birthYear); context.write(year, new IntWritable(1)); //key为年份 value默认为1 } }
//ExamReducer.java import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; public class ExamReducer extends Reducer<Text, IntWritable, Text, IntWritable> { //记住父类参数 @Override protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { //将map结果根据key值分类,将value值相加 int sum = 0; for (IntWritable val : values) { sum += val.get(); } context.write(key, new IntWritable().set(sum)); //根据key值 将vlaue相加 } }
//ExamJob.java import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class ExamJob { public static void main(String[] args) throws Exception { //获取作业对象 Job job = Job.getInstance(new Configuration()); //设置主类 job.setJarByClass(ExamJob.class); //关联mapper和reducer job.setMapperClass(ExamMapper.class); job.setReducerClass(ExamReducer.class); //设置mapper输出的k、v job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.class); //设置reducer输出的k、v job.setOutputKeyClass(Text.class); //文本 job.setOutputValueClass(IntWritable.class); //int //设置job输入、输出 FileInputFormat.setInputPaths(job, new Path("file:///source.txt")); FileOutputFormat.setOutputPath(job, new Path("file:///output")); System.exit(job.waitForCompletion(true) ? 0 : 1); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。