离线电商数仓(七)之用户行为数据采集(七)组件安装(三)日志生成

1 日志启动

1代码参数说明

// 参数一:控制发送每条的延时时间,默认是0
Long delay = args.length > 0 ? Long.parseLong(args[0]) : 0L;

// 参数二:循环遍历次数
int loop_len = args.length > 1 ? Integer.parseInt(args[1]) : 1000;

2)将生成jar包log-collector-0.0.1-SNAPSHOT-jar-with-dependencies.jar拷贝hadoop102、服务器,并同步到hadoop103/opt/module路径

[atguigu@hadoop102 module]$ xsync log-collector-1.0-SNAPSHOT-jar-with-dependencies.jar

3)在hadoop102上执行jar程序

[atguigu@hadoop102 module]$ java -classpath log-collector-1.0-SNAPSHOT-jar-with-dependencies.jar com.atguigu.appclient.AppMain  >/opt/module/test.log

4)在/tmp/logs路径下查看生成的日志文件

[atguigu@hadoop102 module]$ cd /tmp/logs/
[atguigu@hadoop102 logs]$ ls
app-2019-02-10.log

2 集群日志生成启动脚本

1)在/home/atguigu/bin目录下创建脚本lg.sh

[atguigu@hadoop102 bin]$ vim lg.sh

2)在脚本中编写如下内容

#! /bin/bash
for i in hadoop102 hadoop103
do
        ssh $i "source /etc/profile;java -cp /opt/module/log-collector-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.atguigu.appclient.AppMain $1 $2 > /dev/null 2>&1 &"
done

生成的日志存储在 /tmp/ logs中

3)修改脚本执行权限

[atguigu@hadoop102 bin]$ chmod 777 lg.sh

4)启动脚本

[atguigu@hadoop102 module]$ lg.sh 

5)分别hadoop102、hadoop103/tmp/logs目录查看生成的数据

[atguigu@hadoop102 logs]$ ls
app-2019-02-10.log
[atguigu@hadoop103 logs]$ ls
app-2019-02-10.log

3 集群时间同步修改脚本

1)在/home/atguigu/bin目录下创建脚本dt.sh

[atguigu@hadoop102 bin]$ vim dt.sh

2)在脚本中编写如下内容

#!/bin/bash

for i in hadoop102 hadoop103 hadoop104
do
        echo "========== $i =========="
        ssh -t $i "sudo date -s '$@'"
done

3)修改脚本执行权限

[atguigu@hadoop102 bin]$ chmod 777 dt.sh

4)启动脚本

[atguigu@hadoop102 bin]$ dt.sh 2019-2-10

4 集群所有进程查看脚本

1)在/home/atguigu/bin目录下创建脚本xcall.sh

[atguigu@hadoop102 bin]$ vim xcall.sh

2)在脚本中编写如下内容

#! /bin/bash

for i in hadoop102 hadoop103 hadoop104
do
        echo --------- $i ----------
        ssh $i "$*"
done

3)修改脚本执行权限

[atguigu@hadoop102 bin]$ chmod 777 xcall.sh

4)启动脚本

[atguigu@hadoop102 bin]$ xcall.sh jps
原文地址:https://www.cnblogs.com/qiu-hua/p/13504401.html