Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Druid 極速體驗 #1

Closed
nepaul opened this issue Mar 22, 2016 · 0 comments
Closed

Druid 極速體驗 #1

nepaul opened this issue Mar 22, 2016 · 0 comments

Comments

@nepaul
Copy link
Owner

nepaul commented Mar 22, 2016

該文基於 Druid 0.8.3.

該集羣的 relatime node 採用 indexing server 的方式,即 overload 和 middlerManger 的組合。Deep Storage 用 Hadoop(這裏假設已經有可用 hadoop 的集羣), 而數據灌入採用 traniquilityCore 模塊,並未用 kafaka 等消息隊列。
查詢用了 pydruid,非常簡單方便。

机器

結點都是單臺機器,沒有作 高可用性。

操作系統:CentOS release 6.7 (Final)

机器配置 数量 结点名
8核 8GB 100GB 1 Overload
16核 32GB 100GB 1 MiddlerManager
16核 64GB 200GB 1 Histrical
16核 32GB 100GB 1 Borker
8核 16GB 200GB 1 Coordinator & metadata store(mysql) & zookeeper

安裝

对所有结点机器 更新系统: yum -y upgrade

mysql 安裝和配置:

yun -y install mysql-server
mysql -u root
CREATE DATABASE druid DEFAULT CHARACTER SET utf8;
GRANT ALL ON druid.* TO 'druid'@'%' IDENTIFIED BY 'diurd'; 

zookeeper 安裝和配置:

curl http://www.gtlib.gatech.edu/pub/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz -o zookeeper-3.4.6.tar.gz
tar xzf zookeeper-3.4.6.tar.gz
cd zookeeper-3.4.6
cp conf/zoo_sample.cfg conf/zoo.cfg
./bin/zkServer.sh start
cd ..

下載 druid 安裝包,并解压缩:

wget http://static.druid.io/artifacts/releases/druid-0.8.3-bin.tar.gz
tar -zxvf druid-0.8.3-bin.tar.gz

進入根目錄:cd druid-0.8.3

更改 config 目錄下的各個配置文件,配置的詳細參數可以參看 官方文檔, 這裏是本集羣的一套配置文件

根據上一部配置文件中的信息,在響應節點機器上創建 druid 所需目錄(這一步很關鍵,若是遺漏,後續在啓動運行中會出現一些莫名的問題很折騰人)

  • MiddleManager Node: mkdir -p /druid/prod/discovery
  • Histrical Node: mkdir -p /tmp/druid/indexCache

編寫各個節點的啓動腳本,這裏有本集羣的所有結點啓動腳本

將包分發到各個節點,並啓動相應腳本: nohup sh ./start_node.sh &

數據灌入( Data Ingestion)

Data Ingestion 有很多方式,這裏直接通過官方提供的 tranquility 來實現。 Tranquility 提供了多個模塊,包括 core, server, Samza, Spark, Storm, Kafka, Flink。開發者可以根據自己的架構選擇合適的模塊,支持 Java 和 Scala。這也是官方非常推薦的方式。

這裏選用 Core 模塊,最新版本已經到了 0.7.4 。官方也給出了最新版本的 Java Demo,只是一個 Java 代碼和 配置文件,簡單構建了一個工程,沒跑通。

這裏用的 Tranquility Core 版本是 0.7.3。寫了一個簡單的 Java 版本的 Demo 作爲演示。工程用 Maven 構建,可以直接從 這裏 下載整個工程,在代碼裏修改好一些鏈接的基礎配置,直接可以運行代碼,或者生成 ingestion.jar 並運行 java -cp ./data-ingestion.jar com.ingestion.Ingestion

數據查詢

數據查詢直接用官方提供的 pydruid,不會有太多問題。
這裏直接上 Demo.

關鍵注意點

  1. 集羣時間同步,誤差儘量在 1s 內 (雖然官方文檔未指定,但最好能做到以避免不必要的麻煩)
  2. 整個集羣統一用 utc 時間
  3. 在相應機器上一定要記得 創建druid集羣 配置文件 中指定的響應目錄
  4. Data Ingestion 時常會遇到類似 「Message Drop」的問題,主要原因有兩個
    • Event 過了指定的有效時間,「Tranquility drops events outside the windowPeriod on the client side」。解決方案:丟棄這部分數據就 OK 了。
    • Historical 結點會把數據從 deep storage 拉到本地磁盤並且緩存到內存中,當緩存被耗盡會導致 index task 一直無法完成。那麼 MiddleManager 沒有多餘的進程去執行新的 task。解決方案:可以在 Coordinator(coordinator-node-host:port) 頁面配置中設定加載規則,例如只加載最近 30 天的數據規則可以是這樣#rule1: load 30PD #rule2: drop forever

最後

本文提到的 集羣配置、啓動腳本、Data Ingestion、查詢 等都已經放到了 github,直接 clone 到本地使用: git clone https://github.com/nepaul/DruidDemos.git

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant