Some checks failed
Test / test (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
333 lines
7.7 KiB
Bash
Executable File
333 lines
7.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Complete Deployment Script for Proxmox Network Configuration
|
|
# Updates network config and cluster IPs
|
|
|
|
set -e
|
|
|
|
# Server configuration
|
|
PVE_IP="192.168.1.207"
|
|
PVE2_IP="192.168.1.55"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m'
|
|
|
|
log_info() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
log_warn() {
|
|
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
log_header() {
|
|
echo -e "${CYAN}========================================${NC}"
|
|
echo -e "${CYAN}$1${NC}"
|
|
echo -e "${CYAN}========================================${NC}"
|
|
}
|
|
|
|
# Determine which server this is running on
|
|
detect_server() {
|
|
HOSTNAME=$(hostname)
|
|
CURRENT_IP=$(ip addr show | grep "192.168.1" | head -1 | awk '{print $2}' | cut -d/ -f1)
|
|
|
|
if [[ "$HOSTNAME" == "pve"* ]] || [[ "$CURRENT_IP" == "192.168.1.207" ]]; then
|
|
SERVER="pve"
|
|
SERVER_IP="192.168.1.207"
|
|
OTHER_SERVER="pve2"
|
|
OTHER_IP="192.168.1.55"
|
|
log_info "Detected: pve (ML110) - $SERVER_IP"
|
|
elif [[ "$HOSTNAME" == "pve2"* ]] || [[ "$CURRENT_IP" == "192.168.1.55" ]]; then
|
|
SERVER="pve2"
|
|
SERVER_IP="192.168.1.55"
|
|
OTHER_SERVER="pve"
|
|
OTHER_IP="192.168.1.207"
|
|
log_info "Detected: pve2 (R630) - $SERVER_IP"
|
|
else
|
|
log_error "Cannot detect server. Please specify:"
|
|
log_info " SERVER=pve ./complete-deployment.sh (for ML110)"
|
|
log_info " SERVER=pve2 ./complete-deployment.sh (for R630)"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
configure_network_pve() {
|
|
log_header "Configuring Network - pve (ML110)"
|
|
|
|
# Backup
|
|
cp /etc/network/interfaces /etc/network/interfaces.backup.$(date +%Y%m%d_%H%M%S)
|
|
|
|
# Detect interfaces (use first two physical)
|
|
NIC1=$(ls -d /sys/class/net/nic* /sys/class/net/eth* 2>/dev/null | head -1 | xargs basename)
|
|
NIC2=$(ls -d /sys/class/net/nic* /sys/class/net/eth* 2>/dev/null | head -2 | tail -1 | xargs basename)
|
|
|
|
if [ -z "$NIC1" ] || [ -z "$NIC2" ]; then
|
|
log_error "Could not detect NICs"
|
|
exit 1
|
|
fi
|
|
|
|
log_info "Using NIC 1: $NIC1 (vmbr0 - LAN)"
|
|
log_info "Using NIC 2: $NIC2 (vmbr1 - WAN)"
|
|
|
|
# Create configuration
|
|
cat > /etc/network/interfaces <<EOF
|
|
# Proxmox VE Network Configuration
|
|
# pve (ML110) - 192.168.1.207
|
|
# Generated: $(date)
|
|
|
|
# Loopback
|
|
auto lo
|
|
iface lo inet loopback
|
|
|
|
# Physical interface 1 (LAN)
|
|
auto $NIC1
|
|
iface $NIC1 inet manual
|
|
|
|
# vmbr0 - LAN Bridge
|
|
auto vmbr0
|
|
iface vmbr0 inet dhcp
|
|
bridge-ports $NIC1
|
|
bridge-stp off
|
|
bridge-fd 0
|
|
bridge-vlan-aware no
|
|
metric 200
|
|
|
|
# Physical interface 2 (WAN)
|
|
auto $NIC2
|
|
iface $NIC2 inet manual
|
|
|
|
# vmbr1 - WAN Bridge
|
|
auto vmbr1
|
|
iface vmbr1 inet dhcp
|
|
bridge-ports $NIC2
|
|
bridge-stp off
|
|
bridge-fd 0
|
|
bridge-vlan-aware no
|
|
metric 100
|
|
EOF
|
|
|
|
log_info "Network configuration written"
|
|
}
|
|
|
|
configure_network_pve2() {
|
|
log_header "Configuring Network - pve2 (R630)"
|
|
|
|
# Backup
|
|
cp /etc/network/interfaces /etc/network/interfaces.backup.$(date +%Y%m%d_%H%M%S)
|
|
|
|
log_info "Using nic3 for vmbr0 (LAN)"
|
|
log_info "Using nic2 for vmbr1 (WAN)"
|
|
|
|
# Create configuration
|
|
cat > /etc/network/interfaces <<EOF
|
|
# Proxmox VE Network Configuration
|
|
# pve2 (R630) - 192.168.1.55
|
|
# Generated: $(date)
|
|
# nic3: LAN (192.168.1.0/24)
|
|
# nic2: WAN (Public IP from Spectrum modem)
|
|
|
|
# Loopback
|
|
auto lo
|
|
iface lo inet loopback
|
|
|
|
# Physical interface: nic3 (LAN)
|
|
auto nic3
|
|
iface nic3 inet manual
|
|
|
|
# vmbr0 - LAN Bridge on nic3
|
|
auto vmbr0
|
|
iface vmbr0 inet dhcp
|
|
bridge-ports nic3
|
|
bridge-stp off
|
|
bridge-fd 0
|
|
bridge-vlan-aware no
|
|
metric 200
|
|
|
|
# Physical interface: nic2 (WAN)
|
|
auto nic2
|
|
iface nic2 inet manual
|
|
|
|
# vmbr1 - WAN Bridge on nic2
|
|
auto vmbr1
|
|
iface vmbr1 inet dhcp
|
|
bridge-ports nic2
|
|
bridge-stp off
|
|
bridge-fd 0
|
|
bridge-vlan-aware no
|
|
metric 100
|
|
EOF
|
|
|
|
log_info "Network configuration written"
|
|
}
|
|
|
|
update_hosts_file() {
|
|
log_header "Updating /etc/hosts"
|
|
|
|
# Backup
|
|
cp /etc/hosts /etc/hosts.backup.$(date +%Y%m%d_%H%M%S)
|
|
|
|
# Remove old entries
|
|
sed -i "/$OTHER_SERVER/d" /etc/hosts
|
|
|
|
# Add new entry
|
|
echo "$OTHER_IP $OTHER_SERVER $OTHER_SERVER.local" >> /etc/hosts
|
|
|
|
log_info "Updated /etc/hosts with $OTHER_SERVER -> $OTHER_IP"
|
|
}
|
|
|
|
update_corosync_conf() {
|
|
log_header "Updating corosync.conf"
|
|
|
|
COROSYNC_FILE="/etc/pve/corosync.conf"
|
|
|
|
if [ ! -f "$COROSYNC_FILE" ]; then
|
|
log_warn "corosync.conf not found - cluster may not be configured"
|
|
return
|
|
fi
|
|
|
|
# Backup
|
|
cp "$COROSYNC_FILE" "${COROSYNC_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
|
|
# Update ring0_addr entries
|
|
sed -i "s/ring0_addr:.*pve$/ring0_addr: 192.168.1.207/" "$COROSYNC_FILE"
|
|
sed -i "s/ring0_addr:.*pve2$/ring0_addr: 192.168.1.55/" "$COROSYNC_FILE"
|
|
|
|
log_info "Updated corosync.conf with new IPs"
|
|
|
|
# Show updated config
|
|
log_info "Updated configuration:"
|
|
grep ring0_addr "$COROSYNC_FILE" | sed 's/^/ /'
|
|
}
|
|
|
|
apply_network_config() {
|
|
log_header "Applying Network Configuration"
|
|
|
|
log_warn "This will restart networking and may temporarily disconnect you"
|
|
read -p "Continue? (yes/no): " CONFIRM
|
|
|
|
if [ "$CONFIRM" != "yes" ]; then
|
|
log_info "Skipping network apply"
|
|
return
|
|
fi
|
|
|
|
log_info "Applying network configuration..."
|
|
ifreload -a || systemctl restart networking
|
|
|
|
log_info "Waiting for DHCP..."
|
|
sleep 5
|
|
|
|
log_info "Current IP addresses:"
|
|
ip addr show | grep -E "vmbr|inet " | head -10
|
|
}
|
|
|
|
restart_cluster_services() {
|
|
log_header "Restarting Cluster Services"
|
|
|
|
log_warn "This will restart cluster services"
|
|
read -p "Continue? (yes/no): " CONFIRM
|
|
|
|
if [ "$CONFIRM" != "yes" ]; then
|
|
log_info "Skipping cluster restart"
|
|
log_info "Manually restart with: systemctl restart corosync && systemctl restart pve-cluster"
|
|
return
|
|
fi
|
|
|
|
systemctl restart corosync
|
|
sleep 2
|
|
systemctl restart pve-cluster
|
|
|
|
log_info "Cluster services restarted"
|
|
}
|
|
|
|
verify_deployment() {
|
|
log_header "Verification"
|
|
|
|
log_info "Network Status:"
|
|
echo ""
|
|
echo "Bridges:"
|
|
ip link show type bridge 2>/dev/null | grep -oP '^\d+: \K[^:]+' | while read br; do
|
|
IP=$(ip addr show $br 2>/dev/null | grep "inet " | awk '{print $2}' | head -1)
|
|
echo " $br: ${IP:-No IP}"
|
|
done
|
|
|
|
echo ""
|
|
echo "Routing:"
|
|
ip route show | head -5
|
|
|
|
echo ""
|
|
if [ -f /etc/pve/corosync.conf ]; then
|
|
log_info "Cluster Configuration:"
|
|
grep ring0_addr /etc/pve/corosync.conf | sed 's/^/ /'
|
|
|
|
echo ""
|
|
log_info "Cluster Status:"
|
|
pvecm status 2>/dev/null || log_warn "Could not get cluster status"
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
log_header "Complete Proxmox Deployment"
|
|
echo ""
|
|
|
|
# Detect server
|
|
if [ -n "$SERVER" ]; then
|
|
if [ "$SERVER" = "pve" ]; then
|
|
SERVER_IP="192.168.1.207"
|
|
OTHER_SERVER="pve2"
|
|
OTHER_IP="192.168.1.55"
|
|
else
|
|
SERVER_IP="192.168.1.55"
|
|
OTHER_SERVER="pve"
|
|
OTHER_IP="192.168.1.207"
|
|
fi
|
|
else
|
|
detect_server
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Network configuration
|
|
if [ "$SERVER" = "pve2" ]; then
|
|
configure_network_pve2
|
|
else
|
|
configure_network_pve
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Update cluster configuration
|
|
update_hosts_file
|
|
update_corosync_conf
|
|
|
|
echo ""
|
|
|
|
# Apply network
|
|
apply_network_config
|
|
|
|
echo ""
|
|
|
|
# Restart cluster (if configured)
|
|
if [ -f /etc/pve/corosync.conf ]; then
|
|
restart_cluster_services
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Verify
|
|
verify_deployment
|
|
|
|
echo ""
|
|
log_header "Deployment Complete!"
|
|
}
|
|
|
|
main "$@"
|
|
|