1. 程式人生 > >赫拉(hera)分散式任務排程系統之專案啟動(二)

赫拉(hera)分散式任務排程系統之專案啟動(二)

克隆hera

暫時還未開源 後面補上。

建立表

當使用githera克隆到本地之後,首先在hera/hera-admin/resources目錄下找到hera.sql檔案,在自己的資料庫中新建這些必要的表,並插入初始化的資料。

此時可以在hera/hera-admin/resources目錄下找到application.yml檔案。在檔案裡修改資料來源hera的資料來源(修改druid.datasource下的配置)即可進行下面的操作。

spring:
    profiles:
        active: @[email protected]	##當前環境 打包時通過-P來指定
http: multipart: max-file-size: 100Mb #允許上傳檔案的最大大小 max-request-size: 100Mb #允許上傳檔案的最大大小 freemarker: allow-request-override: true cache: false check-template-location: true charset: utf-8 content-type: text/html expose-request-attributes
: false expose-session-attributes: false expose-spring-macro-helpers: false suffix: .ftl template-loader-path: classpath:/templates/ request-context-attribute: request druid: datasource: username: root #資料庫使用者名稱 password: XIAOSUDA #資料庫密碼 driver-class-name
: com.mysql.jdbc.Driver #資料庫驅動 url: jdbc:mysql://localhost:3306/hera?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&allowMultiQueries=true initial-size: 5 #初始化連線池數量 min-idle: 1 #最小生存連線數 max-active: 16 #最大連線池數量 max-wait: 5000 #獲取連線時最大等待時間,單位毫秒。配置了maxWait之後,預設啟用公平鎖,併發效率會有所下降,如果需要可以通過配置useUnfairLock屬性為true使用非公平鎖。 time-between-connect-error-millis: 60000 # Destroy執行緒會檢測連線的間隔時間,如果連線空閒時間大於等於minEvictableIdleTimeMillis則關閉物理連線,單位是毫秒 min-evictable-idle-time-millis: 300000 # 連線保持空閒而不被驅逐的最長時間,單位是毫秒 test-while-idle: true #申請連線的時候,如果檢測到連線空閒時間大於timeBetweenEvictionRunsMillis,執行validationQuery檢測連線是否有效 test-on-borrow: true #申請連線時執行validationQuery檢測連線是否有效 test-on-return: false # 歸還連線時執行validationQuery檢測連線是否有效 connection-init-sqls: set names utf8mb4 validation-query: select 1 #用來檢測連線是否有效的sql,要求是一個查詢語句。如果validationQuery為null,testOnBorrow、testOnReturn、testWhileIdle都不會其作用。 validation-query-timeout: 1 #單位:秒,檢測連線是否有效的超時時間。底層呼叫jdbc Statement物件的void setQueryTimeout(int seconds)方法 log-abandoned: true stat-mergeSql: true filters: stat,wall,log4j connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 server: port: 8080 context-path: /hera clean: path: ${server.context-path} #hera全域性配置 hera: defaultWorkerGroup : 1 #預設worker的host組id preemptionMasterGroup : 1 #搶佔master的host組id excludeFile: jar;war maxMemRate : 0.80 #已使用記憶體佔總記憶體的最大比例,預設0.80。當worker記憶體使用達到此值時將不會再向此work發任務 maxCpuLoadPerCore : 1.0 #cpu load per core等於最近1分鐘系統的平均cpu負載÷cpu核心數量,預設1.0。當worker平均負載使用達到此值時將不會再向此work發任務 scanRate : 1000 #任務佇列掃描頻率(毫秒) systemMemUsed : 4000 # 系統佔用記憶體 perTaskUseMem : 500 # 假設每個任務使用記憶體500M requestTimeout: 10000 # 非同步請求超時時間 channelTimeout: 1000 # netty請求超時時間 heartBeat : 3 # 心跳傳遞時間頻率 downloadDir : /opt/logs/spring-boot hdfsLibPath : /hera/hdfs-upload-dir #此處必須是hdfs路徑,所有的上傳附件都會存放在下面路徑上 schedule-group : online maxParallelNum: 2000 #master 允許的最大並行任務 當大於此數值 將會放在阻塞佇列中 connectPort : 9887 #netty通訊的埠 admin: biadmin # admin使用者 taskTimeout: 12 #單個任務執行的最大時間 單位:小時 env: @[email protected] # 傳送配置郵件的傳送者 mail: host: smtp.mxhichina.com protocol: smtp port: 465 user: xxx password: xxx logging: config: classpath:logback-spring.xml path: /opt/logs/spring-boot level: root: INFO org.springframework: ERROR com.dfire.common.mapper: ERROR mybatis: configuration: mapUnderscoreToCamelCase: true #spark 配置 spark : address : jdbc:hive2://localhost:10000 driver : org.apache.hive.jdbc.HiveDriver username : root password : root master : --master yarn driver-memory : --driver-memory 1g driver-cores : --driver-cores 1 executor-memory : -- executor-memory 1g executor-cores : --executor-cores 1 --- ## 開發環境 spring: profiles: dev logging: level: com.dfire.logs.ScheduleLog: ERROR com.dfire.logs.HeartLog: ERROR --- ## 日常環境 通常與開發環境一致 spring: profiles: daily --- ## 預發環境 spring: profiles: pre druid: datasource: url: jdbc:mysql://localhost:3306/lineage?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&allowMultiQueries=true username: root password: root #spark 配置 spark : address : jdbc:hive2://localhost:10000 #spark地址 master : --master yarn driver-memory : --driver-memory 2g driver-cores : --driver-cores 1 executor-memory : -- executor-memory 2g executor-cores : --executor-cores 1 --- ## 正式環境 spring: profiles: publish druid: datasource: url: jdbc:mysql://localhost:3306/lineage?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&allowMultiQueries=true username: root password: root #spark 配置 spark : address : jdbc:hive2://localhost:10000 master : --master yarn driver-memory : --driver-memory 2g driver-cores : --driver-cores 1 executor-memory : -- executor-memory 2g executor-cores : --executor-cores 1

打包部署

當上面的操作完成後,即可使用maven的打包命令進行打包

mvn clean package -Dmaven.test.skip -Pdev

打包後可以進入hera-admin/target目錄下檢視打包後的hera.jar 。此時可以簡單使用java -server -Xms4G -Xmx4G -Xmn2G -jar hera.jar啟動專案,此時即可在瀏覽器中輸入

localhost:8080/hera

即進入登入介面,賬號為hera 密碼為biadmin,點選登入即進入系統。

順便附上我的啟動指令碼

#!/bin/sh

JAVA_OPTS="-server -Xms4G -Xmx4G -Xmn2G -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=5 -XX:+CMSParallelInitialMarkEnabled -XX:CMSInitiatingOccupancyFraction=80  -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:/opt/logs/spring-boot/gc.log -XX:MetaspaceSize=128m -XX:+UseCMSCompactAtFullCollection -XX:MaxMetaspaceSize=128m -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/logs/spring-boot/dump"

log_dir="/opt/logs/spring-boot"
log_file="/opt/logs/spring-boot/all.log"
jar_file="/opt/app/spring-boot/hera.jar"


#日誌資料夾不存在,則建立
if [ ! -d "${log_dir}" ]; then
    echo "建立日誌目錄:${log_dir}"
    mkdir -p "${log_dir}"
    echo "建立日誌目錄完成:${log_dir}"
fi


#父目錄下jar檔案存在
if [ -f "${jar_file}" ]; then
    #啟動jar包 錯誤輸出的error 標準輸出的log
    nohup java $JAVA_OPTS -jar ${jar_file} 1>"${log_file}" 2>"${log_dir}"/error.log &
    echo "啟動完成"
    exit 0
else
    echo -e "\033[31m${jar_file}檔案不存在!\033[0m"
    exit 1
fi

測試

此時就登入上了。下面需要做的是在worker管理這裡新增執行任務的機器IP,然後選擇一個機器組(組的概念:對於不同的worker而言環境可能不同,可能有的用來執行spark任務,有的用來執行hadoop任務,有的只是開發等等。當建立任務的時候根據任務型別選擇一個組,要執行任務的時候會發送到相應的組的機器上執行任務)。
對於執行work的機器ip除錯時可以是master,生產環境建議不要讓master執行任務。如果要執行map-reduce或者spark任務,要保證你的work具有這些叢集的客戶端。
那麼我們就在work管理頁面增加要執行的work地址以及機器組。

在這裡插入圖片描述

此時有30分鐘的緩衝時間,master才會檢測到該work加入。為了測試,此時我們可以通過重啟master來立刻使該work加入執行組(後面會增加一鍵重新整理work資訊)。

重啟後我們可以進入排程中心 ,在搜尋欄裡搜尋1,然後按回車
在這裡插入圖片描述

會發現一個echoTest任務 ,此時我們還不能執行任務,因為我們的所有任務的執行者登入使用者。比如此刻我使用hera登入的,那麼此時一定要保證你的work機器上有hera這個使用者。
否則執行任務會出現sudo: unknown user: hera 異常。
在這裡插入圖片描述

此時可以向我們填寫的work機器上增加hera使用者。

useradd hera

如果是mac系統 那麼可以使用以下命令建立hera使用者

sudo  dscl . -create /Users/hera
sudo  dscl . -create /Users/hera UserShell /bin/bash
sudo  dscl . -create /Users/hera RealName "hera分散式任務排程"
sudo  dscl . -create /Users/hera UniqueID "1024"
sudo  dscl . -create /Users/hera PrimaryGroupID 80
sudo  dscl . -create /Users/hera NFSHomeDirectory /Users/hera

此時點選手動執行->選擇版本->執行。此時該任務會執行,點選右上角的檢視日誌,可以看到任務的執行記錄。

此時如果任務執行失敗,error日誌內容為

sudo: no tty present and no askpass program specified

那麼此時要使你啟動hera專案的使用者具有sudo -u hera的許可權(無須輸入root密碼,即可執行sudo -u hera echo 1 ,具體可以在sudo visudo中配置)。
比如我啟動hera的使用者是wyr
那麼首先在終端執行sudo visudo命令,此時會進入文字編輯
然後在後面追加一行

wyr             ALL=(ALL) NOPASSWD:ALL

如下圖:
在這裡插入圖片描述
這樣就會在切換使用者的時候無須輸入密碼。當然如果你使用的是root使用者啟動,即可跳過這段。
如果一切配置完成,那麼即可看到輸出任務執行成功的日誌。

在這裡插入圖片描述
至此 已經完成了 任務的手動執行。