본문 바로가기

리눅스

CentOS Stream 10에서 PXE 서버를 구성하는 방법

728x90
반응형

CentOS Stream 10에서 PXE 서버를 구성하는 방법

firewalld 비활성화

sudo systemctl list-unit-files | grep -E '(firewalld|nftables)'
sudo systemctl disable --now firewalld nftables

SELinux 비활성화

즉시 비활성화

sudo setenforce 0

영구적으로 비활성화

sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
reboot

재부팅 후 확인

getenforce

패키지 설치

 sudo dnf install -y \
  kea \
  tftp-server \
  syslinux \
  syslinux-tftpboot

서비스 활성화

sudo systemctl enable --now kea-dhcp4.service
sudo systemctl enable --now tftp.socket tftp.service

DHCP(kea) 서버 설정

sudo cp /etc/kea/kea-dhcp4.conf /etc/kea/kea-dhcp4.conf_$(date '+%Y%m%d_%H%M%S')
sudo tee /etc/kea/kea-dhcp4.conf << 'EOF'
{
"Dhcp4": {
    "interfaces-config": {
        "interfaces": ["enp0s3"]
    },
    
    "lease-database": {
        "type": "memfile",
        "persist": true,
        "name": "/var/lib/kea/dhcp4.leases"
    },
    
    "valid-lifetime": 4000,
    "renew-timer": 1000,
    "rebind-timer": 2000,
    
    "subnet4": [
        {
            "subnet": "192.168.10.0/24",
            "pools": [
                {
                    "pool": "192.168.10.106 - 192.168.10.120"
                }
            ],
            "option-data": [
                {
                    "name": "routers",
                    "data": "192.168.10.1"
                },
                {
                    "name": "domain-name-servers",
                    "data": "8.8.8.8"
                },
                {
                    "name": "boot-file-name",
                    "data": "pxelinux.0"
                },
                {
                    "name": "next-server",
                    "data": "192.168.10.100"
                }
            ]
        }
    ],
    
    "loggers": [
        {
            "name": "kea-dhcp4",
            "severity": "INFO",
            "debuglevel": 0
        }
    ]
}
}
EOF
sudo systemctl restart kea-dhcp4.service
sudo systemctl status kea-dhcp4.service

TFTP 서버 + PXELINUX 구성

TFTP Root

sudo mkdir -p /var/lib/tftpboot/pxelinux.cfg

PXELINUX 파일 복사

sudo cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
sudo cp /usr/share/syslinux/{menu.c32,ldlinux.c32,libutil.c32,libcom32.c32} \
  /var/lib/tftpboot/

권한 설정

#sudo chown -R tftp:tftp /var/lib/tftpboot
sudo chmod -R 755 /var/lib/tftpboot

Nginx 설치

sudo yum install -y yum-utils
sudo tee /etc/yum.repos.d/nginx.repo << 'EOF'
[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=https://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
sudo yum install -y nginx

Nginx HTTP 서버 설정

sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf_$(date '+%Y%m%d_%H%M%S')
sudo tee /etc/nginx/conf.d/default.conf << 'EOF'
server {
    listen 80;
    server_name _;

    client_max_body_size 0;

    location / {
        root /usr/share/nginx/html;
        autoindex on;
    }

    location /ubuntu/ {
        alias /usr/share/nginx/html/ubuntu/;
        autoindex on;
    }

    location /autoinstall/ {
        alias /usr/share/nginx/html/autoinstall/;
        autoindex on;
        default_type text/plain;
    }
}
EOF
sudo nginx -t
sudo systemctl restart nginx

우분투 ISO 준비(HTTP Repository)

디렉터리 생성

sudo mkdir -p /usr/share/nginx/html/{iso,ubuntu/24.04}

ISO 다운로드 및 풀기

cd /usr/share/nginx/html/iso
wget https://releases.ubuntu.com/24.04/ubuntu-24.04.3-live-server-amd64.iso

sudo mount -o loop,ro ubuntu-24.04.3-live-server-amd64.iso /mnt
sudo cp -r /mnt/* /usr/share/nginx/html/ubuntu/24.04/
sudo umount /mnt

casper squashfs 링크

cd /usr/share/nginx/html/ubuntu/24.04/casper
ln -s ubuntu-server-minimal.ubuntu-server.installer.squashfs filesystem.squashfs

커널/initrd(TFTP용)

sudo cp /usr/share/nginx/html/ubuntu/24.04/casper/vmlinuz \
  /var/lib/tftpboot/vmlinuz-ubuntu2404

sudo cp /usr/share/nginx/html/ubuntu/24.04/casper/initrd \
  /var/lib/tftpboot/initrd-ubuntu2404

cloud-init(Autoinstall)

sudo mkdir -p /usr/share/nginx/html/autoinstall

meta-data

sudo tee /usr/share/nginx/html/autoinstall/meta-data << 'EOF'
instance-id: ubuntu-pxe
local-hostname: ubuntu-autoinstall
EOF

user-data

sudo tee /usr/share/nginx/html/autoinstall/user-data << 'EOF'
#cloud-config
autoinstall:
  version: 1
  locale: ko_KR.UTF-8
  keyboard:
    layout: kr
  timezone: Asia/Seoul

  identity:
    hostname: ubuntu
    username: ubuntu
    password: "$6$HASHED_PASSWORD"

  ssh:
    install-server: true
    allow-pw: true

  storage:
    layout:
      name: direct

  packages:
    - vim
    - curl
    - net-tools
EOF

PXE 부팅 메뉴(Ubuntu 전용)

sudo tee /var/lib/tftpboot/pxelinux.cfg/default << 'EOF'
DEFAULT menu.c32
PROMPT 0
TIMEOUT 300
MENU TITLE Ubuntu Autoinstall PXE (CentOS Stream 10)

LABEL ubuntu-2404
    MENU LABEL Install Ubuntu 24.04 (Autoinstall)
    KERNEL vmlinuz-ubuntu2404
    INITRD initrd-ubuntu2404
    APPEND ip=dhcp \
      boot=casper \
      netboot=http \
      casper-path=casper \
      autoinstall \
      ds=nocloud-net;s=http://192.168.10.100/autoinstall/ \
      url=http://192.168.10.100/ubuntu/24.04/ \
      fsck.mode=skip

LABEL local
    MENU LABEL Boot from local disk
    LOCALBOOT 0
EOF

서비스 재시작

sudo systemctl restart kea-dhcp4.service tftp.service nginx.service

정상 동작 체크 포인트

HTTP 접근

PXE 접근

 

Sudo Tee /Share/nginx/nginx/html/autonstall/meta-data << 'EOF' 인스턴스 ID: Ubuntu-PXe 로컬 호스트 이름: Ubuntu-autonstall EOF
 
728x90
반응형