多版本管理解读-配置级alternatives
bigtop 平台实现多版本管理,不仅限于二进制和运行环境,还依赖于配置文件的多版本隔离与灵活切换。这背后核心依赖于 Linux 系统的 alternatives 工具。本文将分为两大部分详细解读其原理与大数据工程落地。
# 一、alternatives 工具原理简介
# 1. 核心作用
alternatives 是 Linux 系统用于同一功能多套实现的管理工具,典型如 JDK、Python 多版本,或命令、配置文件的多版本切换。
- 通过软链接注册和切换,实现无需手动重命名/移动。
- 支持自动/手动模式,方便运维自动化。
# 2. 常用 alternatives 操作
操作 | 命令示例 | 说明 |
---|---|---|
注册新实现 | alternatives --install /etc/redis/conf redis-conf /path/conf 30 | 注册新 conf |
查看当前状态 | alternatives --display redis-conf | 查看当前软链和候选实现 |
手动切换实现 | alternatives --set redis-conf /usr/bigtop/3.2.1/redis/conf | 手动切换到指定 conf |
移除实现 | alternatives --remove redis-conf /usr/bigtop/3.2.0/redis/conf | 移除指定实现 |
提示
alternatives --display {name}
可以直观查看当前 conf 软链指向、所有注册的实现路径及优先级。
# 二、bigtop 集成 alternatives 的工程实现
bigtop 在组件安装阶段自动植入 alternatives 注册,让运维几乎“零感知”即可实现配置多版本治理。其机制与实际脚本如下:
# 1. 自动植入:rpm 安装阶段批量注册
安装大数据组件的 rpm 包时,会在 %post
阶段自动完成 conf 注册。
%post
if [ "$1" = 1 ]; then
mkdir -p %{np_etc_component_name}
%{alternatives_cmd} --install %{np_etc_component_name}/conf %{component_name}-conf %{etc_component}/conf.empty 30
mkdir -p %{np_var_log_component_name}
mkdir -p /var/lib/%{component_name}
chown -R %{user_name}:%{group_name} /var/lib/%{component_name}
fi
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
笔记
- /etc/{component}/conf 会自动变成软链接(由 alternatives 托管)
- 新版本/老版本注册后,conf 都能多版本共存
# 2. 手动切换/查询配置版本
手动管理时(如升级或回滚),只需用 alternatives 命令:
查询当前 conf 指向(如 redis):
alternatives --display redis-conf
1输出示例:
redis-conf - status is auto. link currently points to /usr/bigtop/3.2.0/redis/conf /usr/bigtop/3.2.0/redis/conf - priority 30 /usr/bigtop/3.2.1/redis/conf - priority 20 Current `best' version is /usr/bigtop/3.2.0/redis/conf.
1
2
3
4
5手动切换 conf 版本:
alternatives --set redis-conf /usr/bigtop/3.2.1/redis/conf
1验证软链:
ls -l /etc/redis/conf
1
# 3. Zookeeper 实战案例【官方】
Zookeeper 配置切换同样用 alternatives 机制。实际查询:
alternatives --display zookeeper-conf
1
输出:
zookeeper-conf - status is auto.
link currently points to /usr/bigtop/3.2.0/etc/zookeeper/conf.dist
/usr/bigtop/3.2.0/etc/zookeeper/conf.dist - priority 30
Current `best' version is /usr/bigtop/3.2.0/etc/zookeeper/conf.dist.
1
2
3
4
2
3
4
提示
/etc/zookeeper/conf
当前就指向了 3.2.0 版本下的 conf.dist 目录。
# 三、Ambari 集成场景下的自动生效
在使用 Ambari 集群管理时,组件配置切换、激活一般全部由 Ambari 自动处理:
- 部署、重启、升级、回滚都会自动调整 alternatives
- 运维人员无需手动操作 alternatives,所有组件 conf 会自动保持与实际激活版本一致
- 配合 UI,管理更直观、无感知
笔记
只要用 Ambari 接管,alternatives 的 conf 切换全部自动完成,完全无需手动干预。
- 01
- bigtop-select 打包缺 compat 报错修复 deb07-16
- 02
- bigtop-select 打包缺 control 文件报错修复 deb07-16
- 03
- 首次编译-环境初始化 必装07-16