搭建 StarRocks 分析集群

适用场景

需要实时数仓、明细/聚合查询和高并发报表。StarRocks 兼容 MySQL 协议,支持多种表模型、物化视图和湖仓分析。

前置条件

步骤

  1. 使用 Operator 安装:
kubectl apply -f https://raw.githubusercontent.com/StarRocks/starrocks-kubernetes-operator/main/deploy/starrocks.com_starrocksclusters.yaml
kubectl apply -f https://raw.githubusercontent.com/StarRocks/starrocks-kubernetes-operator/main/deploy/operator.yaml
  1. 创建 StarRocksCluster:
kubectl apply -f - <<'EOF'
apiVersion: starrocks.com/v1
kind: StarRocksCluster
metadata:
  name: starrocks
  namespace: starrocks
spec:
  starRocksFeSpec:
    image: starrocks/fe-ubuntu:3.3.0
    replicas: 3
    requests: {cpu: "4", memory: 16Gi}
  starRocksBeSpec:
    image: starrocks/be-ubuntu:3.3.0
    replicas: 3
    requests: {cpu: "8", memory: 32Gi}
EOF
kubectl -n starrocks get pods
  1. 连接并建表:
mysql -h starrocks-fe-service -P 9030 -u root
CREATE DATABASE demo;
USE demo;
CREATE TABLE events (
  dt DATE,
  user_id BIGINT,
  event_type VARCHAR(32),
  amount DECIMAL(10,2)
)
DUPLICATE KEY(dt, user_id)
PARTITION BY RANGE(dt) (
  START ("2026-10-01") END ("2026-11-01") EVERY (INTERVAL 1 DAY)
)
DISTRIBUTED BY HASH(user_id) BUCKETS 8
PROPERTIES ("replication_num" = "3");
  1. Stream Load 导入:
curl --location-trusted -u root: \
  -H 'format: json' -H 'strip_outer_array: true' \
  -T events.json \
  http://starrocks-fe-service:8030/api/demo/events/_stream_load
  1. 创建物化视图:
CREATE MATERIALIZED VIEW mv_daily AS
SELECT dt, event_type, COUNT(*) AS cnt, SUM(amount) AS amt
FROM events GROUP BY dt, event_type;

验证

回滚

常见坑

相关命令