· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Auto Installation

pxe 와 kickstart 이용하여 OS 자동설치하기

문태준 2006-09-27 20:15:01 http://tunelinux.pe.kr http://database.sarang.net


1. AutoInstallation 개략

리눅스 설치 자동화. 시스템자동화와 연관된 자료모음은 다음 사이트 참고 http://tunelinux.pe.kr/wikix/index.php?display=SystemAutomation

PXE 부팅을 이용하여 CD등 없이 원격에서 자동으로 부팅하고 설치는 kickstart 와 네트워크 설치를 이용하여 자동화한다. kickstart 를 이용하여 설치후 필요한 작업까지 넣어두면(post 항목 이용) 좀더 편리한 서버작업이 가능하다.

여기서는 pxe, kickstart, nfs, dhcp, tftp 서버등에 대해서는 설명을 하지 않겠다.

2. 사용 OS

RHEL ES 3.0 (RHEL 4.0 도 동일함) Cent OS 4.x

3. 참고자료

Red Hat Enterprise Linux 3: System Administration Guide Chapter 14. PXE Network Installations de/ch-pxe.html...

Red Hat Enterprise Linux 4: System Administration Guide Chapter 3. PXE Network Installations http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/sysadmin-guide/ch-pxe.html

syslinux, pxelinux 사이트 http://syslinux.zytor.com/pxe.php

4. 전체세팅순서

네트워크 설치할 서버를 세팅합니다. 한대만 있으면 됩니다. 이 한대의 서버에 nfs, dhcp, tftp 서버를 올려서 이용하겠습니다. nfs 는 /export/centos 디렉토리를 이용하는 것으로 예제삼음

  • 네트워크 설치 준비 : 네트워크 설치용 nfs 서버 세팅하고 데이타 올림
  • 자동설치 위한 kickstart 준비 : 설정파일을 kickstart에 넣어두고 네트워크를 통하여(nfs, http 등) 자동설치하기 위함
  • dhcp 준비 : ip를 자동으로 할당하고 원격부팅시 부트이미지를 찾아주는 역할을 함
  • tftp 서버 세팅 : pxe 원격부팅을 위한 프로그램임. dhcp에서 ip를 받고 tftp에서 부팅이미지를 받아옴.
  • pxe 자동설치 세팅 : tftp 에서 자동으로 부팅할 수 있도록 준비하고 화면에 출력하는 메시지를 조정함.

5. 네트워크 설치준비


rhel 4장의 cd 에서 마운트하여 복사
mount /mnt/cdrom
cp -arv /mnt/cdrom/Redhat /export/centos
(CentOS일 경우는 디렉토리가 redhat이 아닌 CentOs)

cp /mnt/cdrom/RELEASE-NOTES*.html /export/centos

pxe 부팅을 이용할 경우에는 첫번째 CD의 images 디렉토리가 필요하므로 추가로 이 디렉토리도 복사해주어야한다.
cp -arv /mnt/cdrom/images /export/centos 

iso 이미지를 이용하면 더 간편하다. 아래와 같은 형태를 이용하면 된다.

mount -o loop CD1.iso /location/of/disk/space/disc1/

cd /root/iso
mount -o loop CentOS-4.3-i386-bin1of4.iso /export/centos/disc1
mount -o loop CentOS-4.3-i386-bin2of4.iso /export/centos/disc2
mount -o loop CentOS-4.3-i386-bin3of4.iso /export/centos/disc3
mount -o loop CentOS-4.3-i386-bin4of4.iso /export/centos/disc4

그런데 NFS를 이용하는 경우 ISO 이미지를 NFS 설치디렉토리에 복사해두면 훨씬 더 간편하다. 위에서 /export/centos/ 에 iso 이미지 네장을 넣어두고 설치시 이 디렉토리를 지정하면 된다. 그렇지만 아래에서 pxe 부팅을 세팅할때 이미지파일, 커널등을 복사해야하기때문에 특정 디렉토리로 몰아넣는 것이 좋다. loop 로 mount 한 것이 nfs에서는 보이지 않는 문제도 있다. 이유는???

네트워크설치를 하려면 설치시 askmethod 옵션을 이용하면 된다.
linux askmethod

{i} 설치에 지정하는 디렉토리는 RedHat/ (또는 CentOS) 배포 디렉토리를 포함하지 않고 이 디렉토리까지에 이르는 하부 디렉토리들을 의미합니다. 예를 들어 Red Hat Enterprise Linux 4 설치 파일이 설치 서버에서 /export/rhel/에 위치한다면, /location/of/disk/space/는 /export/rhel/이 됩니다. 미러한 사이트의 경우 centos/4.4/os/i386/ 가 될 것입니다. centos 앞의 디렉토리는 미러한 디렉토리에 따라 다르겠지요.

6. kickstart 준비과정

kickstart 파일 이용 http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/sysadmin-guide/s1-kickstart2-startinginstall.html os를 설치하고나면 /root/anaconda-ks.cfg 파일이 있다. 이것을 이용하면 된다.

설치는 nfs를 이용. 아래에서 설치방법은 nfs 를 이용하고 있으며 server, dir만 설정에 따라 조정하면 된다. X-windows 설정은 제외하였다. network는 dhcp 이용. 고정 ip를 등록해놓고 부팅후 바꾸어도 된다. root 비밀번호는 암호화해서 저장함. 파티션부분은 시스템마다 다를 수 있으므로 주석처리하면 설치시 물어봄. 아래는 sda 에서 ext3 로 /boot 100M를 만들고 나머지 공간을 물리적 볼륨, 볼륨 그룹으로 할당한후 로지컬 볼륨으로 swap 256M , 나머지 공간 / 로 할당한다. 패키지 목록은 admin-tools, editors(vi때문에 필요), x 윈도우 관련하여 base-x 와 gnone-desktop (서버운영할 목적이라면 x는 빼도 됨), legacy-software-development (이전 버전과의 호환성을 위해 필요), development-tools (개발을 위해 필요. gcc 등) 등을 선택하였다.

서버용이라면 아래의 그룹과 패키지만 선택해도 될 것이다.

설치패키지그룹 admin-tools editors development-tools

추가 패키지 vsftpd (mysql-server) (httpd) (php) (php-mysql) sysstat mc

post는 설치후 작업하는 스크립트이며 불필요한 서비스를 자동으로 내리는 역할을 한다. nameser를 지정하고 ssh 키를 가져오는 부분이 있다. psot는 chroot 환경에서 작동을 하며 이 상태에서는 아직 dns정보를 가지고 있지 않다. 그래서 코넷의 dns를 지정하고 /root/.ssh 디렉토리를 만든후 cent.tunelinux.pe.kr 서버의 root 계정의 공개키를 복사하여 cent.tunelinux.pe.kr 서버에서 root로 자동로그인하도록 한 것이다. 초기 작업은 root 권한이 많이 필요한데 좀더 편안하게 작업을 할 수 있도록 해 놓은 것이다.

# Kickstart file automatically generated by anaconda.
install
nfs --server=192.168.202.100 --dir=/home/taejun/iso
lang ko_KR.UTF-8
langsupport --default=en_US.UTF-8 en_US.UTF-8 ko_KR.UTF-8
keyboard us
#xconfig --card "VMWare" --videoram 16384 --hsync 31.5-37.9 --vsync 50-70 --resolution 800x600 --depth 16 --startxonboot  --defaultdesktop gnome
network --device eth0 --bootproto dhcp
rootpw --iscrypted $1$Q.jKpF0a$lxii4oW6QbxBRdIGZhxty1
firewall --disabled
selinux --disabled
authconfig --enableshadow --enablemd5
timezone Asia/Seoul
bootloader --location=mbr --append="rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --drives=sda
part /boot --fstype ext3 --size=100 --ondisk=sda
part pv.2 --size=0 --grow --ondisk=sda
volgroup VolGroup00 --pesize=32768 pv.2
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=256 --grow --maxsize=512
logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow

%packages
@ admin-tools
@ editors
@ gnome-desktop
@ ftp-server
@ network-server
@ legacy-software-development
@ base-x
@ development-tools

%post
#!/bin/bash
for target in `ls /etc/init.d/ /etc/xinetd.d/ | egrep -v "/etc/init.d|/etc/xinetd.d" | egrep -v "rpmsave|rpmnew" | egrep -v 'auth|functions|halt|killall|single'`
do
        /sbin/chkconfig --level 345 $target off
done

SERVICE="crond irqbalance network sshd syslog sysstat vsftpd xinetd"

/sbin/chkconfig --level 345 auth off

for service_target in $SERVICE
do
        /sbin/chkconfig --level 345 $service_target on
done

echo "nameserver 168.126.63.1" > /etc/resolv.conf
cd /root
mkdir .ssh
cd .ssh
wget http://cent.tunelinux.pe.kr/authorized_keys
chmod 600 authorized_keys


kickstart 설정은 매뉴얼을 보면서 수동으로 해도 되지만 system-config-kickstart 프로그램을 이용하면 GUI로 세팅할 수 있다. http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/sysadmin-guide/ch-redhat-config-kickstart.html



# yum -y install system-config-kickstart
# system-config-kickstart

설치시 아래와 같이 실행을 하면 된다.
linux ks=nfs:192.168.202.100:/home/taejun/iso/ks.cfg 

{i} 참고로 하드웨어의 특성으로 특정 드라이버가 필요할 경우에는 드라이버도 네트워크를 통하여 받을 수 있다. 이 경우는 설치매뉴얼에서 부팅옵션을 참고하기 바란다.

  • Intel Server Board S5000VSA의 SAS RAID(megasr) 모듈 추가하기 (20080716-이돈현 삽입)

    1. [http]드라이버 다운로드

    2. 이미지 파일(megasr-09.32.0207.2008-1-rhel40-u6-all.img)을 웹서버에 업로드

    3. /tftpboot/linux-install/pxelinux.cfg/default 파일에 dd=http://my.... 부분 추가
label c64ss144
kernel centos64/vmlinuz
append initrd=centos64/initrd.img ramdisk_size=9216 text ks=http://mydomain.com/ks/c64ss144.cfg dd=http://mydomain.com/module/megasr-09.32.0207.2008-1-
rhel40-u6-all.img


{i} 설정에서 네임서버를 포함하여 고정ip로 하였다면 %post 섹션에서 ip 주소를 질의할 수 있지만 dhcp로 설정을 한 경우에는 /etc/resole.conf 파일이 생성되지 않은 상태이므로 스크립트에서 다른 서버에 접속할 일이 있다면 ip로 질의를 해야한다.
http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/sysadmin-guide/s1-kickstart2-postinstallconfig.html If you configured the network with static IP information, including a nameserver, you can access the network and resolve IP addresses in the %post section. If you configured the network for DHCP, the /etc/resolv.conf file has not been completed when the installation executes the %post section. You can access the network, but you can not resolve IP addresses. Thus, if you are using DHCP, you must specify IP addresses in the %post section.

7. nfs 세팅

# cat /etc/exports
/export/centos 192.168.202.0/24(ro,insecure)

보안을 위해서는 접근할 ip, host를 제한하는 것이 좋다.
/etc/init.d/portmap start
/etc/init.d/nfs start

아래와 같은 식으로 테스팅을 해본다.
mount -t nfs 192.168.202.100:/export/centos /tmp/test

8. dhcp

서버프로그램설치
# yum -y install dhcp
# /etc/init.d/dhpcd start

dhcp 설정파일은 /etc/dhcpd.conf 이다. 초기에는 주석과 함께 내용이 비어있다. /usr/share/doc/dhcp*/dhcpd.conf.sample 의 내용을 복사하여 적절히 수정하면 된다.
# cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcpd.conf

[root@mytest etc]# diff /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcpd.conf
4c4
< subnet 192.168.0.0 netmask 255.255.255.0 {
---
> subnet 192.168.202.0 netmask 255.255.255.0 {
7c7
<       option routers                  192.168.0.1;
---
>       option routers                  192.168.202.2;
12c12
<       option domain-name-servers      192.168.1.1;
---
>       option domain-name-servers      192.168.202.2;
21c21
<       range dynamic-bootp 192.168.0.128 192.168.0.254;
---
>       range dynamic-bootp 192.168.202.200 192.168.202.210;

subnet, netmask, routers, domain-name-servers, ip 대역 정도만 수정해도 잘 동작한다.


dhcp 서버를 설치하면 /usr/share/doc/dhcp-3.0.1/dhcpd.conf.sample 의 파일을 참고로 해서 /etc/dhcpd.conf 를 만들어주면 된다.

여기서 수정해줄 항목은 subnet, netmask, routers (기본 게이트웨이), range dynamic-bootp (dhcp로 쓸 ip 대역을 세부적으로 나눔) 이 파일에서 아래 부분을 추가해주면 된다.
allow booting;
allow bootp;
class "pxeclients" {
match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
next-server <server-ip>;
filename "linux-install/pxelinux.0";
}
server-ip 는 tftp 서버의 ip를 말하며 별도의 서버를 쓰지 않는다면 현재 세팅하는 서버일 것이다.


9. 자동설치 세팅

system-config-netboot 를 이용하여 세팅하겠음 상세 내용은 참고자료를 이용함. 이 프로그램을 실행하고 네트워크 설치를 골라서 1차 진행함.

이 화면에서 Operating system identifier 에 적당한 이름을 입력하고 필요에 따라 킥스타트 파일이름을 적고 프로토콜, 서버 ip 주소와 위치를 지정하면 해당 ip와 위치에서 부팅에 필요한 파일을 가져와 /tftpboo/linux-install/Operating system identifier 에 initrd.img vmlinuz 를 복사한다. 여기서 Operating system identifier 에는 cent 를 넣었다고 하고 진행. (한글화면일 경우에는 설정-네트워크 설치)

PXE Boot Configuration

Adding PXE Hosts


이렇게 진행하면 여러가지 디렉토리와 파일을 손댄다.

/tftpboot/linux-install/centos 디렉토리를 생성하고 부팅관련한 파일을 복사함. /tftpboot/linux-install/pxelinux.cfg 디렉토리에 default, pxeos.xml 파일 생성하며 여기서 pxeos.xml은 설정내용을 저장하고 있고 default 가 부팅되고나서의 옵션을 정함. /tftpboot/linux-install/msgs 파일에 해당 OS 추가
msgs:
합계 24
--rw-r--r-- 1 root root 507 12월 18 22:18 boot.msg
+-rw-r--r-- 1 root root 531 12월 18 22:19 boot.msg
-rw-r--r-- 1 root root 668 9월 1 03:35 expert.msg
-rw-r--r-- 1 root root 871 9월 1 03:35 general.msg
-rw-r--r-- 1 root root 860 9월 1 03:35 param.msg
@@ -11,4 +11,12 @@
-rw-r--r-- 1 root root 545 9월 1 03:35 snake.msg

pxelinux.cfg:
-합계 0
+합계 8
+-rw-r--r-- 1 root root 356 12월 18 22:19 default
+-rw-r--r-- 1 root root 247 12월 18 22:19 pxeos.xml
+
+centos:
+합계 3368
+-rw-r--r-- 1 root root 2535139 12월 18 22:19 initrd.img
+-rw-r--r-- 1 root root 77 12월 18 22:19 ks.cfg
+-rw-r--r-- 1 root root 900120 12월 18 22:19 vmlinuz

# cat pxelinux.cfg/default
....

label 1
kernel centos/vmlinuz
append initrd=centos/initrd.img ramdisk_size=7000 ks=nfs:192.168.40.11:/export/centos/ks222.cfg

[root@localhost pxelinux.cfg]# cat pxeos.xml
<?xml version="1.0" ?>
<OperatingSystems>
<OS Anonymous="1" Description="rhel3 es " Diskless="0" Kernel="" Kickstart="nfs:192.168.40.11:/export/centos/ks222.cfg" Location="/export/centos" 
Name="centos" Password="" Protocol="NFS" Server="192.168.40.11" User=""/>

여기서 설정하는 kickstart 파일도 원격에서 이용할 수 있으므로 nfs:192.168.40.11:/export/centos/ks222.cfg 와 같이 지정하면 편리하게 사용할 수 있다.

이제 특정 네트워크 또는 ip와 앞에서 정의한 os를 연결시켜주는 작업을 해야 한다.

여기서 호스트명에 192.168.40.0 이라고 넣으면 해당 네트워크 대역을 모두 포함하는 것이다. (c 클래스)

여기서도 킥스타트파일을 넣어주는 것이 있다. 그러나 여기 넣어준다고 바로 작동하지 않는다. /tftp/linux-install/pxelinux.cfg/ 디렉토리에 아래와 같은 내용이 생기는데 이것을 참고로 해서 위의 default 파일을 수정해주든지 하면 된다. pxelinux.0 프로그램에서 설정파일을 읽을때 가장 먼저 찾는것을 이용한다. 클라이언트의 ip를 가지고 10진수를 16진수로 바꾸어 이에 해당하는 파일명을 찾는다. 예를 들어 192.168.0.11 은 C0A8000B 이다. 해당파일이 없으면 default 파일을 읽는다. 일반적으로 여러대의 서버에 설치를 할 경우에는 이 방식을 쓸 필요는 없고 default 파일을 조정하여 같은 버전이라고 하더라도 kickstart 파일만 여러개 지정하여 이용하도록 하면 될 것이다.


# cat C0A82800
default centos

label centos
kernel centos/vmlinuz
append initrd=centos/initrd.img ramdisk_size=7000 ks=http://lx03.tunelinux.pe.kr/ks.cfg

명령행에서는 pxeboot 라는 명령을 이용할 수 있는데 레드햇에서 편리하게 만들어놓은 듯 하다.

/tftp/linux-install/msgs 디렉토리는 부팅후 화면에 뿌려주는 화면이며 해당 파일을 마음대로 수정해도 된다. 단지 뿌려주는 부분이므로. 그렇지만 label은 default 파일에서 조정하는 것이므로 함께 맞추어주어야 한다.


굳이 위의 툴을 쓰지 않는다면 /tftpboot/linux-install 에 해당 os명 디렉토리를 만들어 initrd 와 부팅용 커널을 복사하고 default 파일을 수정한후 (ks 파일 지정등) 부팅할 때 고르기 편하도록 msgs 파일에 내용을 넣어주면 된다.

10. 자동설치의 이론적 내용

pxe 가 활성화가 되면 dhcp를 통하여 처음 ip를 부여받고 next-server 에서 지정한 tftp 서버에서 filename 에 지정한 프로그램으로 부팅을 한다.

pxelinux.0 프로그램을 이용하여 default 파일을 읽어 필요한 커널로 부팅을 한다.

pxe, dhcp, tftp 를 이용하는 방식은 윈도우즈도 동일하다.

11. tftp 서버 시작

/sbin/chkconfig --level 345 xinetd on
/sbin/chkconfig --level 345 tftp on
이렇게하고 xinetd 를 시작해준다.
service xinetd restart

설치하여 테스팅을 해본다.

12. 참고

위와 같이 하여 모든 테스팅을 마쳤다면 자기 상황에 맞게 조절하여 사용하자. 위에서 OS버전별로 구분할 수도 있고 웹, 메일 등 서버의 기능에 따라 분리할 수도 있다. OS버전에 따라서 조정을 하고 kickstart 파일을 조정하여 세부 세팅을 하면 편리하게 이용이 가능하다.

여기서 좀 더 나간다면 새로운 서버를 추가하거나 삭제하는 경우 서버등록, dns 등록, ip 부여등을 자동으로 하는 스크립트등을 만들어서 이용할 수 있을 것이다.

설치는 이렇게 자동화를 하고 이후 시스템설정은 cfengine 을 이용하여보자.


13. 참고 : system rescue cd 테스팅

http://www.systemrescuecd.org/ http://tunelinux.pe.kr/zboard/view.php?id=tip&no=42 systemrescuecd 는 간단히 말해 리눅스용 고스트프로그램으로 생각하면 되며 시스템에 문제가 발생하였을 경우 cd에서 부팅해 작업할 수 있는 프로그램이고 partimage 를 이용하여 파티션을 다른 곳으로 옮기거나 복구할 수 있다. 이 cd를 다운로드받아 pxe로 부팅되는 것을 확인해보았다. systemrescuecd 는 젠투기반이며 라이브cd같은것을 생각하면 된다. Knoppix 등 다른 배포판도 동일하게 작업을 할 수 있으리라 예상이 된다.

# mount -o loop ~test/systemrescuecd-x86-0.2.15.iso /mnt/floppy/
# cp /mnt/floppy/isolinux/vmlinuz1 /mnt/floppy/isolinux/initrd1 /tftpboot/linux-install/rescue/
커널과 initrd 파일을 복사해준것이다.

# cat /tftpboot/linux-install/pxelinux.cfg/default
label 3
kernel rescue/vmlinuz1
append initrd=/rescue/initrd1 acpi=off root=/dev/ram0 init=/linuxrc dokeymap vga=785

위와 같이 추가해주었다.

위의 내용은 아래 isolinux 에서 부팅에 관련된 파일에서 정보를 확인한 것이다. 달라진것이 있다면 우리가 rescue 디렉토리를 기준으로 하기 때문에 이 부분만 달라졌다.
# cat /mnt/floppy/isolinux/isolinux.cfg

이렇게 해서 부팅을 하면 systemrescuecd 에서 부팅을 할 수 있다.

부팅시는 3번을 골라야하며 msg 파일도 수정을 해야 편할 것이다.

ID
Password
Join
You shall be rewarded for a dastardly deed.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-01-19 17:59:23
Processing time 0.0106 sec