You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过单脚本实现Hortonworks集群多节点Ambari Server重启

One-Click Script to Start/Stop Ambari Server Across All Hortonworks Cluster Nodes

Hey there! Since you already have passwordless SSH configured for root across all your cluster nodes, putting together a simple script to handle Ambari Server start/stop on every node in one go is totally straightforward. Here's exactly how to set this up:

Step 1: Create a Node List File

First, make a text file that lists all your cluster nodes (hostnames or IP addresses), one per line. Let's name it ambari_nodes.txt:

nano ambari_nodes.txt

Add entries like:

node01.example.com
node02.example.com
node03.example.com

Save and exit the editor once you've added all nodes.

Step 2: Write the Control Script

Create a shell script (let's call it ambari_control.sh) with the following content. This script accepts a start or stop argument and runs the corresponding command on every node in your list:

#!/bin/bash

# Check if a valid command argument was provided
if [ $# -ne 1 ]; then
    echo "Usage: $0 {start|stop}"
    exit 1
fi

COMMAND=$1
NODE_LIST="./ambari_nodes.txt"

# Validate the input command
if [ "$COMMAND" != "start" ] && [ "$COMMAND" != "stop" ]; then
    echo "Invalid command. Please use 'start' or 'stop'."
    exit 1
fi

# Loop through each node and execute the Ambari Server command
while read -r NODE; do
    if [ -n "$NODE" ]; then
        echo "--- Running '$COMMAND' on $NODE ---"
        ssh root@$NODE "ambari-server $COMMAND"
        echo "--- Finished $COMMAND on $NODE ---"
        echo ""
    fi
done < "$NODE_LIST"

echo "Ambari Server $COMMAND operation completed across all nodes."

Step 3: Make the Script Executable

Give the script execute permissions so you can run it directly:

chmod +x ambari_control.sh

Step 4: Use the Script

  • To start Ambari Server on all nodes:
    ./ambari_control.sh start
    
  • To stop Ambari Server on all nodes:
    ./ambari_control.sh stop
    

Quick Notes to Keep in Mind

  • Check Ambari Path: If your Ambari Server binary isn't in the default /usr/sbin/ambari-server location, update the script to use the full path (e.g., /opt/ambari/bin/ambari-server).
  • Confirm Passwordless SSH: Double-check that root can SSH into every node without a password prompt—this is essential for the script to run unattended.
  • Ambari Server vs Agent: A quick heads-up: Typically, Ambari Server runs on a single master node, while Ambari Agents run on all cluster nodes. If you meant to control Agents instead, just replace ambari-server with ambari-agent in the script.

内容的提问来源于stack exchange,提问作者Darshan Manek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:56:44