0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Grafana&Trino&Zeppelinを使用してログ解析基盤から情報を可視化する。

0
Last updated at Posted at 2026-03-25

はじめに

Trino&Grafana&Zeppelinによる可視化も実施してみました。

以下の構成の基盤を構築していること。

全体構成(今回作るもの)

  • HDFS Iceberg:既存流用
  • Trino:SQLエンジン
  • Grafana , Zeppelin:可視化

Trino/Grafanaを新規ホストとして構築します。

0. 準備

ubuntu24.04で実施すること。

以下の設定で新規ホストを構築すること。

スペックはCPU:2コア、メモリ4GBにすること。

以下のファイルを他のホストからコピーすること。

/etc/hadoop/conf/core-site.xml
/etc/hadoop/conf/hdfs-site.xml
sudo mkdir -p /etc/hadoop/conf
ファイルのコピー実施
sudo chmod 644 /etc/hadoop/conf/*.xml

1. Java

sudo apt-get update
sudo apt-get install -y wget gnupg
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | \
  sudo gpg --dearmor -o /etc/apt/keyrings/adoptium.gpg
echo "deb [signed-by=/etc/apt/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/adoptium.list
sudo apt-get update
sudo apt-get install -y temurin-24-jdk
java -version

2. Trino インストール

sudo useradd --system --home /opt/trino --shell /usr/sbin/nologin trino || true
export TRINO_VER=476
cd /tmp
wget https://repo1.maven.org/maven2/io/trino/trino-server/${TRINO_VER}/trino-server-${TRINO_VER}.tar.gz
sudo mkdir -p /opt/trino
sudo tar -xzf trino-server-${TRINO_VER}.tar.gz -C /opt/trino --strip-components=1
sudo mkdir -p /var/lib/trino /var/log/trino /opt/trino/etc/catalog
sudo chown -R trino:trino /opt/trino /var/lib/trino /var/log/trino

3. Trino 設定

node.properties

sudo tee /opt/trino/etc/node.properties >/dev/null <<EOF
node.environment=production
node.id=trino1
node.data-dir=/var/lib/trino
EOF

jvm.config

sudo tee /opt/trino/etc/jvm.config >/dev/null <<EOF
-server
-Xmx3G
-XX:InitialRAMPercentage=80
-XX:MaxRAMPercentage=80
-XX:+UseG1GC
-XX:+ExitOnOutOfMemoryError
-Dfile.encoding=UTF-8
EOF

config.properties

zeppelinと同じホストにtrinoを導入する際は"8080"を"8085"などに変更すること。

sudo tee /opt/trino/etc/config.properties >/dev/null <<EOF
coordinator=true
node-scheduler.include-coordinator=true

http-server.http.port=8080
discovery.uri=http://trino1:8080

query.max-memory=2GB
query.max-memory-per-node=1GB
memory.heap-headroom-per-node=1GB
EOF

log.properties

echo "io.trino=INFO" | sudo tee /opt/trino/etc/log.properties

4. Hive カタログ(curated用)

sudo tee /opt/trino/etc/catalog/hive.properties >/dev/null <<EOF
connector.name=hive
hive.metastore.uri=thrift://hive1:9083,thrift://hive2:9083

fs.hadoop.enabled=true
hive.config.resources=/etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml

hive.security=allow-all
hive.non-managed-table-writes-enabled=true
EOF

5. Iceberg カタログ

sudo tee /opt/trino/etc/catalog/iceberg.properties >/dev/null <<EOF
connector.name=iceberg
iceberg.catalog.type=hive_metastore

hive.metastore.uri=thrift://hive1:9083,thrift://hive2:9083

fs.hadoop.enabled=true
hive.config.resources=/etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml

iceberg.file-format=PARQUET
EOF

6. systemd 化

sudo tee /etc/systemd/system/trino.service >/dev/null <<'EOF'
[Unit]
Description=Trino
After=network.target

[Service]
Type=simple
User=trino
Group=trino
ExecStart=/opt/trino/bin/launcher run
ExecStop=/opt/trino/bin/launcher stop
Restart=always
LimitNOFILE=131072
Environment="JAVA_HOME=/usr/lib/jvm/temurin-24-jdk-amd64"
Environment="PATH=/usr/lib/jvm/temurin-24-jdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now trino

7. 動作確認

trino応答確認

curl http://localhost:8080/v1/info

SQL送付コマンド導入

cd /tmp
wget https://repo1.maven.org/maven2/io/trino/trino-cli/476/trino-cli-476-executable.jar -O trino
chmod +x trino
sudo install -m 0755 /tmp/trino /usr/local/bin/trino
which trino
trino --version
cd

trinoからSQL参照できることを確認する。

trino --server http://localhost:8080 --execute "SHOW CATALOGS;"

trino --server http://localhost:8080 \
  --execute "SHOW TABLES FROM hive.logs;"

trino --server http://localhost:8080 \
  --execute "SHOW TABLES FROM iceberg.logs;"

8. Grafana インストール

既存Grafanaホストを使用する場合本手順はスキップしてもよい。

sudo apt-get install -y apt-transport-https wget gnupg

sudo mkdir -p /etc/apt/keyrings

wget -q -O - https://apt.grafana.com/gpg.key | \
  sudo gpg --dearmor -o /etc/apt/keyrings/grafana.gpg

echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | \
  sudo tee /etc/apt/sources.list.d/grafana.list

sudo apt-get update
sudo apt-get install -y grafana

9. Trino plugin

Grafanaホストで実施する

sudo grafana-cli plugins install trino-datasource
sudo systemctl enable --now grafana-server
sudo systemctl restart grafana-server

10. Grafana 初期設定

ブラウザ:

http://<サーバIP>:3000
user: admin
pass: admin
→変更推奨

11. データソース設定

Grafana → Connections → Data sources → Trino

設定:

URL: http://trino1:8080

Save & Test

12. ダッシュボード作成(そのまま使えるSQL)

以下のクエリを入れてみていくつかでデータが出ればよい。

  • syslog 時系列
SELECT
  CAST(date_trunc('hour', ts) AS timestamp) AS time,
  COUNT(*) AS syslogcnt
FROM iceberg.logs.syslog_iceberg
WHERE dt BETWEEN CAST(from_iso8601_timestamp('${__from:date:iso}') AS date)
           AND CAST(from_iso8601_timestamp('${__to:date:iso}') AS date)
  AND ts BETWEEN from_iso8601_timestamp('${__from:date:iso}')
             AND from_iso8601_timestamp('${__to:date:iso}')
GROUP BY 1
ORDER BY 1
  • authlog 時系列
SELECT
  CAST(date_trunc('hour', ts) AS timestamp) AS time,
  COUNT(*) AS authlogcnt
FROM iceberg.logs.authlog_iceberg
WHERE dt BETWEEN CAST(from_iso8601_timestamp('${__from:date:iso}') AS date)
           AND CAST(from_iso8601_timestamp('${__to:date:iso}') AS date)
  AND ts BETWEEN from_iso8601_timestamp('${__from:date:iso}')
             AND from_iso8601_timestamp('${__to:date:iso}')
GROUP BY 1
ORDER BY 1

13. Zeppelinからtrinoを介してデータ参照

Zeppelin1で行う。

Trino JDBC Driver を配置

cd /tmp
wget https://repo1.maven.org/maven2/io/trino/trino-jdbc/476/trino-jdbc-476.jar
sudo mkdir -p /opt/zeppelin/lib
sudo mv trino-jdbc-476.jar /opt/zeppelin/lib/
sudo chown zeppelin:zeppelin /opt/zeppelin/lib/trino-jdbc-476.jar

Zeppelin の Interpreter を作成

Zeppelin の Web UI から設定します。

  • 操作

Interpreter → Create New

  • 設定値

Name
trino

Interpreter Group
jdbc

  • プロパティ設定値
default.driver = io.trino.jdbc.TrinoDriver
default.url = jdbc:trino://<Trinoホスト>:8080/iceberg/logs
default.user = hive

DependenciesのArtifactに以下の設定を追記する。
io.trino:trino-jdbc:476

Save

Zeppelinの再起動を行う。

sudo systemctl restart zeppelin

Interprontのtrinoを検索し、右側のマークが緑になること。

Zeppelin確認

Zeppelinで以下のSQLを入力してテーブル一覧参照できること。

%trino
SHOW TABLES;

Zeppelinで以下のSQLを入力してCuratedデータとicebergテーブルの前日件数の比較が行えること。

%trino
-- 0. curated vs iceberg trino収集差分(差分が出る場合要調査)

-- テーブル名のiceberg.logs.は省略してもよい。(インタプリタのdefault.urlで指定しているため。)

SELECT 'curated' AS src, count(*) AS cnt
FROM hive.logs.syslog_curated
WHERE dt = CAST(current_date - INTERVAL '1' day AS varchar)

UNION ALL

SELECT 'iceberg' AS src, count(*) AS cnt
FROM iceberg.logs.syslog_iceberg
WHERE dt = current_date - INTERVAL '1' day;

SELECT 'curated' AS src, count(*) AS cnt
FROM hive.authlogs.authlog_curated
WHERE dt = CAST(current_date - INTERVAL '1' day AS varchar)

UNION ALL

SELECT 'iceberg' AS src, count(*) AS cnt
FROM iceberg.logs.authlog_iceberg
WHERE dt = current_date - INTERVAL '1' day;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?