반응형
    
    
    
  PXE + Kickstart 기반 CentOS 자동 설치 환경 구축하는 방법
SELinux 비활성화
perl -pi -e 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
reboot
기본 패키지 설치
PXE, DHCP, TFTP, NGINX를 위한 패키지를 설치합니다.
yum install -y tftp tftp-server syslinux-tftpboot xinetd dhcp dhcp-devel syslinux
yum install -y epel-release
yum install -y nginx
TFTP 설정
sed -i '/disable/ s/yes/no/' /etc/xinetd.d/tftp
DHCP 서버 설정
cat /usr/share/doc/dhcp*/dhcpd.conf.example > /etc/dhcp/dhcpd.conf
cat > /etc/dhcp/dhcpd.conf << "EOF"
Allow booting;
Allow bootp;
ddns-update-style none;
authoritative;
log-facility local7;
option pxe-system-type code 93 = unsigned integer 16;
subnet 192.168.0.0 netmask 255.255.255.0 {
     #option routers             192.168.0.1;
     #option domain-name-servers 192.168.0.1;
     #option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.0.210 192.168.0.240;
     default-lease-time         600;
     max-lease-time             7200;
     next-server                192.168.0.201;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "grub/grub-x86.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "grub/grub-x86_64.efi";
          } else if option pxe-system-type = 00:09 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }
}
EOF
NGINX 설정
cat > /etc/nginx/nginx.conf << "EOF"
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /apps/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
           autoindex on;
        }
        location /centos/ {
           alias /apps/nginx/html/repository/centos/;
           autoindex on;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}
EOF
ISO Mount & 파일 복사
설치용 ISO 이미지를 웹서버 경로로 복사합니다.
mkdir -p /apps/nginx/html/repository/centos/6.9/{isos,os}/x86_64
mkdir -p /apps/nginx/html/repository/centos/7.4/{isos,os}/x86_64
ln -s /apps/nginx/html/repository/centos/6.9 /apps/nginx/html/repository/centos/6
ln -s /apps/nginx/html/repository/centos/7.4 /apps/nginx/html/repository/centos/7
mount -t iso9660 -o loop CentOS-6.9-x86_64-bin-DVD1.iso /mnt
cp -rf /mnt/.discinfo ../../os/x86_64/.
cp -rf /mnt/{.discinfo,.treeinfo} ../../os/x86_64/.
mount -t iso9660 -o loop CentOS-7-x86_64-DVD-1708.iso /mnt
cp -rf /mnt/.discinfo ../../os/x86_64/.
cp -rf /mnt/{.discinfo,.treeinfo} ../../os/x86_64/.
Syslinux 부트 이미지 복사
TFTP용 PXE 부트 환경을 준비합니다.
mkdir -p /var/lib/tftpboot/{pxelinux.cfg,pxeboot}
mkdir -p /var/lib/tftpboot/pxeboot/{centos6,centos7}
cp /apps/nginx/html/repository/centos/6/os/x86_64/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/pxeboot/centos6/
cp /apps/nginx/html/repository/centos/7/os/x86_64/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/pxeboot/centos7/
cat > /var/lib/tftpboot/pxelinux.cfg/default << "EOF"
default menu.c32
prompt 0
timeout 300
ONTIMEOUT local
MENU TITLE Main Menu
MENU TITLE ########## PXE Boot Menu ##########
LABEL 1
        MENU LABEL ^1) Boot from local drive localboot
        LOCALBOOT 0
LABEL 2
        MENU LABEL ^2) Install CentOS 7.4 x86_64 Edition (64-bit)
        KERNEL pxeboot/centos7/vmlinuz
        append initrd=pxeboot/centos7/initrd.img ks=http://192.168.0.201/ks/ks-centos7_x64.cfg repo=http://192.168.0.201/centos/7/os/x86_64 ksdevice=link
        TEXT HELP
        Install CentOS 7.4 (64-bit)
        ENDTEXT
LABEL 3
        MENU LABEL ^3) Install CentOS 6.9 x86_64 Edition (64-bit)
        KERNEL pxeboot/centos6/vmlinuz
        APPEND initrd=pxeboot/centos6/initrd.img ks=http://192.168.0.201/ks/ks-centos6_x64.cfg load_ramdisk=1 ksdevice=link network
        TEXT HELP
        Install CentOS 6.9 (64-bit)
        ENDTEXT
EOF
Kickstart 자동 설치 파일 준비
CentOS 6.9용 Kickstart 예시
mkdir -p /apps/nginx/html/ks/
cat > /apps/nginx/html/ks/ks-centos6_x64.cfg << "EOF"
#platform=x86, AMD64, 또는 Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Do not configure the X Window System
skipx
# Use network installation
url --url="http://192.168.0.201/centos/6/os/x86_64"
# Root password
rootpw --iscrypted $1$rb4.hv78hu$3m7vWlDbMQkxUdsXWxEo.E.
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# Use text mode install
#text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# System language
#lang ko_KR
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Seoul
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=512
part swap --fstype="swap" --size=8192
part / --fstype="ext4" --grow --size=1
%packages
@base
@compat-libraries
@legacy-unix
@system-admin-tools
@system-management-snmp
%end
%post --log=/tmp/ks-post.log
#!/bin/sh
curl -o /root/security_script_centos6.sh http://192.168.0.201/post/security_script_centos6.sh
%end
EOF
CentOS 7.4용 Kickstart 예시
cat > /apps/nginx/html/ks/ks-centos7_x64.cfg  << "EOF"
#platform=x86, AMD64, 또는 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
#keyboard --vckeymap=kr --xlayouts='kr'
# Root password
rootpw --iscrypted $1$EMaZps876557$B2N1LKYvg1DiNYTQwVdLR0
# Use network installation
url --url="http://192.168.0.201/centos/7/os/x86_64"
# System language
lang en_US
#lang ko_KR.UTF-8
# System authorization information
auth  --useshadow  --passalgo=sha512
# Accept Eula
eula --agreed
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Seoul
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel --drives=sda
ignoredisk --only-use=sda
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=8192
part / --fstype="xfs" --grow --size=1
%packages
@^minimal
@core
chrony
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%post --log=/tmp/ks-post.log
#!/bin/sh
curl -o /root/security_script_centos7.sh http://192.168.0.201/post/security_script_centos7.sh
%end
EOF
Deamon Restart 스크립트
cat > /root/kss-restart.sh << "EOF"
#!/bin/sh
systemctl restart xinetd
systemctl restart dhcpd
systemctl restart nginx
EOF
chmod +x /root/kss-restart.sh
정리
DHCP + TFTP + NGINX + Kickstart 조합으로 네트워크 자동 설치 환경 구성
서버 전원을 켜면 PXE 부팅 → OS 선택 → Kickstart로 자동 설치 진행
728x90
    
    
  반응형
    
    
    
  '리눅스' 카테고리의 다른 글
| CentOS 6에 rsyslog 7을 설치하는 방법 (0) | 2018.06.08 | 
|---|---|
| CentOS 7에서 bonding과 teaming 차이점 및 구성 방법 (0) | 2018.05.23 | 
| GRUB VGA Modes (0) | 2018.05.09 | 
| Sysbench 설치 및 사용 방법 (0) | 2018.04.10 | 
| CentOS 7에서 GRUB2 부팅 순서 변경 방법 (0) | 2018.01.22 |