用户行为日志:用户每次访问网站时全部的行为数据(访问、浏览、搜索、点击...)
用户行为轨迹、流量日志
日志数据内容:
1)访问的系统属性: 操做系统、浏览器等等
2)访问特征:点击的url、从哪一个url跳转过来的(referer)、页面上的停留时间等
3)访问信息:session_id、访问ip(访问城市)等
数据处理流程
1)数据采集
Flume: web日志写入到HDFS
2)数据清洗
脏数据
Spark、Hive、MapReduce 或者是其余的一些分布式计算框架
清洗完以后的数据能够存放在HDFS(Hive/Spark SQL)
3)数据处理
按照咱们的须要进行相应业务的统计和分析
Spark、Hive、MapReduce 或者是其余的一些分布式计算框架
4)处理结果入库
结果能够存放到RDBMS、NoSQL
5)数据的可视化
经过图形化展现的方式展示出来:饼图、柱状图、地图、折线图
ECharts、HUE、Zeppelin
通常的日志处理方式,咱们是须要进行分区的,
按照日志中的访问时间进行相应的分区,好比:d,h,m5(每5分钟一个分区)
输入:访问时间、访问URL、耗费的流量、访问IP地址信息
输出:URL、cmsType(video/article)、cmsId(编号)、流量、ip、城市信息、访问时间、天
使用github上已有的开源项目
2)编译下载的项目:mvn clean package -DskipTests
3)安装jar包到本身的maven仓库
mvn install:install-file -Dfile=/Users/rocky/source/ipdatabase/target/ipdatabase-1.0-SNAPSHOT.jar -DgroupId=com.ggstar -DartifactId=ipdatabase -Dversion=1.0 -Dpackaging=jar
java.io.FileNotFoundException:
file:/Users/rocky/maven_repos/com/ggstar/ipdatabase/1.0/ipdatabase-1.0.jar!/ipRegion.xlsx (No such file or directory)
调优势:
1) 控制文件输出的大小: coalesce
2) 分区字段的数据类型调整:spark.sql.sources.partitionColumnTypeInference.enabled
3) 批量插入数据库数据,提交使用batch操做
create table day_video_access_topn_stat (
day varchar(8) not null,
cms_id bigint(10) not null,
times bigint(10) not null,
primary key (day, cms_id)
);
create table day_video_city_access_topn_stat (
day varchar(8) not null,
cms_id bigint(10) not null,
city varchar(20) not null,
times bigint(10) not null,
times_rank int not null,
primary key (day, cms_id, city)
);
create table day_video_traffics_topn_stat (
day varchar(8) not null,
cms_id bigint(10) not null,
traffics bigint(20) not null,
primary key (day, cms_id)
);
数据可视化:一副图片最伟大的价值莫过于它可以使得咱们实际看到的比咱们指望看到的内容更加丰富
常见的可视化框架
1)echarts
2)highcharts
3)D3.js
4)HUE
5)Zeppelin
在Spark中,支持4种运行模式:
1)Local:开发时使用
2)Standalone: 是Spark自带的,若是一个集群是Standalone的话,那么就须要在多台机器上同时部署Spark环境
3)YARN:建议你们在生产上使用该模式,统一使用YARN进行整个集群做业(MR、Spark)的资源调度
4)Mesos
无论使用什么模式,Spark应用程序的代码是如出一辙的,只须要在提交的时候经过--master参数来指定咱们的运行模式便可
Client
Driver运行在Client端(提交Spark做业的机器)
Client会和请求到的Container进行通讯来完成做业的调度和执行,Client是不能退出的
日志信息会在控制台输出:便于咱们测试
Cluster
Driver运行在ApplicationMaster中
Client只要提交完做业以后就能够关掉,由于做业已经在YARN上运行了
日志是在终端看不到的,由于日志是在Driver上,只能经过yarn logs -applicationIdapplication_id
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn \
--executor-memory 1G \
--num-executors 1 \
/home/hadoop/app/spark-2.1.0-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.1.0.jar \
4
此处的yarn就是咱们的yarn client模式
若是是yarn cluster模式的话,yarn-cluster
Exception in thread "main" java.lang.Exception: When running with master 'yarn' either HADOOP_CONF_DIR or YARN_CONF_DIR must be set in the environment.
若是想运行在YARN之上,那么就必需要设置HADOOP_CONF_DIR或者是YARN_CONF_DIR
1) export HADOOP_CONF_DIR=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop
2) $SPARK_HOME/conf/spark-env.sh
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn-cluster \
--executor-memory 1G \
--num-executors 1 \
/home/hadoop/app/spark-2.1.0-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.1.0.jar \
4
yarn logs -applicationId application_1495632775836_0002
打包时要注意,pom.xml中须要添加以下plugin
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass></mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
mvn assembly:assembly
./bin/spark-submit \
--class com.imooc.log.SparkStatCleanJobYARN \
--name SparkStatCleanJobYARN \
--master yarn \
--executor-memory 1G \
--num-executors 1 \
--files /home/hadoop/lib/ipDatabase.csv,/home/hadoop/lib/ipRegion.xlsx \
/home/hadoop/lib/sql-1.0-jar-with-dependencies.jar \
hdfs://hadoop001:8020/imooc/input/* hdfs://hadoop001:8020/imooc/clean
注意:--files在spark中的使用
spark.read.format("parquet").load("/imooc/clean/day=20170511/part-00000-71d465d1-7338-4016-8d1a-729504a9f95e.snappy.parquet").show(false)
./bin/spark-submit \
--class com.imooc.log.TopNStatJobYARN \
--name TopNStatJobYARN \
--master yarn \
--executor-memory 1G \
--num-executors 1 \
/home/hadoop/lib/sql-1.0-jar-with-dependencies.jar \
hdfs://hadoop001:8020/imooc/clean 20170511
调整并行度
./bin/spark-submit \
--class com.imooc.log.TopNStatJobYARN \
--name TopNStatJobYARN \
--master yarn \
--executor-memory 1G \
--num-executors 1 \
--conf spark.sql.shuffle.partitions=100 \
/home/hadoop/lib/sql-1.0-jar-with-dependencies.jar \
hdfs://hadoop001:8020/imooc/clean 20170511