当前位置: 首页 > ds >正文

一键管理 StarRocks:简化集群的启动、停止与状态查看

一键管理 StarRocks:简化集群的启动、停止与状态查看

在日常运维中, StarRocks 集群的启动、停止与状态查看 一直是一件颇为繁琐的事情.

想象一下,如果双十一前夕,StarRocks 集群在做例行压测。凌晨 3 点,监控告警:CPU 飙高,查询超时。值班同学第一反应是「重启试试」。

  • 5 个 FE、8 个 BE,分布在 8 台服务器;

录到每台服务器,分别执行:

/fe/bin/start_fe.sh --daemon
/be/bin/start_be.sh --daemon
  • 逐台 SSH,输入密码,执行 stop → start;
  • 第 4 台机器输错路径,进程没起来,导致元数据不一致;
  • 回滚、定位、修复,一共要花多少时间 。 更不要说跟多的 服务器。

这种逐台操作的方式,不仅耗时,还容易出错。 如果能一键启动、停止集群,并随时查看节点状态,效率将大大提升。

今天我来分享一个 一键管理 StarRocks 的linux 的 shell脚本 ,实现以下功能:
一键启动 / 停止集群
统一查看 FE / BE 节点状态
动态配置节点,方便扩展
优点 代码归一性


文章目录

  • 一键管理 StarRocks:简化集群的启动、停止与状态查看
    • 代码
    • 依赖关系
    • 启动 Start the Cluster:
    • 停止 Stop the Cluster:
    • 检查 Check the Cluster Status:
    • 总结


具体代码已经 更新到 starrocks issue #615415 ,但是能不能被采纳就不知道,希望能采纳。
🙏 🙏 🙏 🙏 🙏

在这里插入图片描述

在这里插入图片描述

代码


#!/bin/bash# =================================================================
# StarRocks Cluster Management Script
#
# Author: tomxjc305
# Date: 2025-08-02
# Description: This script automates the start, stop, and status
#              check operations for a StarRocks cluster with dynamic configuration.
# =================================================================# --- Configuration Section ---# Define the FE and BE nodes dynamically in the environment variables or a configuration file.
# Example:
# export STARROCKS_FE_NODES="192.168.5.128 "
# export STARROCKS_BE_NODES="192.168.5.128 192.168.5.129 192.168.5.130"
# These can be configured by exporting environment variables in your shell or you can modify this section
# for more dynamic reading, such as from a configuration file.# --- Configuration from environment variables ---
STARROCKS_FE_NODES=("192.168.5.128")  # List of Frontend (FE) nodes
STARROCKS_BE_NODES=("192.168.5.130" "192.168.5.129" "192.168.5.128")  # List of Backend (BE) nodes# MySQL(StarRocks) connection settings for the FE node
MASTER_FE_HOST="192.168.5.128"
MYSQL_QUERY_PORT="9030"# Installation path of StarRocks on all nodes
STARROCKS_FE_DIR="/data/starrocks/fe"
STARROCKS_BE_DIR="/data/starrocks/be"# MySQL(StarRocks) client connection info
MYSQL_USER="root"
MYSQL_PASSWORD="123456"# --- Main Logic ---# Get the operation parameter (start, stop, status) from the user
ACTION=$1# Check if the user has provided an operation parameter
if [[ -z "$ACTION" ]]; thenecho "Error: Operation not specified."echo "Usage: $0 {start|stop|status}"exit 1
fi# Function: Start component
# Parameter 1: Host IP
# Parameter 2: Component type (fe/be)
# Parameter 3: Host password
start_component() {local host=$1local role=$2local password=$3local cmd=""echo "--- [Start] Connecting to $host ($role)... ---"if [[ "$role" == "fe" ]]; thencmd="cd $STARROCKS_FE_DIR && ./bin/start_fe.sh --daemon"elif [[ "$role" == "be" ]]; thencmd="cd $STARROCKS_BE_DIR && ./bin/start_be.sh --daemon"elseecho "Warning: Unknown component type '$role' found on $host. Skipping."returnfiecho "Executing command: $cmd"sshpass -p "$password" ssh -o StrictHostKeyChecking=no root@"$host" "$cmd"if [[ $? -eq 0 ]]; thenecho "Successfully started $role on $host."elseecho "Error: Failed to start $role on $host."fi
}# Function: Stop component
# Parameter 1: Host IP
# Parameter 2: Component type (fe/be)
# Parameter 3: Host password
stop_component() {local host=$1local role=$2local password=$3local cmd=""echo "--- [Stop] Connecting to $host ($role)... ---"if [[ "$role" == "fe" ]]; thencmd="cd $STARROCKS_FE_DIR && ./bin/stop_fe.sh"elif [[ "$role" == "be" ]]; thencmd="cd $STARROCKS_BE_DIR && ./bin/stop_be.sh"elseecho "Warning: Unknown component type '$role' found on $host. Skipping."returnfiecho "Executing command: $cmd"sshpass -p "$password" ssh -o StrictHostKeyChecking=no root@"$host" "$cmd"if [[ $? -eq 0 ]]; thenecho "Successfully stopped $role on $host."elseecho "Error: Failed to stop $role on $host."fi
}# Function: Check cluster status
check_cluster_status() {echo "--- [Status Check] Connecting to master FE node ($MASTER_FE_HOST) to query cluster status... ---"echo ""echo ">>> Querying all Frontend nodes:"# Build MySQL command to query FE statuslocal fe_status_cmd="mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -h $MASTER_FE_HOST -P $MYSQL_QUERY_PORT -e 'SHOW FRONTENDS;'"eval $fe_status_cmdif [[ $? -ne 0 ]]; thenecho "Error: Failed to query FE status. Please check if the master FE node is running or if the network is reachable."fiecho ""echo ">>> Querying all Backend nodes:"# Build MySQL command to query BE statuslocal be_status_cmd="mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -h $MASTER_FE_HOST -P $MYSQL_QUERY_PORT -e 'SHOW BACKENDS;'"eval $be_status_cmdif [[ $? -ne 0 ]]; thenecho "Error: Failed to query BE status."fiecho ""
}# --- Main Execution Flow ---case "$ACTION" instart)echo "========== Starting StarRocks Cluster =========="for host in "${STARROCKS_FE_NODES[@]}"; dostart_component "$host" "fe" "$MYSQL_PASSWORD"donefor host in "${STARROCKS_BE_NODES[@]}"; dostart_component "$host" "be" "$MYSQL_PASSWORD"doneecho "========== Cluster start operation completed ==========";;stop)echo "========== Stopping StarRocks Cluster =========="for host in "${STARROCKS_BE_NODES[@]}"; dostop_component "$host" "be" "$MYSQL_PASSWORD"donefor host in "${STARROCKS_FE_NODES[@]}"; dostop_component "$host" "fe" "$MYSQL_PASSWORD"doneecho "========== Cluster stop operation completed ==========";;status)echo "========== Checking StarRocks Cluster Status =========="check_cluster_statusecho "========== Cluster status check completed ==========";;*)echo "Error: Invalid operation '$ACTION'."echo "Usage: $0 {start|stop|status}"exit 1;;
esacexit 0

依赖关系

下载sshpass 并编译

wget https://sourceforge.net/projects/sshpass/files/sshpass/1.09/sshpass-1.09.tar.gz
tar -xzf sshpass-1.09.tar.gz
cd sshpass-1.09
./configure && make && sudo make install

执行步骤如下:

启动 Start the Cluster:

./starrocks_cluster_manager.sh start

在这里插入图片描述

停止 Stop the Cluster:

./starrocks_cluster_manager.sh stop

在这里插入图片描述

检查 Check the Cluster Status:

./starrocks_cluster_manager.sh status

在这里插入图片描述

总结

自我感觉还是不够通用化,应该有很多提升的空间。但目前我在维护中就可以一建启动了。

有了这个脚本, StarRocks 集群的日常运维可以从繁琐的手动登录,变成一条命令搞定 ,大幅提升了运维效率。如果你有更大规模的集群,进一步提速。

http://www.xdnf.cn/news/18201.html

相关文章:

  • JAVA后端开发——Token自动续期机制的必要性
  • 库制作与原理(下)
  • RabbitMQ面试精讲 Day 24:消费者限流与批量处理
  • Linux中iSCSI存储配置与管理指南
  • Leetcode 15 java
  • 【LeetCode 热题 100】118. 杨辉三角
  • 使用Github Page发布网站
  • Compose笔记(四十六)--Popup
  • 廖雪峰-java教程-Part01
  • RK3588开发板Ubuntu系统烧录
  • 如何利用gemini-cli快速了解一个项目以及学习新的组件?
  • GitHub Copilot:AI编程助手的架构演进与真实世界影响
  • 【102页PPT】新一代数字化转型信息化总体规划方案(附下载方式)
  • 第七十九:AI的“急诊科医生”:模型失效(Loss Explode)的排查技巧——从“炸弹”到“稳定”的训练之路!
  • 为什么神经网络在长时间训练过程中会存在稠密特征图退化的问题
  • AI+预测3D新模型百十个定位预测+胆码预测+去和尾2025年8月17日第163弹
  • 内网穿透系列十一:NPS 是一款轻量级、高性能、功能强大的内网穿透工具,自带Web管理端,支持Docker快速部署
  • Win10快速安装.NET3.5
  • Web全栈项目中健康检查API的作用(现代云原生应用标准实践)(health check、healthcheck、livenessProbe、健康探针)
  • 博士招生 | 香港大学 机器增强认知实验室 招收博士生/实习生/访问学生
  • File 类的用法和 InputStream, OutputStream 的用法
  • Python列表与元组:数据存储的艺术
  • 车载诊断架构 --- 怎么解决对已量产ECU增加具体DTC的快照信息?
  • python---模块
  • CentOS7安装使用FTP服务
  • java内存模型:
  • 新字符设备驱动实验
  • DBngin:告别数据库多版本环境管理的烦恼
  • 后台管理系统-4-vue3之pinia实现导航栏按钮控制左侧菜单栏的伸缩
  • 如何解决C盘存储空间被占的问题,请看本文