1. 程式人生 > 實用技巧 >大資料實戰(十四):電商數倉(七)之使用者行為資料採集(七)元件安裝(三)日誌生成

大資料實戰(十四):電商數倉(七)之使用者行為資料採集(七)元件安裝(三)日誌生成

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 "java -classpath /opt/module/gmall/logcollector-1.0-SNAPSHOT-jar-with-dependencies.jar com.atguigu.appclient.AppMain $1 $2 > /opt/module/test.log &
" done

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 $1"
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