Apache Ambari 裸机和 KVM 环境设置
本指南说明如何配置现有裸机服务器或 KVM 虚拟机以安装 Apache Ambari。假设你已有至少 3 台可用的物理或虚拟机器,重点介绍为 Ambari 部署准备所需的系统配置。
前提条件
- 至少 3 台机器(物理服务器或 KVM 虚拟机)
- 所有机器上安装 Rocky Linux 8(或兼容的 RHEL 系列发行版)
- 对所有机器具有 root 访问权限
- 所有机器之间具有网络连通性
机器角色
对于基本 Ambari 集群,需要为机器指定以下角色:
- 机器 1: Ambari Server
- 机器 2、3、...: Ambari Agents
所有机器都需要类似的基础配置,Ambari Server 还需要一些特定设置。
1. 配置主机名和网络
1.1 设置主机名
如果尚未为机器配置主机名,可以按如下方式设置:
# Example hostname configuration (only if needed)
sudo hostnamectl set-hostname your-preferred-hostname
选择的具体主机名并不重要,但应满足:
- 在所有机器中唯一
- 尽可能使用完全限定域名(FQDN)
- 与网络命名约定一致
如果已配置主机名,可以跳过此步骤。
1.2 在所有机器上配置 /etc/hosts
通过编辑每台机器上的 /etc/hosts 文件,确保所有机器都能解析彼此的主机名:
# Login as root
sudo su -
# Edit the hosts file
vi /etc/hosts
# Add entries for all machines (use your actual IP addresses and hostnames)
192.168.1.10 server-hostname
192.168.1.11 agent-machine1-hostname
192.168.1.12 agent-machine2-hostname
# Add more entries for additional machines
确保所有机器上的这些更改完全一致。此步骤对 Ambari 正常运行至关重要,因为服务器与 Agent 之间的通信依赖主机名解析。
2. 配置安全设置
2.1 Disable SELinux on All Machines
# Temporarily disable SELinux
setenforce 0
# Permanently disable SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
2.2 在所有机器上配置防火墙
对于开发环境,可以禁用防火墙:
# Disable and stop firewalld
systemctl disable firewalld
systemctl stop firewalld
3. 配置 SSH 访问
与 Vagrant 环境设置类似,需要配置从 Ambari Server 到所有 Agent 机器的免密码 SSH 访问。
3.1 在服务器机器上生成 SSH 密钥
# Login as root on the server machine
sudo su -
# Generate SSH key if not exists
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
fi
3.2 配置 SSH 密码认证
如果尚未配置,请在所有机器上编辑 SSH 配置:
# Edit sshd_config
vi /etc/ssh/sshd_config
# Ensure these lines are set
PasswordAuthentication yes
PermitRootLogin yes
# Restart SSH service
systemctl restart sshd
3.3 Distribute SSH Keys from Server to Agents
在 Ambari 服务器机器上,将 SSH 密钥复制到每台 Agent 机器:
# Copy SSH key to all agent machines (replace with your actual hostnames)
ssh-copy-id -o StrictHostKeyChecking=no root@agent-machine1-hostname
ssh-copy-id -o StrictHostKeyChecking=no root@agent-machine2-hostname
# Repeat for additional agent machines
# Test SSH connections (replace with your actual hostnames)
ssh root@agent-machine1-hostname echo "Connection successful"
ssh root@agent-machine2-hostname echo "Connection successful"
# Test additional connections as needed
4. 在所有机器上安装所需软件包
4.1 更新系统并安装基本工具
在所有机器上运行这些命令:
# Update package lists and upgrade packages
dnf update -y
# Install basic utilities
dnf install -y sudo openssh-server openssh-clients which iproute net-tools less vim-enhanced
dnf install -y wget curl tar unzip git
4.2 启用开发仓库
必须在所有机器上启用 Rocky Linux 开发仓库,以安装 Ambari 所需的依赖:
# Edit the Rocky-Devel repository configuration
vi /etc/yum.repos.d/Rocky-Devel.repo
# There are two possible scenarios:
# 1. If all lines are commented (start with #), uncomment all lines
# 2. If you see "enabled=0", change it to "enabled=1"
# After editing, verify the repository is enabled
dnf repolist | grep devel
4.3 在所有机器上安装 Java
# Install OpenJDK 8
dnf install -y java-1.8.0-openjdk-devel
# Verify Java installation
java -version
5. 配置网络时间协议(NTP)
同步所有机器上的时间:
# Install chrony (NTP implementation)
dnf install -y chrony
# Start and enable chronyd service
systemctl start chronyd
systemctl enable chronyd
# Verify time synchronization
chronyc sources
6. 验证环境
6.1 检查网络连通性
在服务器机器上测试与所有 Agent 机器的连通性:
# Test connectivity to all agent machines (replace with your actual hostnames)
ping -c 2 agent-machine1-hostname
ping -c 2 agent-machine2-hostname
# Test additional machines as needed
6.2 验证 SSH 访问
在服务器机器上验证对所有 Agent 机器的 SSH 访问:
# Verify SSH access to all agent machines (replace with your actual hostnames)
ssh root@agent-machine1-hostname hostname
ssh root@agent-machine2-hostname hostname
# Verify additional machines as needed
6.3 验证安全设置
# Check SELinux status on all machines (replace with your actual hostnames)
for host in server-hostname agent-machine1-hostname agent-machine2-hostname; do
echo "=== $host SELinux Status ==="
ssh root@$host getenforce # Should show 'Disabled'
done
# Check firewall status on all machines (replace with your actual hostnames)
for host in server-hostname agent-machine1-hostname agent-machine2-hostname; do
echo "=== $host Firewall Status ==="
ssh root@$host systemctl status firewalld # Should show 'inactive' for dev environments
done
故障排除
网络问题
# Check network interfaces
ip addr show
# Test DNS resolution (replace with your actual hostnames)
nslookup server-hostname
nslookup agent-machine1-hostname
nslookup agent-machine2-hostname
SSH 问题
# Check SSH service status
systemctl status sshd
# Verify SSH key permissions
ls -la ~/.ssh/
# Check SSH configuration
cat /etc/ssh/sshd_config | grep PasswordAuthentication
cat /etc/ssh/sshd_config | grep PermitRootLogin
SELinux 问题
即使禁用 SELinux 后仍遇到权限问题:
# Verify SELinux is disabled
getenforce
# If it shows 'Enforcing', disable it again
setenforce 0
后续步骤
裸机或 KVM 环境配置完成后,继续阅读安装指南,安装并配置 Ambari Server 和 Agent。安装指南提供适用于所有环境(Vagrant、Docker 和裸机/KVM)的标准说明。
阅读安装指南时请记住:
- 所有命令都应以 root 身份运行
- 在指定服务器机器上
- 在所有机器上运行 Ambari Agent 安装
- 通过服务器机器的 IP 地址和 8080 端口访问 Ambari Web UI (http://server-hostname:8080)