天天看點

linux無人值守安裝+PXE

第一階段 實作無人值守安裝

思路:

作為提供安裝的伺服器(注意它的iptables和selinux)

1、生成ks.cfg(無人值守配置檔案),并通過NFS/HTTP/FTP/Harddisk共享

2、配置DHCP伺服器(用戶端隻有有與共享ks.cfg配置檔案的伺服器在同一網段的IP才可行)

作為需要安裝系統的用戶端

1、CD光牒啟動

2、在boot: linux ks=/path/ks.cfg

具體實作:

作為提供安裝的伺服器

無人值守配置檔案的生成方法有兩種:

a.system-config-kickstart指令生成( 注意key --skip)

[root@localhost ~]# yum -y install system-config-kickstart

[root@localhost ~]# system-config-kickstart

注意ks.cfg檔案的權限

[root@localhost ftp]# ls -l /var/ftp/ks.cfg

-rw-r--r-- 1 root root 1292 03-31 11:15 /var/ftp/ks.cfg

b.拷系統自身的一個ks檔案,稍做修改

系統自身的一個ks檔案:/root/anaconda-ks.cfg

通過NFS共享ks.cfg檔案

[root@localhost ftp]# ls /var/ftp/ks.cfg

/var/ftp/ks.cfg

[root@localhost ftp]# vim /etc/exports

[root@localhost ftp]# cat /etc/exports

/var/ftp *(rw)

[root@localhost ftp]# yum -y install dhcp

[root@localhost ftp]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf

cp:是否覆寫“/etc/dhcpd.conf”? y

修改/etc/dhcpd.conf的配置檔案,定義租用IP的位址段和位址池範圍

[root@localhost ftp]# service dhcpd start

啟動 dhcpd: [确定]

3、配置NFS伺服器,共享安裝樹檔案 /rhel5u5

/rhel5u5 *(rw)

[root@localhost ftp]# service portmap restart

停止 portmap: [确定]

啟動 portmap: [确定]

[root@localhost ftp]# service nfs restart

boot: linux ks=nfs:192.168.1.254:/var/ftp/ks.cfg

ks.cfg檔案

[root@localhost ftp]# cat ks.cfg

#platform=x86, AMD64, 或 Intel EM64T

# System authorization information

key --skip

auth --useshadow --enablemd5

# System bootloader configuration

bootloader --location=mbr

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Use text mode install

text

# Firewall configuration

firewall --enabled

# Run the Setup Agent on first boot

firstboot --disable

# System keyboard

keyboard us

# System language

lang en_US

# Installation logging level

logging --level=info

# Use NFS installation media

nfs --server=192.168.1.254 --dir=/rhel5u5

# Network information

network --bootproto=dhcp --device=eth0 --onboot=on

# Reboot after installation

reboot

#Root password

rootpw --iscrypted $1$23JmK7TQ$mPN5A.BrLCoDGHIktT0r80

# SELinux configuration

selinux --enforcing

# System timezone

timezone Asia/Shanghai

# Install OS instead of upgrade

install

# X Window System configuration information

xconfig --defaultdesktop=GNOME --depth=32 --resolution=1024x768

# Disk partitioning information

part / --bytes-per-inode=4096 --fstype="ext3" --size=6000

part /boot --bytes-per-inode=4096 --fstype="ext3" --size=100

part swap --bytes-per-inode=4096 --fstype="swap" --size=1500

%packages

@base-x

@gnome-desktop

@chinese-support

@admin-tools

@system-tools

dhcpd.conf

[root@localhost ftp]# cat /etc/dhcpd.conf

ddns-update-style interim;

ignore client-updates;

subnet 192.168.1.0 netmask 255.255.255.0 {

# --- default gateway

option routers 192.168.1.254;

option subnet-mask 255.255.255.0;

option nis-domain "domain.org";

option domain-name "domain.org";

option domain-name-servers 192.168.1.254;

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.128 192.168.1.254;

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;

}

第二階段 實作網絡引導

1、需要安裝系統的用戶端主機必須要支援網絡啟動

網卡支援intel PXE規範

2、當網絡啟動後

需要有IP 位址----DHCP伺服器配置設定

需要去找網絡上一個共享了bootstrap程式(pxelinux.0)的主機,一般是通過一個TFTP服務來共享 ----DHCP伺服器可以在配置檔案中定義下一個伺服器是誰,DHCP伺服器中也定義了找到下一個伺服器以後,加載它共享的哪一個檔案 (bootstrap).

3、将加載bootstrap(相當于grub的stage2功能)運作,繼續再加載自己的配置檔案(相當于grub.conf),此配置檔案中将定義加載從CD光牒中拷出的vmlinuz和initrd.img檔案。

同時,為了讓後續的安裝過程實作無人值守,我們需要在配置檔案中定義如何找到ks.cfg檔案(此檔案在上一階段已經OK)

需要在第一了段基本上額外配置dhcp的相關字段,TFTP伺服器,TFTP伺服器要共享 bootstrap程式檔案,bootstrap配置檔案和vmlinuz/initrd.img

具體細節實作:

1、修改dhcp配置檔案:

vim /etc/dhcpd.conf

在subnet聲明中加如下語句:

next-server 192.168.1.254; 此IP是TFTP伺服器的IP

filename "/pxelinux.0"; 此檔案是TFTP伺服器共享的檔案

2、配置TFTP,共享相關檔案

[root@localhost isolinux]# yum -y install tftp-server

[root@localhost isolinux]# cd /tftpboot/

此目錄 就是tftp伺服器的共享根目錄

a.拷bootstrap檔案(系統自帶)到tftp的共享根目錄下

]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/

b.建立放bootstrap配置檔案的目錄

[root@localhost syslinux]# mkdir /tftpboot/pxelinux.cfg

c.拷bootstrap配置檔案的模闆(CD光牒中的isolinux目錄下自帶)

[root@localhost syslinux]# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default

d.拷vmlinuz,initrd.img到tftp共享根目錄下

]# cp /mnt/isolinux/vmlinuz /mnt/isolinux/initrd.img /tftpboot/

]# cp /mnt/isolinux/*.msg /tftpboot/pxelinux.cfg/

e.pxelinux.0的配置檔案

[root@localhost syslinux]# cat /tftpboot/pxelinux.cfg/default

default linux

prompt 1

timeout 30

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 text ks=nfs:192.168.1.254:/var/ftp/ks.cfg

3、注意,服務啟動

[root@localhost syslinux]# chkconfig tftp on [root@localhost syslinux]# service xinetd restart[root@localhost syslinux]# netstat -tunlp | grep :69

udp 0 0 0.0.0.0:69 0.0.0.0:* 4896/xinetd

pxelinux.0的配置檔案

繼續閱讀