【Kylin V10】强力卸载脚本x86_64
场景说明
本指南专为 Kylin V10(SP3·Halberd,x86_64) 设计,支持一键安全批量卸载 Ambari/Bigtop 及其依赖。适合 环境重置、集群重装、测试回收。脚本支持多节点并发,卸载后确保系统无历史残留。
# 一、支持范围
| 类别 | 说明 |
|---|---|
| 操作系统 | Kylin V10(SP3·Halberd),兼容 x86_64 |
| 包管理器 | yum/dnf 自动识别(脚本已做容错),不依赖 APT |
| 卸载内容 | Ambari Server/Agent、MariaDB/MySQL、JDK、MySQL Connector、 Nginx、本地 YUM 源、常见大数据组件残留(HDFS/HBase/Hive/Kafka/YARN/Tez/ZooKeeper/Ozone/Spark/Flink…) |
| 适用场景 | 建议与本站 ONEKEY 安装方案配套,复用原始 hosts.txt,支持多节点集群卸载、环境回滚、二次安装前清场与验收测试 |
# 二、卸载脚本完整内容 必读
注意
下方为 Kylin V10 专用 一键卸载脚本。复制前请确认 hosts.txt(用户名 密码 IP)配置无误;脚本会并发批处理,
对生产环境务必谨慎。已适配 yum/dnf、公钥、sudo 与 systemd 差异。
#!/bin/bash
# SPDX-License-Identifier: LicenseRef-JaneTTR-Proprietary
# 版权所有 (c) 2025 JaneTTR
# 项目名称:ambari-env
# 文件:install_ambari_cluster.sh
# 版本:1.0.0
# 联系方式:3832514048@qq.com
#
# 许可说明(付费/专有代码):
# - 本文件仅限个人学习与研究使用;
# - 未经版权所有者书面授权,禁止任何商业用途;
# - 禁止再分发本文件或其修改版本;
# - 禁止通过反编译、反向工程等方式试图绕过授权验证。
#
# 商业授权:
# 如需将本文件或其编译后的代码用于商业用途,必须获得版权所有者的书面授权。
# 请通过上述联系方式进行洽谈。
#
# 免责声明:
# 本文件按“现状”提供,不附带任何形式的担保,包括但不限于适销性、
# 特定用途适用性或无侵权的担保。因使用本文件造成的任何直接或间接损失,
# 版权所有者不承担任何责任。
#
# 如有任何疑问,请联系版权所有者。
set -euo pipefail
#=============================
# 环境与日志
#=============================
LOGFILE="/tmp/ambari_cleanup_kylin.log"
exec > >(tee -a "$LOGFILE") 2>&1
TARGET="${TARGET:-localhost}"
log_info () { echo "$(date '+%F %T') [Info] $*"; }
log_warn () { echo "$(date '+%F %T') [Warn] $*"; }
log_error () { echo "$(date '+%F %T') [Error] $*" >&2; }
#=============================
# OS 检测(要求 RedHat 家族)
#=============================
require_redhat_like() {
if command -v rpm >/dev/null 2>&1 && [ -f /etc/os-release ]; then
. /etc/os-release || true
if echo "${ID_LIKE:-}${ID:-}" | grep -Ei 'rhel|redhat|centos|kylin|openeuler|rocky|almalinux' >/dev/null; then
return 0
fi
fi
log_error "检测到当前不是 RedHat 家族系统(本脚本适配 Kylin/RedHat 系)。"
exit 1
}
#=============================
# 包管理工具选择
#=============================
PM=""
pm_detect() {
if command -v dnf >/dev/null 2>&1; then
PM="dnf"
elif command -v yum >/dev/null 2>&1; then
PM="yum"
else
log_error "未找到 dnf/yum,请确认是 Kylin/RedHat 系并安装包管理器。"
exit 1
fi
}
pm_install() { sudo "$PM" -y install "$@" --allowerasing || sudo "$PM" -y install "$@" || true; }
pm_remove() { sudo "$PM" -y remove "$@" || true; }
pm_autoremove() { if [ "$PM" = "dnf" ]; then sudo dnf -y autoremove || true; fi; }
pm_makecache() { sudo "$PM" -y makecache || true; }
pm_update_metadata() {
if [ "$PM" = "dnf" ]; then sudo dnf -y --refresh makecache || true; else sudo yum -y makecache fast || true; fi
}
#=============================
# 区域/语言(Kylin)
#=============================
ensure_locale_kylin() {
# Kylin/RedHat 系:通过 glibc-langpack-* 提供本地化
pm_install glibc-langpack-zh glibc-langpack-en || true
# 设置系统 locale(Kylin 支持 localectl)
if command -v localectl >/dev/null 2>&1; then
sudo localectl set-locale LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 || true
else
# 兜底写入 /etc/locale.conf
if [ -w /etc/locale.conf ] || sudo test -w /etc/locale.conf; then
echo -e "LANG=zh_CN.UTF-8\nLC_ALL=zh_CN.UTF-8" | sudo tee /etc/locale.conf >/dev/null || true
fi
fi
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
}
#=============================
# 基础工具与 sshpass
#=============================
ensure_base_tools() {
pm_update_metadata
pm_install which coreutils findutils util-linux procps-ng psmisc lsof gawk grep sed tar gzip || true
}
ensure_sshpass() {
if ! command -v sshpass >/dev/null 2>&1; then
log_info "sshpass 未安装,开始安装…"
pm_install sshpass
if ! command -v sshpass >/dev/null 2>&1; then
log_warn "仓库中找不到 sshpass,尝试启用可用的 Extra/Epol/PowerTools 仓库后再次安装…"
# 视 Kylin 仓库情况而定,尝试启用额外仓库(存在则启用)
sudo "$PM" config-manager --set-enabled epol 2>/dev/null || true
sudo "$PM" config-manager --set-enabled powertools 2>/dev/null || true
pm_makecache
pm_install sshpass
fi
fi
}
#=============================
# 停服务 & 杀进程
#=============================
stop_services_and_kill() {
log_info "[$TARGET] 停止服务与杀进程…"
# 优先通过 systemctl 停止常见大数据服务(存在则停止)
local svc_list=(
ambari-server ambari-agent
hadoop-hdfs-namenode hadoop-hdfs-datanode hadoop-yarn-resourcemanager hadoop-yarn-nodemanager
zookeeper ranger-admin ranger-usersync
kafka solr zeppelin spark flink ozone
mariadb mysql
nightingale categraf
)
for svc in "${svc_list[@]}"; do
if systemctl list-unit-files | awk '{print $1}' | grep -qx "${svc}.service"; then
sudo systemctl stop "$svc" || true
sudo systemctl disable "$svc" || true
fi
done
# 杀掉 jps 检测到的 Java 进程(排除 Jps)
if command -v jps >/dev/null 2>&1; then
mapfile -t pids < <(jps | awk '$2 != "Jps" && $3 != "information" {print $1}')
for pid in "${pids[@]}"; do
if [[ "$pid" =~ ^[0-9]+$ ]] && kill -0 "$pid" 2>/dev/null; then
kill -9 "$pid" || true
fi
done
fi
# 关键词兜底
for kw in java n9e nightingale categraf hadoop yarn zookeeper kafka spark flink zeppelin solr ozone; do
mapfile -t kw_pids < <(ps -eo pid,cmd --no-headers | grep -E "$kw" | grep -v grep | awk '{print $1}')
for pid in "${kw_pids[@]:-}"; do
if [[ "$pid" =~ ^[0-9]+$ ]] && kill -0 "$pid" 2>/dev/null; then
log_info "按关键词[$kw] 杀进程: $pid"
kill -9 "$pid" || true
fi
done
done
}
#=============================
# 卸载 Ambari/Bigtop 相关包(RPM)
#=============================
remove_ambari_bigtop_rpms() {
log_info "[$TARGET] 卸载 Ambari/Bigtop 相关 RPM 包…"
mapfile -t rpms < <(rpm -qa | egrep -i 'ambari|bigtop' || true)
if [ "${#rpms[@]}" -gt 0 ]; then
pm_remove "${rpms[@]}" || true
pm_autoremove
fi
}
#=============================
# 清理文件/目录/用户/DB/日志
#=============================
cleanup_files_users_db() {
log_info "[$TARGET] 清理残留文件与目录…"
local dirs=(/opt /usr /etc /var /home /data* /kafka-logs /hadoop /ozone /celeborn)
local regex='.*(ambari-qa|ams|hbase|hcat|hdfs|hive|kafka|kms|mapred|ranger|solr|sqoop|tez|yarn|dolphin|zookeeper|doris|nightingale|categraf|spark|flink|zeppelin|phoenix|ozone|celeborn|cloudbeaver|bigtop|ambari).*'
for d in "${dirs[@]}"; do
[ -e "$d" ] || continue
sudo find "$d" -regextype posix-extended -regex "$regex" \
-not -path "/data/modules" -not -path "/data/modules/*" \
-exec rm -rf {} + 2>/dev/null || true
done
sudo rm -rf /usr/bigtop 2>/dev/null || true
sudo rm -rf /data/kafka-logs /data/hadoop 2>/dev/null || true
sudo rm -rf /kafka-logs/meta.properties /hadoop/* /data1/* /data2/* /ozone /celeborn 2>/dev/null || true
log_info "[$TARGET] 清理大数据相关用户/组/家目录…"
local users=(ambari-qa ams hbase hcat hdfs hive kafka kms mapred ranger solr sqoop tez yarn zookeeper zeppelin flink spark hadoop doris nightingale categraf ozone celeborn)
for u in "${users[@]}"; do
sudo pkill -u "$u" 2>/dev/null || true
sudo userdel -r "$u" 2>/dev/null || true
sudo groupdel "$u" 2>/dev/null || true
sudo rm -rf /home/"$u" 2>/dev/null || true
done
log_info "[$TARGET] 清理 Hadoop/ZK/Kafka 等日志目录(按组 hadoop)…"
sudo find /var/log -type d -group hadoop -exec rm -rf {} + 2>/dev/null || true
log_info "[$TARGET] 清理并重建数据库(如安装了 MariaDB/MySQL)…"
local svc="" initcmd=""
if systemctl list-units --type=service | grep -q mariadb; then
svc="mariadb"; initcmd="mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql"
elif systemctl list-units --type=service | grep -q mysql; then
svc="mysql"; initcmd="mysqld --initialize-insecure --user=mysql --datadir=/var/lib/mysql"
fi
if [ -n "$svc" ]; then
sudo systemctl stop "$svc" || log_warn "停止 $svc 失败(可能未运行)"
sudo rm -rf /var/lib/mysql/* || log_warn "清理 /var/lib/mysql 失败"
# 某些发行版 mariadb-install-db 在 /usr/libexec /usr/bin 之间差异,尝试补全 PATH
if ! command -v mariadb-install-db >/dev/null 2>&1 && [ -x /usr/libexec/mariadb-install-db ]; then
sudo ln -sf /usr/libexec/mariadb-install-db /usr/bin/mariadb-install-db || true
fi
bash -lc "$initcmd" || log_warn "数据库初始化失败:$initcmd"
sudo systemctl restart "$svc" || log_warn "重启 $svc 失败"
sudo systemctl enable "$svc" || true
fi
}
#=============================
# 远端执行(通过 sshpass)
#=============================
run_remote() {
local user=$1 ip=$2 pass=$3
sshpass -p "$pass" ssh -o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-o ConnectTimeout=8 \
"$user@$ip" "TARGET=$ip bash -s remote" < "$0"
}
#=============================
# 本地主流程
#=============================
main() {
require_redhat_like
pm_detect
ensure_base_tools
ensure_locale_kylin
ensure_sshpass
# 获取本机 IP 列表(含 127.0.0.1)
mapfile -t local_ips < <(hostname -I 2>/dev/null | tr ' ' '\n' || true)
local_ips+=(127.0.0.1)
# 读取 hosts.txt:每行 "user password ip"
if [ ! -f "./hosts.txt" ]; then
log_error "hosts.txt 不存在(每行格式:user password ip)"
exit 1
fi
while IFS= read -r line || [ -n "$line" ]; do
line="$(echo "$line" | tr -d '\r')"
[[ -z "$line" || "$line" =~ ^# ]] && continue
read -r user pass ip <<< "$(echo "$line" | xargs)"
TARGET="$ip"
log_info "=== 开始处理 $TARGET ==="
if printf '%s\n' "${local_ips[@]}" | grep -Fxq "$ip"; then
stop_services_and_kill
remove_ambari_bigtop_rpms
cleanup_files_users_db
ensure_locale_kylin
else
run_remote "$user" "$ip" "$pass"
fi
log_info "=== $TARGET 处理完毕 ==="
done < "./hosts.txt"
log_info "所有节点清理完成,详见 $LOGFILE"
}
#=============================
# 远端主流程
#=============================
remote_main() {
require_redhat_like
pm_detect
ensure_base_tools
ensure_locale_kylin
stop_services_and_kill
remove_ambari_bigtop_rpms
cleanup_files_users_db
ensure_locale_kylin
}
#=============================
# 脚本入口
#=============================
if [[ "${1-}" == "remote" ]]; then
remote_main
exit 0
else
main
exit 0
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# 三、hosts.txt 格式说明
| 用户名 | 密码 | IP地址 |
|---|---|---|
| root | xxxxxx | 192.168.3.1 |
| root | xxxxxx | 192.168.3.2 |
| root | xxxxxx | 192.168.3.3 |
笔记
Kylin V10 全节点需 网络互通、具备 sudo/root 权限。hosts.txt 可直接复用 ONEKEY 安装方案的同名文件。
# 四、使用方法
# 1、准备 hosts.txt
将所有目标主机账号、密码、IP 填入 hosts.txt 并与脚本置于同目录。
# 2、执行卸载脚本
chmod +x uninstall_ambari_cluster.sh
./uninstall_ambari_cluster.sh
1
2
2
日志默认写入 ambari_cleanup.log;失败节点会落盘到 failed_hosts.log。
# 3、核查结果(建议逐台)
- 关键目录确认
/var/lib/ambari-*、/usr/bigtop、/var/lib/mysql/、/etc/ambari*、/var/log/ambari* - 数据卷按需复核
/data1、/data2、/data/hadoop、/data/kafka-logs、/hadoop/* - 服务状态
systemctl status ambari-server ambari-agent mariadb应处于 inactive/disabled
可选:保留业务数据的做法
若节点上存在需保留的数据分区,请在脚本前部的 数据清理段 注释对应的 rm -rf 行,或在生产环境使用前先在测试环境验证路径白名单。
# 五、Kylin V10 差异项说明
# 一、包管理差异
- Kylin 使用 yum/dnf,脚本已自动识别,不再包含 APT 分支。
- Ambari/Bigtop 组件卸载通过
yum/dnf remove,正则命中ambari|bigtop包名,避免遗漏。
# 二、服务管理
- 统一使用
systemctl stop/disable处理 Ambari/MDB/Nginx 及常见大数据服务; - 对历史“非 systemd 启动脚本”进程,通过 关键词杀进程 兜底(
java/hadoop/hdfs/kafka/...)。
# 三、数据与账号回收
- 覆盖 用户/用户组 清理:
ambari-qa、hdfs、yarn、hive、kafka、zookeeper、spark、flink、ranger…; - 数据目录按 关键词 与 常见路径 双清理,减少残留;
- MariaDB 支持 数据重建(
mariadb-install-db),用于集群重装前置。
警告
生产环境谨慎执行!脚本默认会清理多类数据路径与用户。如需保留业务数据/账号,请先调小清理范围再执行。
# 六、图示参考



- 01
- Ambari开启Kerberos认证加密类型错误 Kylin V1011-05
- 02
- KERBEROS SERVICE CHECK 报错11-04