linux無人值守安裝+PXE

第一階段 實現無人值守安裝
思路:
作爲提供安裝的服務器(注意它的iptables和selinux)
1、生成ks.cfg(無人值守配置文件),並通過NFS/HTTP/FTP/Harddisk共享

2、配置DHCP服務器(客戶端只有有與共享ks.cfg配置文件的服務器在同一網段的IP纔可行)


作爲需要安裝系統的客戶端
1、光盤啓動
2、在boot: linux ks=/path/ks.cfg


具體實現:
作爲提供安裝的服務器
1、生成ks.cfg(無人值守配置文件),並通過NFS/HTTP/FTP/Harddisk共享
無人值守配置文件的生成方法有兩種:
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)


2、配置DHCP服務器(客戶端只有有與共享ks.cfg配置文件的服務器在同一網段的IP纔可行)
[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
[root@localhost ftp]# cat /etc/exports
/var/ftp *(rw)
/rhel5u5 *(rw)
[root@localhost ftp]# service portmap restart
停止 portmap: [確定]
啓動 portmap: [確定]
[root@localhost ftp]#
service nfs restart


作爲需要安裝系統的客戶端
1、光盤啓動
2、在boot: linux ks=/path/ks.cfg
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),此配置文件中將定義加載從光盤中拷出的vmlinuz和initrd.img文件。
同時,爲了讓後續的安裝過程實現無人值守,我們需要在配置文件中定義如何找到ks.cfg文件(此文件在上一階段已經OK)


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

具體細節實現:
1、修改dhcp配置文件:
vim /etc/dhcpd.conf
在subnet聲明中加如下語句:
subnet 192.168.1.0 netmask 255.255.255.0 {

# --- default gateway
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配置文件的模板(光盤中的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的配置文件
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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章