利用PXE自动安装linux配置
环境:server:192.168.32.20
client:192.168.32.21
原理:客户端PXE网卡启动--DHCP服务器获得IP--从TFTP目录上下载pxelinux.0、default--根据配置文件default指定的vmlinuz、initrd启动系统内核--通过内核指定地点去下载ks.cfg文件--跟据ks.cfg去(HTTP、FTP、NFS)服务器下载RPM包并安装系统----完成安装
1、NFS服务器配置
[root@server1 ~]# cat /etc/exports
/var/ftp/pub *(ro)
#rhel5.5安装光盘存放目录/var/ft/pub下
[root@server1 ~]# /etc/init.d/nfs start
[root@server1 ~]#chkconfig nfs on
[root@server1 ~]# /etc/init.d/portmap start
注:nfs服务是基于rpc服务的,即需要开启portmap服务
2、DHCP服务器配置
[root@server1 ~]#cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
[root@server1 ~]#vi /etc/dhcpd
ddns-update-style interim;
#定义所支持的DNS动态更新类型,该参数必选且必须放在第一行,一般为none和interim
ignore client-updates;
subnet 192.168.32.0 netmask 255.255.255.0 {
#定义dhcp的网段
# --- default gateway
option routers 192.168.32.254;
option subnet-mask 255.255.255.0;
option nis-domain "notexample";
option domain-name "example.com";
option domain-name-servers 192.168.32.20;
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.32.25 192.168.32.27;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.32.20;
#定义提供PXE服务的tftp服务器地址
filename "/pxelinux.0";
#定义PXE启动文件pxelinux.0存放位置
# 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;
}
}
注:DHCP配置文件中每个选项行必须以;结尾,否则DHCP会启动失败
[root@server1 ~]#service dhcpd start
#
启动dhcp服务
[root@server1 ~]#chkconfig dhcpd on
#添加到开机自起动
3、tftp服务器配置
[root@server1 ~]#vi /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
#将此行默认不启动,no为启动
per_source = 11
cps = 100 2
flags = IPv4
}
[root@server1 ~]#/etc/init.d/xinetd restart
[root@server1 ~]#chkconfig xinetd on
4、PXE配置
[root@server1 ~]#cp /usr/lib/syslinux/pxelinux.0 /tftpboot/pxelinux.0
[root@server1 ~]#cp /var/ftp/pub/isolinux/vmlinuz /tftpboot/vmlinuz
[root@server1 ~]#cp /var/ftp/pub/isolinux/initrd.img /tftpboot/initrd.img
[root@server1 ~]#mkdir /tftpboot/pxelinux.cfg
[root@server1 ~]#cp /var/ftp/pub/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
[root@server1 ~]#vi /tftpboot/pxelinux.cfg/default
default linux
#如果启动时不按任何选项,默认执行lable linux安装
prompt 1
#启动时候等待参数,设置为0 表示启动不等待参数,直接进入,网络安装必须为1
timeout 10
display boot.msg
#.msg文件是启动时的显示界面,图像文件,可不要,要则复制到/tftpboot/目录下
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img ks=nfs:192.168.32.220:/var/ftp/pub/ks.cfg
#指定kickstart配置文件
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append -
5、通过kickstart生产ks.cfg配置文件
5.1、配置yum源
#运行kickstart时,在选择安装所需软件包时需要yum的支持
[root@server1 ~]#vi /etc/yum.repos.d/server1.repo
[base]
#注此处必须为[base]或[core]否则kickstart启动时无法找到软件包源,此为perl的bug
name=server
baseurl=file:///var/ftp/pub/Server
enabled=1
gpgcheck=0
[root@server1 ~]#yum makecache
5.2、进入5级别,图形界面中,利用kickstart创建ks.cfg文件
[root@server1 ~]#system-config-kickstart
#按照提示进行配置,并将其文件保存为/var/ftp/pub/ks.cfg
[root@server1 ~]#vi /var/ft/pub/ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
# System authorization information
auth --useshadow --enablemd5
key --skip
#必须加入此行,否则在pxe安装时会因为要求输入sn号而中断
# 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 --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Installation logging level
logging --level=info
# Use NFS installation media
nfs --server=192.168.32.20 --dir=/var/ftp/pub/
#指定安装盘所在位置
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$JJqgz1nm$gGpOgJGbq24TxU32NG0r4.
# SELinux configuration
selinux --permissive
# System timezone
timezone America/New_York
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig --defaultdesktop=GNOME --depth=32 --resolution=1024x768
# Disk partitioning information
#分区信息,默认是普通分区,可手动修改成lvm分区
part /boot --bytes-per-inode=4096 --fstype="ext3" --size=100
part swap --bytes-per-inode=4096 --fstype="swap" --size=1024
part / --bytes-per-inode=4096 --fstype="ext3" --size=10240
#part /boot --fstype ext3 --size=100 --ondisk=sda
#创建lvm分区
#part pv.2 --size=0 --grow --ondisk=sda
#volgroup VolGroup00 --pesize=32768 pv.2
#logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
#logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=1000 --grow --maxsize=4032
%packages
@development-libs
@gnome-desktop
@base
@base-x
@admin-tools
@legacy-software-development
@development-tools
@printing
@chinese-support
@server-cfg
@legacy-network-server
@legacy-software-support
@system-tools
@text-internet
@editors
@ftp-server
@network-server
@smb-server