본문 바로가기

리눅스

[리눅스] 킥스타트로 설치 자동화하기

반응형

킥스타트로 설치 자동화하기

selinux

perl -pi -e 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

reboot

reboot

Packages Installation

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

dhcpd

cat /usr/share/doc/dhcp*/dhcpd.conf.example > /etc/dhcp/dhcpd.conf
cat > /etc/dhcp/dhcpd.conf << "EOF"
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

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 & COPY

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 COPY

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 File

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
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 700 /root/kss-restart.sh

 

728x90
반응형