photoncloud-monorepo/testing/qemu-cluster/scripts/start-cluster.sh

73 lines
1.9 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
IMAGES_DIR="$PROJECT_ROOT/testing/qemu-cluster/images"
VMS_DIR="$PROJECT_ROOT/testing/qemu-cluster/vms"
echo "Starting PhotonCloud QEMU Test Cluster..."
mkdir -p "$VMS_DIR"
BASE_IMAGE="$IMAGES_DIR/base.qcow2"
if [ ! -f "$BASE_IMAGE" ]; then
echo "Error: Base image not found: $BASE_IMAGE"
echo "Run ./scripts/create-base-image.sh first"
exit 1
fi
# VM設定
NODE01_IMAGE="$VMS_DIR/node-01.qcow2"
NODE02_IMAGE="$VMS_DIR/node-02.qcow2"
NODE01_MAC="52:54:00:12:34:01"
NODE02_MAC="52:54:00:12:34:02"
# ベースイメージからVMイメージを作成COW
if [ ! -f "$NODE01_IMAGE" ]; then
echo "Creating node-01 image..."
qemu-img create -f qcow2 -b "$BASE_IMAGE" -F qcow2 "$NODE01_IMAGE" 10G
fi
if [ ! -f "$NODE02_IMAGE" ]; then
echo "Creating node-02 image..."
qemu-img create -f qcow2 -b "$BASE_IMAGE" -F qcow2 "$NODE02_IMAGE" 10G
fi
# VMを起動
echo "Starting node-01..."
qemu-system-x86_64 \
-enable-kvm \
-name node-01 \
-m 2048 \
-smp 2 \
-hda "$NODE01_IMAGE" \
-netdev user,id=net0,hostfwd=tcp::2201-:22,hostfwd=tcp::18080-:18080 \
-device e1000,netdev=net0,mac="$NODE01_MAC" \
-nographic \
-daemonize \
-pidfile "$VMS_DIR/node-01.pid"
echo "Starting node-02..."
qemu-system-x86_64 \
-enable-kvm \
-name node-02 \
-m 2048 \
-smp 2 \
-hda "$NODE02_IMAGE" \
-netdev user,id=net0,hostfwd=tcp::2202-:22,hostfwd=tcp::18081-:18081 \
-device e1000,netdev=net0,mac="$NODE02_MAC" \
-nographic \
-daemonize \
-pidfile "$VMS_DIR/node-02.pid"
echo "Cluster started successfully!"
echo ""
echo "Access VMs:"
echo " node-01: ssh -p 2201 photon@localhost"
echo " node-02: ssh -p 2202 photon@localhost"
echo ""
echo "Stop cluster:"
echo " ./scripts/stop-cluster.sh"