ONEKEY——快速安装适用于3.0.0-el7
# 🚀 ONEKEY 快速安装指南
本教程介绍 一键安装脚本 的使用方法,帮助您快速部署集群环境。
如果您希望深入了解安装原理,请参考 常规安装教程。
# 📌 适用环境
适用系统
- 操作系统:适用于 CentOS 7.9.2009
- 其他环境:未经测试,不保证兼容性
# 📌 安装步骤
# 1️⃣ 复制安装脚本
脚本如下
可以复制如下脚本,首次执行会比较慢,会从公网上下载必要的镜像
#!/bin/bash
# 版权所有 (c) JaneTTR 2025
# 项目名称:ambari-env
#
# 本文件属于付费部分代码,仅供个人学习和研究使用。
#
# 禁止行为:
# 1. 未经授权,不得将本文件或其编译后的代码用于任何商业用途;
# 2. 禁止重新分发本文件或其修改版本;
# 3. 禁止通过反编译、反向工程等手段试图绕过授权验证。
#
# 商业授权:
# 如需将本文件或其编译后的代码用于商业用途,必须获得版权所有者的书面授权。
# 联系方式:
# 邮箱:3832514048@qq.com
#
# 责任声明:
# 本文件按“现状”提供,不附带任何形式的担保,包括但不限于适销性、特定用途适用性或无侵权的担保。
#
# 如有任何疑问,请联系版权所有者。
# install_ambari_cluster.sh
# 一键安装 Ambari 集群环境
# 读取 hosts.txt(每行格式:用户名 密码 ip),转换为“用户名 ip 密码”
# 依次执行:
# 1. 安装必要工具
# 2. 配置主机间免密 SSH
# 3. 更新各主机 /etc/hosts 文件
# 4. 配置 Chrony 时间同步
# 5. 配置 Nginx(作为本地 Yum 源代理)
# 6. 检查并安装 JDK
# 7. 安装 MySQL Connector/J
# 8. 检查并初始化本地 YUM 仓库
# 9. 配置本地 Yum 源(指向最小 IP 主机)
# 10. 配置 MariaDB(含自动 secure-installation 应答,并授予 root 远程权限)
# 11. 安装 Ambari Server 和 Agent(ambari-server setup 部分采用 expect 自动应答)
#
# 请确保系统中已安装 sshpass、expect、curl、yum 等工具,
# 并保证 hosts.txt 与此脚本在同一目录下。
set -e
LOGFILE="ambari_install.log"
exec > >(tee -a "$LOGFILE") 2>&1
# 定义日志函数,与 uninstall 脚本保持统一
log_info() {
echo "$(date '+%Y-%m-%d %H:%M:%S') [Info] $*"
}
log_error() {
echo "$(date '+%Y-%m-%d %H:%M:%S') [Error] $*" >&2
}
##############################
# 全局变量配置
##############################
HOSTS_FILE="hosts.txt"
DDL_PATH="/var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql"
# JDK 版本参数(适用于 ambari 3.0)
JDK_VERSION="17.0.15_6"
JDK_SHORT="17.0.15"
JDK_FILENAME="OpenJDK17U-jdk_x64_linux_hotspot_${JDK_VERSION}.tar.gz"
JDK_DOWNLOAD_URL="https://mirrors.tuna.tsinghua.edu.cn/Adoptium/17/jdk/x64/linux/${JDK_FILENAME}"
JDK_FILE_PATH="/opt/modules/${JDK_FILENAME}"
JDK_FILE_HOME_PATH="/opt/modules/jdk-${JDK_SHORT}+6"
JDK17_SYMLINK="/usr/jdk64/jdk17"
JDK8_VERSION="1.8.0_202"
JDK8_SHORT="1.8.0_202"
JDK8_FILENAME="jdk-8u202-linux-x64.tar.gz"
JDK8_DOWNLOAD_URL="https://repo.huaweicloud.com/java/jdk/8u202-b08/${JDK8_FILENAME}"
JDK8_FILE_PATH="/opt/modules/${JDK8_FILENAME}"
JDK8_FILE_HOME_PATH="/opt/modules/jdk${JDK8_SHORT}"
JDK8_SYMLINK="/usr/jdk64/jdk1.8"
# MySQL Connector 配置
CONNECTOR_FILE="mysql-connector-java-5.1.48.tar.gz"
CONNECTOR_URL="https://mirrors.aliyun.com/mysql/Connector-J/mysql-connector-java-5.1.48.tar.gz"
CONNECTOR_JAR="mysql-connector-java-5.1.48-bin.jar"
TARGET_JAR="/usr/share/java/mysql-connector-java.jar"
# MariaDB 配置
ROOT_PASSWORD="root"
AMBARI_DB_PASSWORD="ambari"
HIVE_DB_PASSWORD="hive"
# RPM 仓库配置
RPM_DIR="/data/modules"
CREATEREPO_CMD="createrepo"
# Nginx 配置(作为本地 Yum 源代理)
NGINX_MODULES_DIR="/data/modules"
# 获取 JAVA_HOME(确保 JDK 已安装,否则后续应答 ambari-server setup 时无法提供 JAVA_HOME)
JAVA_HOME=$(readlink -f "$(which java)" | sed "s:/bin/java::")
export JAVA_HOME
##############################
# 从 hosts.txt 读取主机信息
# 每行格式:用户名 密码 ip
# 转换为 "用户名 ip 密码" 存入数组 HOSTS
##############################
HOSTS=()
while IFS= read -r line || [ -n "$line" ]; do
[[ -z "$line" || "$line" =~ ^# ]] && continue
line=$(echo "$line" | tr -d '\r' | xargs)
read -r username password ip <<< "$line"
log_info "读取主机: $ip (user: $username)"
HOSTS+=("$username $ip $password")
done < "$HOSTS_FILE"
log_info "读取完毕,主机列表:"
printf " %s\n" "${HOSTS[@]}"
##############################
# 函数:安装必要工具
##############################
function pre_install_tools() {
log_info ">>> 安装必要工具"
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
log_info "处理主机 $ip ..."
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<'EOF'
set -e
echo "更新系统软件包..."
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
sudo yum update -y
sudo yum install -y py wget createrepo chrony sshpass expect python3
if [ ! -f /etc/yum.repos.d/mariadb.repo ]; then
cat <<EOL | sudo tee /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.11/centos7-amd64
gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
enabled = 1
EOL
fi
sudo yum install -y MariaDB-server MariaDB-client
sudo systemctl enable mariadb
sudo systemctl start mariadb
if [ ! -f /etc/yum.repos.d/nginx.repo ]; then
cat <<EOL | sudo tee /etc/yum.repos.d/nginx.repo
[nginx-stable]
name = nginx stable repo
baseurl = https://mirrors.ustc.edu.cn/nginx/centos/7/x86_64/
gpgcheck = 0
enabled = 1
module_hotfixes = true
EOL
fi
sudo yum install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
EOF
done
}
##############################
# 函数:配置主机间免密 SSH
##############################
function pre_setup_passwordless_ssh() {
log_info ">>> 配置主机间免密登录"
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<'EOF'
set -e
mkdir -p ~/.ssh
chmod 700 ~/.ssh
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -N ""
fi
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
EOF
done
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
pub_key=$(sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" "cat ~/.ssh/id_rsa.pub")
for target_info in "${HOSTS[@]}"; do
target_user=$(echo "$target_info" | awk '{print $1}')
target_ip=$(echo "$target_info" | awk '{print $2}')
target_pass=$(echo "$target_info" | awk '{print $3}')
sshpass -p "$target_pass" ssh -o StrictHostKeyChecking=no "$target_user@$target_ip" bash <<EOF
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
if ! grep -q '$pub_key' ~/.ssh/authorized_keys; then
echo '$pub_key' >> ~/.ssh/authorized_keys
fi
EOF
done
done
log_info "免密登录配置完成。"
}
##############################
# 函数:更新 /etc/hosts 文件
##############################
function pre_update_hosts_file() {
log_info ">>> 更新 /etc/hosts 文件"
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
log_info "更新主机 $ip 的 /etc/hosts 文件..."
host_name=$(sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" "hostname")
update_cmd="echo '### 更新 /etc/hosts 文件 ###';"
for target_info in "${HOSTS[@]}"; do
target_ip=$(echo "$target_info" | awk '{print $2}')
target_host_name=$(sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" "ssh -o StrictHostKeyChecking=no $user@$target_ip hostname")
update_cmd+="if ! grep -q '$target_ip $target_host_name' /etc/hosts; then echo '$target_ip $target_host_name' | sudo tee -a /etc/hosts > /dev/null; fi;"
done
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" "$update_cmd"
log_info "主机 $ip 的 /etc/hosts 更新完成。"
done
log_info "/etc/hosts 更新完成。"
}
##############################
# 函数:配置 Chrony 时间同步
##############################
function pre_setup_ntp_sync() {
log_info ">>> 配置 Chrony 时间同步"
IPS=()
for host_info in "${HOSTS[@]}"; do
ip=$(echo "$host_info" | awk '{print $2}')
IPS+=("$ip")
done
SERVER_IP="${IPS[0]}"
CLIENT_IPS=("${IPS[@]:1}")
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
if [ "$ip" == "$SERVER_IP" ]; then
log_info "在服务器 $ip 上配置 Chrony..."
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<'EOF'
set -e
if ! command -v chronyd &>/dev/null; then
sudo yum install -y chrony
fi
cat <<EOL | sudo tee /etc/chrony.conf
server ntp.ntsc.ac.cn iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
allow 0.0.0.0/0
local stratum 10
driftfile /var/lib/chrony/drift
logdir /var/log/chrony
EOL
sudo systemctl restart chronyd
sudo systemctl enable chronyd
EOF
fi
done
for ip in "${CLIENT_IPS[@]}"; do
for host_info in "${HOSTS[@]}"; do
curr_ip=$(echo "$host_info" | awk '{print $2}')
if [ "$curr_ip" == "$ip" ]; then
user=$(echo "$host_info" | awk '{print $1}')
password=$(echo "$host_info" | awk '{print $3}')
log_info "在客户端 $ip 配置 Chrony..."
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<EOF
set -e
if ! command -v chronyd &>/dev/null; then
sudo yum install -y chrony
fi
cat <<EOL | sudo tee /etc/chrony.conf
server $SERVER_IP iburst
driftfile /var/lib/chrony/drift
logdir /var/log/chrony
EOL
sudo systemctl restart chronyd
sudo systemctl enable chronyd
EOF
fi
done
done
log_info "Chrony 时间同步配置完成。"
}
##############################
# 函数:配置 Nginx(作为本地 Yum 仓库代理)
##############################
function pre_setup_nginx() {
log_info ">>> 配置 Nginx"
IPS=()
for host_info in "${HOSTS[@]}"; do
ip=$(echo "$host_info" | awk '{print $2}')
IPS+=("$ip")
done
IFS=$'\n' sorted_ips=($(sort -n <<<"${IPS[*]}"))
unset IFS
SMALLEST_IP="${sorted_ips[0]}"
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
if [ "$ip" == "$SMALLEST_IP" ]; then
log_info "在 $ip 配置 Nginx..."
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<'EOF'
set -e
if ! command -v nginx &>/dev/null; then
sudo yum install -y epel-release nginx
fi
MODULES_DIR="'"$NGINX_MODULES_DIR"'"
sudo mkdir -p "$MODULES_DIR"
sudo chmod -R 755 "$MODULES_DIR"
sudo chown -R nginx:nginx "$MODULES_DIR"
if getenforce | grep -iq "Enforcing"; then
sudo chcon -Rt httpd_sys_content_t "$MODULES_DIR"
fi
if [ -f "/etc/nginx/conf.d/default.conf" ]; then
sudo mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
fi
if [ ! -f "/etc/nginx/nginx.conf" ]; then
sudo tee /etc/nginx/nginx.conf > /dev/null <<EOL
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/conf.d/*.conf;
}
EOL
fi
sudo tee /etc/nginx/conf.d/modules_proxy.conf > /dev/null <<EOL
server {
listen 80;
server_name _;
location / {
root /data/modules;
index index.html index.htm;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
error_page 404 /404.html;
}
EOL
sudo nginx -t
sudo systemctl restart nginx
sudo systemctl enable nginx
EOF
fi
done
log_info "Nginx 配置完成。"
}
function pre_check_jdk() {
log_info ">>> 检查并批量安装 JDK8 & JDK17"
# 1. 取主控机 IP
IPS=()
for host_info in "${HOSTS[@]}"; do
ip=$(echo "$host_info" | awk '{print $2}')
IPS+=("$ip")
done
IFS=$'\n' sorted_ips=($(sort -n <<<"${IPS[*]}"))
unset IFS
SMALLEST_IP="${sorted_ips[0]}"
# 2. 主控机下载 JDK8/JDK17
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
if [ "$ip" == "$SMALLEST_IP" ]; then
log_info "在 $ip 下载 JDK8 和 JDK17..."
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<EOF
set -e
mkdir -p /opt/modules
if [ ! -s "$JDK8_FILE_PATH" ]; then
echo "[JDK8] 开始下载: $JDK8_DOWNLOAD_URL"
curl -fSL -o "$JDK8_FILE_PATH" "$JDK8_DOWNLOAD_URL"
else
echo "[JDK8] JDK 包已存在: $JDK8_FILE_PATH"
fi
if [ ! -s "$JDK_FILE_PATH" ]; then
echo "[JDK17] 开始下载: $JDK_DOWNLOAD_URL"
curl -fSL -o "$JDK_FILE_PATH" "$JDK_DOWNLOAD_URL"
else
echo "[JDK17] JDK 包已存在: $JDK_FILE_PATH"
fi
EOF
fi
done
# 3. 分发 JDK 包到其他节点
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
if [ "$ip" != "$SMALLEST_IP" ]; then
log_info "同步 JDK8 包到 $ip..."
sshpass -p "$password" scp -o StrictHostKeyChecking=no "$SMALLEST_IP:$JDK8_FILE_PATH" "$user@$ip:$JDK8_FILE_PATH"
log_info "同步 JDK17 包到 $ip..."
sshpass -p "$password" scp -o StrictHostKeyChecking=no "$SMALLEST_IP:$JDK_FILE_PATH" "$user@$ip:$JDK_FILE_PATH"
fi
done
# 4. 每台主机解压&配置
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
log_info "在 $ip 解压安装 JDK8 和 JDK17..."
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<EOF
set -e
mkdir -p /opt/modules
# JDK8
if [ ! -d "$JDK8_FILE_HOME_PATH" ]; then
echo "[JDK8] 解压..."
tar -zxf "$JDK8_FILE_PATH" -C /opt/modules
JDK8_DIR=\$(tar -tf "$JDK8_FILE_PATH" | head -1 | cut -d/ -f1)
if [ "/opt/modules/\$JDK8_DIR" != "$JDK8_FILE_HOME_PATH" ]; then
mv "/opt/modules/\$JDK8_DIR" "$JDK8_FILE_HOME_PATH"
fi
else
echo "[JDK8] 已解压: $JDK8_FILE_HOME_PATH"
fi
# JDK17
if [ ! -d "$JDK_FILE_HOME_PATH" ]; then
echo "[JDK17] 解压..."
tar -zxf "$JDK_FILE_PATH" -C /opt/modules
JDK17_DIR=\$(tar -tf "$JDK_FILE_PATH" | head -1 | cut -d/ -f1)
if [ "/opt/modules/\$JDK17_DIR" != "$JDK_FILE_HOME_PATH" ]; then
mv "/opt/modules/\$JDK17_DIR" "$JDK_FILE_HOME_PATH"
fi
else
echo "[JDK17] 已解压: $JDK_FILE_HOME_PATH"
fi
# JDK8 设为默认
sudo bash -c "cat >/etc/profile.d/java.sh" <<EOL
export JAVA_HOME=$JDK8_FILE_HOME_PATH
export PATH=\\\$JAVA_HOME/bin:\\\$PATH
EOL
# JDK17 建软连接
sudo mkdir -p /usr/jdk64
if [ -L "$JDK17_SYMLINK" ] || [ -e "$JDK17_SYMLINK" ]; then
sudo rm -rf "$JDK17_SYMLINK"
fi
sudo ln -s "$JDK_FILE_HOME_PATH" "$JDK17_SYMLINK"
echo "[JDK17] 软链接已创建: $JDK17_SYMLINK -> $JDK_FILE_HOME_PATH"
source /etc/profile.d/java.sh
echo "[JDK8] 当前 JAVA 版本:"
java -version
echo "[JDK17] 路径:"
ls -l "$JDK17_SYMLINK"
# JDK8 建软连接
sudo mkdir -p /usr/jdk64
if [ -L "$JDK8_SYMLINK" ] || [ -e "$JDK8_SYMLINK" ]; then
sudo rm -rf "$JDK8_SYMLINK"
fi
sudo ln -s "$JDK8_FILE_HOME_PATH" "$JDK8_SYMLINK"
echo "[JDK8] 软链接已创建: $JDK8_SYMLINK -> $JDK8_FILE_HOME_PATH"
EOF
done
log_info "JDK8/JDK17 安装及软连接全部完成。"
}
##############################
# 函数:安装 MySQL Connector/J
##############################
function pre_check_mysql_conn() {
log_info ">>> 安装 MySQL Connector/J"
IPS=()
for host_info in "${HOSTS[@]}"; do
ip=$(echo "$host_info" | awk '{print $2}')
IPS+=("$ip")
done
IFS=$'\n' sorted_ips=($(sort -n <<<"${IPS[*]}"))
unset IFS
SMALLEST_IP="${sorted_ips[0]}"
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
if [ "$ip" == "$SMALLEST_IP" ]; then
log_info "在 $ip 安装 MySQL Connector/J..."
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<EOF
set -e
mkdir -p /opt/modules
if [ -f "$TARGET_JAR" ]; then
echo "MySQL Connector/J 已存在,跳过安装。"
exit 0
fi
if [ ! -f "/opt/modules/$CONNECTOR_FILE" ]; then
wget -q "$CONNECTOR_URL" -O "/opt/modules/$CONNECTOR_FILE"
fi
if [ ! -f "/opt/modules/$CONNECTOR_JAR" ]; then
tar -xzf "/opt/modules/$CONNECTOR_FILE" -C /opt/modules
fi
sudo mkdir -p \$(dirname "$TARGET_JAR")
sudo mv "/opt/modules/mysql-connector-java-5.1.48/$CONNECTOR_JAR" "$TARGET_JAR"
EOF
fi
done
log_info "MySQL Connector/J 安装完成。"
}
##############################
# 函数:检查并初始化本地 YUM 仓库
##############################
function pre_check_yum_package() {
log_info ">>> 检查并初始化 YUM 仓库"
IPS=()
for host_info in "${HOSTS[@]}"; do
ip=$(echo "$host_info" | awk '{print $2}')
IPS+=("$ip")
done
IFS=$'\n' sorted_ips=($(sort -n <<<"${IPS[*]}"))
unset IFS
SMALLEST_IP="${sorted_ips[0]}"
for host_info in "${HOSTS[@]}"; do
user=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
password=$(echo "$host_info" | awk '{print $3}')
if [ "$ip" == "$SMALLEST_IP" ]; then
log_info "在 $ip 检查 RPM 包仓库..."
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" bash <<EOF
set -e
if ! command -v $CREATEREPO_CMD &>/dev/null; then
sudo yum install -y createrepo
fi
mkdir -p "$RPM_DIR"
if [ -z "\$(ls -A $RPM_DIR 2>/dev/null)" ]; then
echo "RPM 目录为空,可在此处添加 RPM 包下载逻辑。"
fi
if [ -d "$RPM_DIR/repodata" ]; then
rm -rf "$RPM_DIR/repodata"
fi
$CREATEREPO_CMD "$RPM_DIR"
EOF
fi
done
log_info "YUM 仓库初始化完成。"
}
##############################
# 函数:配置本地 Yum 源(指向最小 IP 主机)
##############################
function pre_check_local_yum() {
log_info ">>> 配置本地 Yum 源"
IPS=()
USERS=()
PASSWORDS=()
for host_info in "${HOSTS[@]}"; do
USERS+=("$(echo "$host_info" | awk '{print $1}')")
ip=$(echo "$host_info" | awk '{print $2}')
IPS+=("$ip")
PASSWORDS+=("$(echo "$host_info" | awk '{print $3}')")
done
IFS=$'\n' sorted_ips=($(sort -n <<<"${IPS[*]}"))
unset IFS
SERVER_IP="${sorted_ips[0]}"
for i in "${!IPS[@]}"; do
if [ "${IPS[i]}" == "$SERVER_IP" ]; then
SERVER_USER="${USERS[i]}"
SERVER_PASSWORD="${PASSWORDS[i]}"
break
fi
done
for i in "${!IPS[@]}"; do
client_ip="${IPS[i]}"
client_user="${USERS[i]}"
client_password="${PASSWORDS[i]}"
sshpass -p "$client_password" ssh -o StrictHostKeyChecking=no "$client_user@$client_ip" bash <<EOF
cat <<YUM_REPO | sudo tee /etc/yum.repos.d/ambari.repo
[ambari]
name=Ambari Local Repository
baseurl=http://$SERVER_IP/
enabled=1
gpgcheck=0
YUM_REPO
sudo yum clean all
sudo yum repolist
EOF
done
log_info "本地 Yum 源配置完成。"
}
##############################
# 函数:配置 MariaDB(含自动 secure-installation 应答,并授予 root 远程连接权限)
##############################
function pre_check_mariadb_config() {
log_info ">>> 配置 MariaDB"
IPS=()
USERS=()
PASSWORDS=()
for host_info in "${HOSTS[@]}"; do
USERS+=("$(echo "$host_info" | awk '{print $1}')")
ip=$(echo "$host_info" | awk '{print $2}')
IPS+=("$ip")
PASSWORDS+=("$(echo "$host_info" | awk '{print $3}')")
done
IFS=$'\n' sorted_ips=($(sort -n <<<"${IPS[*]}"))
unset IFS
SERVER_IP="${sorted_ips[0]}"
CLIENT_IPS=("${sorted_ips[@]:1}")
CURRENT_IP=$(hostname -I | awk '{print $1}')
for i in "${!IPS[@]}"; do
if [ "${IPS[i]}" == "$SERVER_IP" ]; then
SERVER_USER="${USERS[i]}"
SERVER_PASSWORD="${PASSWORDS[i]}"
break
fi
done
if [ "$CURRENT_IP" == "$SERVER_IP" ]; then
# 修改 /etc/my.cnf,确保 bind-address=0.0.0.0
sshpass -p "$SERVER_PASSWORD" ssh -o StrictHostKeyChecking=no "$SERVER_USER@$SERVER_IP" bash <<'EOF'
set -e
sudo tee /etc/my.cnf > /dev/null <<EOL
[client]
default-character-set=utf8mb4
[mysqld]
user=mysql
port=3306
basedir=/usr
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
default-storage-engine=InnoDB
innodb_buffer_pool_size=1G
innodb_log_file_size=256M
innodb_log_buffer_size=64M
innodb_file_per_table=1
innodb_lock_wait_timeout=50
innodb_buffer_pool_instances=4
innodb_doublewrite=1
innodb_adaptive_hash_index=1
innodb_file_format=Barracuda
innodb_compression_level=6
innodb_fast_shutdown=1
innodb_strict_mode=1
innodb_status_file=1
innodb_stats_on_metadata=0
innodb_thread_concurrency=8
bind-address=0.0.0.0
skip-name-resolve
max_connections=500
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow-query.log
long_query_time=2
[mysqldump]
default-character-set=utf8mb4
EOL
if [ ! -d /var/run/mysqld ]; then
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
fi
if [ ! -d /var/log/mysql ]; then
sudo mkdir -p /var/log/mysql
sudo chown mysql:mysql /var/log/mysql
fi
if [ ! -d /var/lib/mysql/mysql ]; then
mysql_install_db --user=mysql --datadir=/var/lib/mysql
fi
if ! command -v mariadb &>/dev/null; then
sudo yum install -y MariaDB-server MariaDB-client
fi
sudo systemctl restart mariadb
sudo systemctl enable mariadb
EOF
# 自动应答 MariaDB secure-installation(用 expect 内嵌应答),注意此处外层 here-doc未使用单引号,以便变量展开
sshpass -p "$SERVER_PASSWORD" ssh -o StrictHostKeyChecking=no "$SERVER_USER@$SERVER_IP" bash <<EOF
set -e
if ! command -v expect >/dev/null 2>&1; then
sudo yum install -y expect
fi
expect << "END_EXPECT"
set timeout 20
spawn mariadb-secure-installation
# 1. 输入空密码(直接回车)
expect "Enter current password for root (enter for none):"
send "root\r"
puts "Sent empty root password."
# 2. 处理 "Switch to unix_socket authentication [Y/n]" 提示
expect {
-re {Switch to unix_socket authentication \[Y/n\]} {
send "n\r"
puts "Sent n for 'Switch to unix_socket authentication'."
}
timeout { puts "No unix_socket prompt encountered."; }
}
# 3. 处理 "Change the root password? [Y/n]" 提示
expect {
-re {Change the root password\? \[Y/n\]} {
send "n\r"
puts "Sent n for 'Change the root password?'."
}
-re {Remove anonymous users\?} {
puts "No change password prompt; proceeding to anonymous users."
exp_continue
}
timeout { puts "No change root password prompt encountered."; }
}
# 4. 处理 "Remove anonymous users?" 提示(允许跨行匹配)
expect {
-re {(?s)Remove anonymous users.*\[Y/n\]} {
send "y\r"
puts "Sent y for 'Remove anonymous users?'."
}
timeout { puts "No 'Remove anonymous users' prompt encountered."; }
}
# 5. 处理 "Disallow root login remotely? [Y/n]" 提示
expect {
-re {Disallow root login remotely\? \[Y/n\]} {
send "n\r"
puts "Sent n for 'Disallow root login remotely?'."
}
timeout { puts "No disallow root login remotely prompt encountered."; }
}
# 6. 处理 "Remove test database and access to it? [Y/n]" 提示
expect {
-re {Remove test database and access to it\? \[Y/n\]} {
send "n\r"
puts "Sent n for 'Remove test database and access to it?'."
}
timeout { puts "No remove test database prompt encountered."; }
}
# 7. 处理 "Reload privilege tables now? [Y/n]" 提示
expect {
-re {Reload privilege tables now\? \[Y/n\]} {
send "y\r"
puts "Sent y for 'Reload privilege tables now?'."
}
timeout { puts "No reload privilege tables prompt encountered."; }
}
expect eof
END_EXPECT
EOF
# 授予 root 用户远程连接权限,解决 1130 错误
sshpass -p "$SERVER_PASSWORD" ssh -o StrictHostKeyChecking=no "$SERVER_USER@$SERVER_IP" bash <<'EOF'
mysql -uroot -p'root' <<EOFSQL
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');
CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EOFSQL
EOF
fi
# 测试客户端 MariaDB 连接
for client_ip in "${CLIENT_IPS[@]}"; do
for host_info in "${HOSTS[@]}"; do
curr_ip=$(echo "$host_info" | awk '{print $2}')
if [ "$curr_ip" == "$client_ip" ]; then
client_user=$(echo "$host_info" | awk '{print $1}')
client_pass=$(echo "$host_info" | awk '{print $3}')
sshpass -p "$client_pass" ssh -o StrictHostKeyChecking=no "$client_user@$client_ip" "mysql -uroot -p'${ROOT_PASSWORD}' -h'$SERVER_IP' -e 'SELECT 1;'"
fi
done
done
log_info "MariaDB 配置完成。"
}
##############################
# 函数:安装 Ambari Server 和 Agent
##############################
function install_ambari() {
log_info ">>> 安装 Ambari Server 和 Agent"
USERS=()
IPS=()
PASSWORDS=()
for host_info in "${HOSTS[@]}"; do
u=$(echo "$host_info" | awk '{print $1}')
ip=$(echo "$host_info" | awk '{print $2}')
p=$(echo "$host_info" | awk '{print $3}')
USERS+=("$u")
IPS+=("$ip")
PASSWORDS+=("$p")
done
IFS=$'\n' sorted_ips=($(sort -n <<<"${IPS[*]}"))
unset IFS
SERVER_IP="${sorted_ips[0]}"
CLIENT_IPS=("${sorted_ips[@]:1}")
CURRENT_IP=$(hostname -I | awk '{print $1}')
if [ "$CURRENT_IP" == "$SERVER_IP" ]; then
log_info "当前主机为 Ambari Server 节点 ($SERVER_IP),开始安装..."
# 安装 MySQL Connector/J(确保 TARGET_JAR 存在)
sshpass -p "${PASSWORDS[0]}" ssh -o StrictHostKeyChecking=no "${USERS[0]}@$SERVER_IP" bash <<EOF
set -ex
mkdir -p /opt/modules/mysql-connector
if [ ! -f "${TARGET_JAR}" ]; then
wget -q "${CONNECTOR_URL}" -O /opt/modules/mysql-connector/mysql-connector-java.tar.gz
tar -xzf /opt/modules/mysql-connector/mysql-connector-java.tar.gz -C /opt/modules/mysql-connector
sudo mkdir -p /usr/share/java
sudo cp /opt/modules/mysql-connector/mysql-connector-java-5.1.48/${CONNECTOR_JAR} "${TARGET_JAR}"
fi
EOF
# 在本地构造 HOSTS_SQL 字符串(各 IP 的 GRANT 语句)
HOSTS_SQL=""
for ip in "${IPS[@]}"; do
HOSTS_SQL+="GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'$ip' IDENTIFIED BY '$AMBARI_DB_PASSWORD' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'hive'@'$ip' IDENTIFIED BY '$HIVE_DB_PASSWORD' WITH GRANT OPTION;
"
done
sshpass -p "${PASSWORDS[0]}" ssh -o StrictHostKeyChecking=no "${USERS[0]}@$SERVER_IP" bash <<EOF
set -e
mysql -uroot -p"${ROOT_PASSWORD}" <<EOFSQL
CREATE DATABASE IF NOT EXISTS ambari;
CREATE DATABASE IF NOT EXISTS hive;
CREATE USER IF NOT EXISTS 'ambari'@'%' IDENTIFIED BY '$AMBARI_DB_PASSWORD';
CREATE USER IF NOT EXISTS 'hive'@'%' IDENTIFIED BY '$HIVE_DB_PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'%' IDENTIFIED BY '$AMBARI_DB_PASSWORD' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'localhost' IDENTIFIED BY '$AMBARI_DB_PASSWORD' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' IDENTIFIED BY '$HIVE_DB_PASSWORD' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'hive'@'localhost' IDENTIFIED BY '$HIVE_DB_PASSWORD' WITH GRANT OPTION;
${HOSTS_SQL}
FLUSH PRIVILEGES;
EOFSQL
EOF
# 先执行一次非交互式 setup 命令
sshpass -p "${PASSWORDS[0]}" ssh -o StrictHostKeyChecking=no "${USERS[0]}@$SERVER_IP" bash <<EOF
set -e
sudo yum install -y ambari-server
source /etc/profile
ambari-server setup --jdbc-db=mysql --jdbc-driver="${TARGET_JAR}"
EOF
# 然后使用 expect 自动应答 setup 后续交互提示
sshpass -p "${PASSWORDS[0]}" ssh -o StrictHostKeyChecking=no "${USERS[0]}@$SERVER_IP" bash <<EOF
set -e
expect -c "
set timeout -1
spawn ambari-server setup --java-home /usr/jdk64/jdk17 --stack-java-home /usr/jdk64/jdk1.8
expect \"Customize user account for ambari-server daemon\"
send \"n\r\"
expect {
\"Completing setup...\" {
}
\"Enable Ambari Server to download and install GPL\" {
send \"y\r\"
}
}
expect \"Enter advanced database configuration\"
send \"y\r\"
expect \"Choose one of the following options:\"
send \"3\r\"
expect \"Hostname\"
send \"${SERVER_IP}\r\"
expect \"Port\"
send \"3306\r\"
expect \"Database name\"
send \"ambari\r\"
expect \"Username\"
send \"ambari\r\"
expect \"Enter Database Password\"
send \"ambari\r\"
expect {
\"Configuring ambari database...\" {
}
\"Re-enter password: \" {
send \"ambari\r\"
}
}
expect {
\"Configuring remote database connection properties...\" {
}
\"Should ambari use existing default jdbc\" {
send \"y\r\"
}
}
expect \"Proceed with configuring remote database connection properties\"
send \"y\r\"
expect eof
"
EOF
# DDL 初始化和启动 Ambari Server(直接在远程展开 DDL_PATH)
sshpass -p "${PASSWORDS[0]}" ssh -o StrictHostKeyChecking=no "${USERS[0]}@$SERVER_IP" bash <<EOF
set -e
echo "执行 Ambari DDL 脚本..."
if [ ! -f "$DDL_PATH" ]; then
echo "错误:DDL 文件 $DDL_PATH 不存在!可能是 Ambari Server 尚未正确安装。"
exit 1
fi
RESULT=\$(mysql -u ambari -p"${AMBARI_DB_PASSWORD}" -D ambari -N -e "SHOW TABLES LIKE 'metainfo';" 2>/dev/null)
if [ "\$RESULT" == "metainfo" ]; then
echo "DDL 脚本已经执行过,跳过初始化。"
else
echo "DDL 尚未执行,开始初始化..."
mysql -u ambari -p"${AMBARI_DB_PASSWORD}" ambari <"$DDL_PATH"
echo "Ambari DDL 脚本执行完成。"
fi
echo "启动 Ambari Server..."
ambari-server restart
echo "Ambari Server 已启动并设置为开机自启。"
sudo yum install -y ambari-agent
ambari-agent restart
EOF
else
log_info "当前主机非 Ambari Server 节点,跳过安装。"
fi
log_info "Ambari 安装完成。"
}
##############################
# 主函数:依次执行所有步骤
##############################
function main() {
pre_install_tools
pre_setup_passwordless_ssh
pre_update_hosts_file
pre_setup_ntp_sync
pre_setup_nginx
pre_check_jdk
pre_check_mysql_conn
pre_check_yum_package
pre_check_local_yum
pre_check_mariadb_config
install_ambari
log_info "Ambari 集群环境安装全部完成。"
}
main
log_info "请查看日志:$LOGFILE"
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
# 2️⃣ 配置 hosts.txt
在解压后的目录中,找到 hosts.txt
文件,并按照以下格式填写 需要安装的集群节点信息:
📌 格式说明
<用户名> <密码> <IP地址>
1
✅ 示例
root Tt3832514048 192.168.3.1
root Tt3832514048 192.168.3.2
root Tt3832514048 192.168.3.3
1
2
3
2
3
📌 注意事项
- 每行填写一台服务器的信息
- 确保密码正确,IP 地址可访问
- 确保
hosts.txt
文件与安装脚本位于同一目录
# 3️⃣ 运行安装脚本
hosts.txt
配置完成后,执行以下命令启动安装过程:
bash install.sh
1
📌 文件示例


安装脚本会自动解析 hosts.txt
,并在所有集群节点上执行安装任务。
# 4️⃣ 安装过程截图
✅ 初始化 MariaDB

✅ 自动化执行 ambari-setup

✅ 集群启动成功
