PXE网络安装服务器
这里假设192.168.0.46为PXE服务器
首先你需要在你的服务器上
实验一:
实验:
rpm -q http dhcp tftp-server查看相关软件包是否安装。如若未安装请安装好相关软件在进行以下操作:
1. kickstart配置相关的文件:
cat ks.cfg
------------------------------------------------------------------------------
key --skip
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.0.254/pub/rhel6/dvd"(或者可以是url --url="http://192.168.0.31/rhel6"但是此时你要通过 httpd 服务共享出 rhel6 的安装介质:mount -o loop rhel-server-6.0-x86_64-dvd.iso /var/www/html/rhel6,在这就是url --url="http://192.168.0.254/pub/rhel6/dvd"但是你要这么安装的话在你进行安装的时候获得PXE地址的时候你拔掉网线,等到获得地址之后你就得插上网线了哦,但是你要是写--url="http://192.168.0.31/rhel6,因为你把设备挂到本地了,所以就不用插网线了啊!
)
# Root password
rootpw --iscrypted $1$u8pJnYgb$ZE0rVkip891Pdf/VYe6Wm0
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System authorization information
auth --useshadow --passalgo=md5
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=100
part swap --fstype="swap" --size=1024
part / --fstype="ext4" --grow --size=1
%packages
@base
%end
-----------------------------------------------------------------------------
保存ks.cfg到/var/www/html中,ksvalidator ks.cfg 可以检查文件是否正确,然后restorecon *
即可发布。
2.配置tftp服务:
cd /var/lib/tftpboot
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
lftp 192.168.0.254(假设服务器是254)
cd /pub/rhel6/dvd/isolinux
mget *(或者是你挂载了媒体设备之后可以cp /var/www/html/rhel6/isolinux . )
mkdir pxelinux.cfg
cp isolinux.cfg pxelinux.cfg/default
cd pxelinux.cfg/
vi default
Timeout=20(设置停留时间)
label rhel6
menu label ^Install rhel6 x86_64
menu default(注意这里的default在所有的标签中你只能设置一个,意思就是你不选择的话将会以哪个启动,Timeout=20)
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.0.74/ks.cfg
chkconfig tftp on
/etc/init.d/xinetd restart
netstat -aulnp | grep :69可以查看xinetd服务是否开启。
3.配置dhcp服务:
cd /etc/dhcp
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample dhcpd.conf
vi dhcpd.conf
ddns-update-style interim; /*dhcp支持的dns动态更新方式*/
ignore client-updates; /*忽略客户端DNS动态更新*/
authoritative; /*授权*/
allow booting; /*支持PXE启动*/
allow bootp; /*支持boottp*/
option domain-name "sushan.org";
option domain-name-servers 192.168.0.74;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.130 192.168.0.140;
option routers 192.168.0.74;
filename "pxelinux.0";
next-server 192.168.0.74;(这2个选项你可以写在里面也可以写在}外面,最好写在里面)
}
(#next-server marvin.redhat.com
这是指明TFTP服务器的IP或者是主机名,如果你的TFTP和DHCP是同一台物理主机,那就可以注释掉该行,本例中便注释掉了该行
filename
这一个选项很重要,它的作用是指明bootstrap所在的位置,一般是指向一个TFTP服务器的某个目录下)
chkconfig dhcpd on
service dhcpd start
测试:
/etc/inid.d/httpd restart
/etc/init.d/dhcpd restart
/etc/init.d/xinetd restart
chkconfig tftp on
新建一个新的虚拟机,假设名字为pxevserver。选择 Network Boot(PXE),如果在安装的过程中出现:That directory could not bo mount from the server这样的错误,那么说明你的配置文件是正确的,只是你的kickstart文件哪里有问题。
注意因为在做dhcp的时候为了避免获得其他人的dhcpd地址,那么你应该在获得IP的时候拔掉网线,然后在得到pxe服务器的地址的时候你在插上网线。然后就可以正常的安装啦!如果你在ks.cfg下面设置的url --url="http://192.168.0.254/pub/rhel6/dvd"(或 者可以是url --url="http://192.168.0.31/rhel6"你进行安装的时候获得PXE地址的时候你 拔掉网线,等到获得地址之后你就得插上网线了哦,但是你要是写--url="http://192.168.0.31/rhel6,因为你把设备挂到本地 了,所以就不用插网线了啊!
)
注意本人错误:首先是在default设置中没有两个menu default,使得系统自动选择最好一个default去安装了。还有就是Timeout最好改动小一些100是指的在10S内你不选择的话以默认的安装。在就是ks.cfg中关于url --url="http://192.168.0.74.设置的问题。还有一点要注意你在kickstart中选择:Installation Source的时候选择的是http那么就以http的方式访问你的源所在位置,要是ftp那么则以ftp的方式访问你的源的位置,当你选择nfs的时候你可以eg:nfs Server: 192.168.0.74 Nfs Directory: /mnt/cdrom 那么你在搭建nfs服务平台的时候你需要yum install nfs-utils -y vi /etc/exports
/media/cdrom 192.168.0.0/24(ro)
/mnt/ks 192.168.0.0/24(ro )之后/etc/init.d/nfs restart chkconfig nfs on 并且showmount -e 192.168.0.74显示一下成功即可,你要想你的ks.cfg也通过你可以共享的话,在/var/lib/tftpboot/pxelinux.cfg下面的default中你也可以通过nfs共享:
label rhel6
menu label ^Install rhel6 x86_64
menu default
kernel vmlinuz
append initrd=initrd.img ks=nfs:192.168.0.74/mnt/ks/ks.cfg
转载于:https://blog.51cto.com/sushan/683493