惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
I
Intezer
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
小众软件
小众软件
T
Threatpost
B
Blog
美团技术团队
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyberwarzone
Cyberwarzone
雷峰网
雷峰网
The GitHub Blog
The GitHub Blog
T
Tenable Blog
A
Arctic Wolf
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 叶小钗
L
Lohrmann on Cybersecurity
博客园 - 三生石上(FineUI控件)
L
LINUX DO - 热门话题
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
S
Security Affairs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
N
News and Events Feed by Topic
Cloudbric
Cloudbric
WordPress大学
WordPress大学
量子位
W
WeLiveSecurity
H
Hacker News: Front Page
Project Zero
Project Zero
S
Security @ Cisco Blogs
Security Latest
Security Latest
Hugging Face - Blog
Hugging Face - Blog
Forbes - Security
Forbes - Security
C
Cybersecurity and Infrastructure Security Agency CISA
人人都是产品经理
人人都是产品经理
U
Unit 42
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog

博客园 - 小得盈满

Hudi 时间旅行与增量查询的区别分析 NATS 的基本安装及使用 Doris 和 StarRocks 性能测试对比 ClickHouse 添加磁盘扩容存储 使用 Docker 部署 Elasticsearch 集群 Qdrant 单机和集群的安装方法 ClickHouse UDF 的基本用法 Kafka 线上性能调优 StarRocks 集群安装 Kafka 的分片和副本机制 Flink 自定义 ClickHouse Table Connector 的简单实现 Redis 性能优化实战 记一次 Go 调用系统命令出现的问题分析 APISIX proxy-cache 插件用法 etcd 历史版本回溯的方法 APISIX 简单的自定义插件开发步骤 Kafka 集群副本数量调整 使用 Docker Compose 安装 APISIX etcd 集群安装 Consul 集群安装
StarRocks 容器镜像构建
小得盈满 · 2024-07-07 · via 博客园 - 小得盈满

StarRocks 官方只提供了单节点运行的镜像,如果是构建可以分布式运行的 StarRocks 的容器镜像,那么基于基础镜像可以有两种选择,分别是:starrocks/artifacts-ubuntu 和 starrocks/allin1-ubuntu,这两个都是基于 Ubuntu 22.04 的基础镜像。其中前者是其中只包含 StarRocks 编译好的安装文件,并不包含任何可运行的环境,需要抠出来放到 Ubuntu 22.04 环境上才可以运行,而且需要安装 JDK 等基础镜像。而后者是编写了具体的启动脚本,可以单机运行所有的服务,作为快速开始使用的,所以里面很多必要的环境都存在,我们可以基于 allin1-ubuntu 做一些修改即可和标准运行方式一样。

artifacts-ubuntu Docker Hub 地址:https://hub.docker.com/r/starrocks/artifacts-ubuntu/tags

allin1-ubuntu Docker Hub 地址:https://hub.docker.com/r/starrocks/allin1-ubuntu/tags

如果基于 artifacts-ubuntu 构建需要我们将镜像里面的安装文件拷贝出来,然后自己编写 Dockerfile 实现,例如:

FROM ubuntu:22.04

RUN sed -i "s@http://.*archive.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list && sed -i "s@http://.*security.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list
RUN apt update && apt install -y openjdk-11-jdk libbinutils

WORKDIR /opt/StarRocks-3.2.3

ADD starrocks-artifacts/ .

CMD ["/bin/bash", "-c", "echo \"StarRocks.\""]

而且这样 FE 和 BE 必须单独启动,也就是启动两个容器。另外这个镜像体积比较大,有 8 个多 GB,原因是 BE 包含了 debuginfo 符号表,这个是方便开发人员 GDB 调试的,正常运行不需要,所以我们最好删除 be/lib/starrocks_be.debuginfo 这个文件。

另外是使用 allin1-ubuntu 镜像,里面使用 Supervisor 来管理 FE 和 BE 等进程,这样比较合理,所以我们可以直接基于这个镜像做一些修改,首先运行镜像并进入容器:

docker run -it starrocks/allin1-ubuntu:3.2.3 /bin/bash

然后我们修改 Supervisor 配置文件 /etc/supervisor/supervisord.conf 在其中调大文件数限制:

[supervisord]
# 添加配置
minfds=1048576

然后查看脚本 entrypoint.sh 默认如下:

#!/bin/bash
# Copyright 2021-present StarRocks, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

get_fe_http_port()
{
    source $SR_HOME/fe/bin/common.sh
    export_env_from_conf $SR_HOME/fe/conf/fe.conf
    echo ${http_port:-8030}
}

update_feproxy_config()
{
    # process fe http_port from a sub shell to avoid env var escalation
    fehttpport=`get_fe_http_port`
    cat $SR_HOME/feproxy/feproxy.conf.template | sed -e "s|{{feproxyhome}}|$SR_HOME/feproxy|g" -e "s|{{fewebport}}|${fehttpport}|g" > $SR_HOME/feproxy/feproxy.conf
}

setup_priority_networks()
{
    echo "priority_networks = 127.0.0.1/32" >> $SR_HOME/fe/conf/fe.conf
    echo "priority_networks = 127.0.0.1/32" >> $SR_HOME/be/conf/be.conf
}

# print banner
if [ -f $SR_HOME/../banner.txt ] ; then
    cat $SR_HOME/../banner.txt
fi

# setup log directories
mkdir -p $SR_HOME/{supervisor,fe,be,apache_hdfs_broker,feproxy}/log

update_feproxy_config
# use 127.0.0.1 for all the services, include fe/be/broker
setup_priority_networks

# setup supervisor and start
SUPERVISORD_HOME=$SR_HOME/supervisor
# allow supervisorctl to find the correct supervisord.conf
ln -sfT $SUPERVISORD_HOME/supervisord.conf /etc/supervisord.conf

cd $SUPERVISORD_HOME
exec supervisord -n -c $SUPERVISORD_HOME/supervisord.conf

这其中执行了 setup_priority_networks 函数,会将配置追加到 fe.confbe.conf ,但是我们需要将这个配置文件拷贝出来再映射进去,所以不需要每次都执行,我们将这行函数注释掉。

然后我们把容器内的配置文件拷贝到容器外面:

docker cp dddddbc9232a:/data/deploy/starrocks/fe/conf/fe.conf .
docker cp dddddbc9232a:/data/deploy/starrocks/be/conf/be.conf .

最后我们再编辑 /data/deploy/starrocks/supervisor/supervisord.conf,默认内容如下:

[unix_http_server]
file=%(ENV_SR_HOME)s/supervisor/supervisor.sock


[supervisord]
logfile=%(ENV_SR_HOME)s/supervisor/log/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=%(ENV_SR_HOME)s/supervisor/supervisord.pid
user=root
nodaemon=true


[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface


[supervisorctl]
serverurl=unix://%(ENV_SR_HOME)s/supervisor/supervisor.sock


[program:feservice]
command=%(ENV_SR_HOME)s/fe/bin/start_fe.sh
numprocs=1
directory=%(ENV_SR_HOME)s/fe
autostart=true
autorestart=true
startsecs=5
startretries=3
stopwaitsecs=15
stopasgroup=true
killasgroup=true
redirect_stderr=true
stdout_logfile=%(ENV_SR_HOME)s/fe/log/fe.out
stdout_logfile_maxbytes=200MB
stdout_logfile_backups=20


[program:beservice]
command=%(ENV_SR_HOME)s/be/bin/start_be.sh
numprocs=1
directory=%(ENV_SR_HOME)s/be
autostart=true
autorestart=true
startsecs=5
startretries=3
# do force kill before BE is good with graceful shutdown
stopsignal=KILL
stopwaitsecs=15
stopasgroup=true
killasgroup=true
redirect_stderr=true
stdout_logfile=%(ENV_SR_HOME)s/be/log/be.out
stdout_logfile_maxbytes=200MB
stdout_logfile_backups=20


[program:broker]
command=%(ENV_SR_HOME)s/apache_hdfs_broker/bin/start_broker.sh
numprocs=1
directory=%(ENV_SR_HOME)s/apache_hdfs_broker
autostart=true
autorestart=true
startsecs=5
startretries=3
stopwaitsecs=15
stopasgroup=true
killasgroup=true
redirect_stderr=true
stdout_logfile=%(ENV_SR_HOME)s/apache_hdfs_broker/log/apache_hdfs_broker.out
stdout_logfile_maxbytes=200MB
stdout_logfile_backups=20


[program:feproxy]
command=nginx -g "daemon off;" -c %(ENV_SR_HOME)s/feproxy/feproxy.conf
numprocs=1
directory=%(ENV_SR_HOME)s/feproxy
autostart=true
autorestart=true
startsecs=5
startretries=3
stopwaitsecs=15
redirect_stderr=true
stdout_logfile=%(ENV_SR_HOME)s/feproxy/log/feproxy.out
stdout_logfile_maxbytes=200MB
stdout_logfile_backups=20


[program:director]
command=%(ENV_SR_HOME)s/director/run.sh
numprocs=1
directory=%(ENV_SR_HOME)s/director
autostart=true
autorestart=true
startsecs=5
startretries=3
stopwaitsecs=15
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0

其中 brokerfeproxy 以及 director 的配置我们用不到,如果开启 director 由于集群配置了密码等还会导致报错重启,所以这个没必要开启,因此将这几个块直接删除掉即可,删除后保存配置文件。

最后我们清理历史命令:

history -c
# 退出容器
exit

然后我们将容器保存为镜像:

docker commit -m "StarRocks 3.2.3 from allin1-ubuntu:3.2.3" dddddbc9232a starrocks:3.2.3

然后我们使用 Docker Compose 管理 StarRocks 进程,创建 docker-compose.yml 配置如下:

version: '3'
services:
  starrocks:
    image: starrocks:3.2.3
    container_name: starrocks-container
    command: ./entrypoint.sh
    restart: always
    network_mode: "host"
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - ./conf/fe.conf:/data/deploy/starrocks/fe/conf/fe.conf
      - ./conf/be.conf:/data/deploy/starrocks/be/conf/be.conf
      - /var/log/starrocks/fe:/data/deploy/starrocks/fe/log
      - /var/log/starrocks/be:/data/deploy/starrocks/be/log
      - /data/starrocks/meta:/data/deploy/starrocks/fe/meta
      - /data/starrocks/storage:/data/deploy/starrocks/be/storage

为了保证性能我们直接使用主机网络模式,这样我们只需要正常配置我们外部的配置文件即可,所有的端口都是直接在主机上监听,所以不要忘记修改 priority_networks 配置。另外我们分别映射了 StarRocks 的 FE 和 BE 日志目录,这个也无需修改内部的配置。最后就是数据目录,我们将外部自定义的数据目录映射到了内部默认位置,所以配置文件中的数据目录也无需修改,只需要修改我们映射的外部目录即可。但是我们要加上 command 指定容器启动的命令,因为我们后面进入容器的时候用了 /bin/bash 这样会将原有镜像默认的 CMD 覆盖掉,当我们提交镜像后默认就变成容器初次启动时的命令 /bin/bash 了,这个时候我们也可以用 entrypoint.sh 启动一次镜像再提交,或者是初次启动容器时用默认命令,我们再用 docker exec 进入容器这样也不会破坏原有镜像默认的入口。

另外注意如果是从之前手动部署的 StarRocks 集群上升级成容器化集群,那么需要设置容器的主机名,如果是 IP 地址访问那么需要将主机名设置为 IP:

version: '3'
services:
  starrocks:
    hostname: x.x.x.x

否则如果启用了主机名访问,那么需要设置为本机实际的主机名并且需要映射主机的 hosts 文件:

version: '3'
services:
  starrocks:
    hostname: host1

默认主机上的 /etc/hosts会自动映射进去可以无需其他配置。

经过上面的调整这样才可以正常启动,否则会报错:

Detect FE service hostname mismatch, FE service won't start.
This is probably caused by persisted fe/meta from outside container, but the container's hostname is not fixed. If running with docker engine, use '-h <hostname>' to assign a fixed hostname and restart.

因为原来的集群 meta 信息已经保存了原来的主机名,启动的时候 FE 会进行校验,不符合将会退出。如果是新部署集群则没有这个问题。