歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Centos 5.5 X86_64實戰KickStart自動化安裝

Centos 5.5 X86_64實戰KickStart自動化安裝

日期:2017/3/3 16:11:15   编辑:關於Linux

原理和概念:

1.1 什麼是PXE

嚴格來說,PXE 並不是一種安裝方式,而是一種引導的方式。進行 PXE 安裝的必要條件是要安裝的計算機中包含一個 PXE 支持的網卡(NIC),即網卡中必須要有 PXE Client。PXE (Pre-boot Execution Environment)協議使計算機可以通過網絡啟動。協議分為 client 和 server 端,PXE client 在網卡的 ROM 中,當計算機引導時,BIOS 把 PXE client 調入內存執行,由 PXE client 將放置在遠端的文件通過網絡下載到本地運行。運行 PXE 協議需要設置 DHCP 服務器和 TFTP 服務器。DHCP 服務器用來給 PXE client(將要安裝系統的主機)分配一個 IP 地址,由於是給 PXE client 分配 IP 地址,所以在配置 DHCP 服務器時需要增加相應的 PXE 設置。此外,在 PXE client 的 ROM 中,已經存在了 TFTP Client。PXE Client 通過 TFTP 協議到 TFTP Server 上下載所需的文件。

1.2 什麼是KickStart

KickStart是一種無人職守安裝方式。KickStart的工作原理是通過記錄典型的安裝過程中所需人工干預填寫的各種參數,並生成一個名為ks.cfg的文件;在其後的安裝過程中(不只局限於生成KickStart安裝文件的機器)當出現要求填寫參數的情況時,安裝程序會首先去查找KickStart生成的文件,當找到合適的參數時,就采用找到的參數,當沒有找到合適的參數時,才需要安裝者手工干預。這樣,如果KickStart文件涵蓋了安裝過程中出現的所有需要填寫的參數時,安裝者完全可以只告訴安裝程序從何處取ks.cfg文件,然後去忙自己的事情。等安裝完畢,安裝程序會根據ks.cfg中設置的重啟選項來重啟系統,並結束安裝。

1.3 PXE + KickStart安裝的條件

執行 PXE + KickStart安裝需要的設備為:

DHCP 服務器;

TFTP 服務器;

KickStart所生成的ks.cfg配置文件

一台存放系統安裝文件的服務器,如 NFS、HTTP 或 FTP 服務器。

帶有一個 PXE 支持網卡的將安裝的主機;

部署需要一台安裝好的圖形界面的Centos5.5虛擬機機器。內存和機器多大都可以。Ip:192.168.1.20

現在開始部署:

1. 插入光盤,掛載光驅:

[root@DZ-03 ~]# mount /dev/cdrom /mnt/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@DZ-03 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 13G 2.8G 9.4G 23% /

/dev/sda1 1.9G 41M 1.8G 3% /boot

tmpfs 125M 0 125M 0% /dev/shm

/dev/hdc 3.9G 3.9G 0 100% /media/CentOS_5.5_Final

/dev/hdc 3.9G 3.9G 0 100% /mnt

2. 安裝tftp服務器

[root@DZ-03 ~]# yum -y install tftp* tftp-server

[root@DZ-03 ~]# vim /etc/xinetd.d/tftp #更改tftp配置文件,打開tftp服務,如下:

# default: off

# description: The tftp server serves files using the trivial file transfer \

# protocol. The tftp protocol is often used to boot diskless \

# workstations, download configuration files to network-aware printers, \

# and to start the installation process for some operating systems.

service tftp

{

socket_type = dgram

protocol = udp

wait = yes

user = root

server = /usr/sbin/in.tftpd

server_args = -s /tftpboot

disable = yes #把yes改成no,然後保存退出即可。

per_source = 11

cps = 100 2

flags = IPv4

}

[root@DZ-03 ~]# /etc/init.d/xinetd restart #啟動tftp服務,因為tftp是xinetd服務的子進程受xinetd的管轄。

Stopping xinetd: [FAILED]

Starting xinetd: [ OK ]

3. 設置pex配置文件

[root@DZ-03 ~]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/ #復制pex引導安裝主程序。

[root@DZ-03 ~]# cp /mnt/images/pxeboot/initrd.img /tftpboot/ #復制initrd.img---ramdisk文件,幫助內核可選加載硬件驅動模塊。

[root@DZ-03 ~]# cp /mnt/images/pxeboot/vmlinuz /tftpboot/ #復制vmlinuz內核文件。

[root@DZ-03 ~]# cp /mnt/isolinux/*.msg /tftpboot/ #復制linux開機引導文件。

[root@DZ-03 ~]# cp /mnt/isolinux/splash.lss /tftpboot/ #復制安裝系統背景圖標。

[root@DZ-03 ~]# mkdir /tftpboot/pxelinux.cfg #創建引導菜單的的目錄。

[root@DZ-03 ~]# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default #default-引導菜單,可在tftp目錄下建立不同vmlinuz和initrd.img的目錄組合,從而建立不同系統引導的條件。

4. 安裝dhcp服務

[root@DZ-03 ~]# yum -y install dhcp*

[root@DZ-03 ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf #拷貝dhcp模板文件到/etc/目錄下命名為dhcpd.conf。

cp: overwrite `/etc/dhcpd.conf'? yes #選擇yes,覆蓋原配置文件。

[root@DZ-03 ~]# vim /etc/dhcpd.conf #更改dhcp配置文件。

ddns-update-style interim; #dhcp支持的dns動態更新方式。

ignore client-updates; #忽略客戶端DNS動態更新。

next-server 192.168.1.20; #添加:Tftp server服務器的ip地址。

filename "/pxelinux.0"; #添加:Bootstrap文件。

subnet 192.168.1.0 netmask 255.255.255.0 { #聲明KickStart ip網段.

# --- default gateway

option routers 192.168.1.1; #必須改成KickStart ip網段的網關地址。

option subnet-mask 255.255.255.0;

option nis-domain "domain.org";

option domain-name "domain.org";

option domain-name-servers 192.168.1.20; #必須改成KickStart ip服務器正確地址。

option time-offset -18000; # Eastern Standard Time

# option ntp-servers 192.168.1.1;

# option netbios-name-servers 192.168.1.1;

# --- Selects point-to-point node (default is hybrid). Don't change this unless

# -- you understand Netbios very well

# option netbios-node-type 2;

range dynamic-bootp 192.168.1.100 192.168.1.254; #更改:安裝完系統默認分配的客戶端ip地址。

default-lease-time 21600;

max-lease-time 43200;

# we want the nameserver to appear at a fixed address

host ns {

next-server marvin.redhat.com;

hardware ethernet 12:34:56:78:AB:CD;

fixed-address 207.175.42.254;

}

}

[root@DZ-03 ~]# /etc/init.d/dhcpd restart #啟動dhcpd服務器

5. 安裝NFS文件系統

[root@DZ-03 ~]# yum -y install nfs-*

[root@DZ-03 ~]# mkdir /tftpboot/ks

[root@DZ-03 ~]# vim /etc/exports #打開配置文件,添加如下:

/mnt *(ro)

/tftpboot/ks/ *(ro)

[root@DZ-03 ~]# /etc/init.d/portmap restart

[root@DZ-03 ~]# /etc/init.d/nfs restart

[root@DZ-03 ~]# showmount -e localhost #檢查是否加載成功

Export list for localhost:

/mnt *

/tftpboot/ks *

6. 安裝KickStart

[root@DZ-03 ~]# yum -y install system-config-kickstart.noarch

[root@DZ-03 ~]# system-config-kickstart #開始進行圖形化配置

(圖一):

(圖二):

(圖三):備注:什麼都不需要修改

(圖四):

 

(圖五):

(圖六):

(圖七):

(圖八):

最後選擇

保存

[root@DZ-03 ~]# cp /root/ks.cfg /tftpboot/ks/

[root@DZ-03 ~]# chmod 777 /tftpboot/pxelinux.cfg/default

[root@DZ-03 ~]# vim /tftpboot/pxelinux.cfg/default #打開配置文件,更改。

default linux #更改成ks。

prompt 1

timeout 600 #引導安裝的超時時間改成6秒即可。

display boot.msg

F1 boot.msg

F2 options.msg

F3 general.msg

F4 param.msg

F5 rescue.msg

label linux

kernel vmlinuz

append initrd=initrd.img

label text

kernel vmlinuz

append initrd=initrd.img text

label ks

kernel vmlinuz

append ks=nfs:192.168.1.20:/tftpboot/ks/ks.cfg initrd=initrd.img #添加ks路徑

append ks initrd=initrd.img #把這行用#號注釋掉。

label local

localboot 1

label memtest86

kernel memtest

append –

1. 關閉防火牆和selinux

[root@DZ-03 ~]# /etc/init.d/iptables stop

[root@DZ-03 ~]# setenforce 0

2. 最後添加一台新的linux主機來測試,測試結果如下:

呵呵,自動化系統安裝成功了。

作者署名:51cto博客 IMySQL

Copyright © Linux教程網 All Rights Reserved