#!/bin/bash # Proxmox VE - VM 생성 스크립트 # 목적: 단일 VM 생성 및 설정 # 사용법: ./proxmox/create_vm.sh # 실행: root 계정에서만 가능 set -e # 색상 정의 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # 함수: 메시지 출력 print_info() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[✓]${NC} $1" } print_warning() { echo -e "${YELLOW}[⚠]${NC} $1" } print_error() { echo -e "${RED}[✗]${NC} $1" } # Root 권한 확인 if [[ $EUID -ne 0 ]]; then print_error "이 스크립트는 root 권한으로 실행되어야 합니다." exit 1 fi # Proxmox 설치 여부 확인 if ! command -v qm &> /dev/null; then print_error "Proxmox VE가 설치되어 있지 않습니다." exit 1 fi # 기본값 DEFAULT_MEMORY=2048 DEFAULT_CORES=2 DEFAULT_DISK=30 DEFAULT_ISO="local:iso/Rocky-9.0-latest.iso" print_info "==========================================" print_info "Proxmox VE - VM 생성" print_info "==========================================" echo "" # 사용자 입력 read -p "VM ID (예: 101): " VM_ID if [[ -z "$VM_ID" ]]; then print_error "VM ID는 필수입니다." exit 1 fi # VM ID가 이미 존재하는지 확인 if qm status "$VM_ID" &>/dev/null 2>&1; then print_error "VM ID $VM_ID가 이미 존재합니다." exit 1 fi read -p "VM 이름 (예: vm1-php82): " VM_NAME if [[ -z "$VM_NAME" ]]; then print_error "VM 이름은 필수입니다." exit 1 fi read -p "메모리 (MB) [기본값: $DEFAULT_MEMORY]: " VM_MEMORY VM_MEMORY="${VM_MEMORY:-$DEFAULT_MEMORY}" read -p "CPU 코어 [기본값: $DEFAULT_CORES]: " VM_CORES VM_CORES="${VM_CORES:-$DEFAULT_CORES}" read -p "디스크 (GB) [기본값: $DEFAULT_DISK]: " VM_DISK VM_DISK="${VM_DISK:-$DEFAULT_DISK}" read -p "ISO 경로 [기본값: $DEFAULT_ISO]: " ISO_PATH ISO_PATH="${ISO_PATH:-$DEFAULT_ISO}" # 설정 요약 print_info "==========================================" print_info "설정 요약" print_info "==========================================" echo "" echo "ID: $VM_ID" echo "이름: $VM_NAME" echo "메모리: ${VM_MEMORY}MB" echo "CPU: ${VM_CORES} Core" echo "디스크: ${VM_DISK}GB" echo "ISO: $ISO_PATH" echo "" read -p "위 설정으로 VM을 생성하시겠습니까? (y/n): " CONFIRM if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then print_warning "취소되었습니다." exit 0 fi # VM 생성 print_info "VM 생성 중..." qm create "$VM_ID" \ --name "$VM_NAME" \ --memory "$VM_MEMORY" \ --cores "$VM_CORES" \ --scsihw virtio-scsi-pci \ --scsi0 "local-lvm:${VM_DISK}" \ --net0 virtio,bridge=vmbr0 \ --cdrom "$ISO_PATH" \ --serial0 socket \ --boot c if [ $? -eq 0 ]; then print_success "VM 생성 완료!" echo "" print_info "다음 단계:" echo "1. VM 시작: qm start $VM_ID" echo "2. Proxmox 웹 UI에서 VM 콘솔로 접속하여 Rocky Linux 설치" echo "3. 설치 중 사용자 계정 생성 (권장: firstgarden)" echo "4. 설치 완료 후 다음 명령어 실행:" echo "" echo " SSH로 VM에 접속:" echo " ssh firstgarden@" echo "" echo " 스크립트 실행:" echo " curl -fsSL https://git.siane.kr/firstgarden/cafe24-testserver/archive/main.tar.gz | tar xz" echo " cd cafe24-testserver-main" echo " chmod +x vm/setup_common.sh && ./vm/setup_common.sh" echo " chmod +x vm/install_php.sh" echo "" echo " PHP 8.2 또는 8.4 설치:" echo " ./vm/install_php.sh 8.2 # 또는 8.4" echo "" else print_error "VM 생성에 실패했습니다." exit 1 fi