linux中pxe批量装机服务的搭建
百度百科:PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端(客户端)基本软件设置,从而引导预先安装在服务器中的终端操作系统。PXE可以引导多种操作系统,如:Windows95/98/2000/windows2003/windows2008/winXP/win7/win8,linux系列系统等。
搭建环境:俩台虚拟机
1,关闭防火墙防止在后续操作过程中对实验产生干扰
[[email protected] ~]#setenforce 0
[[email protected] ~]#iptables -F
2,关闭防火墙后修改yum源挂载光盘,安装与pxe批量装机有关的服务
[[email protected] ~]#mount /dev/sr0 /mnt/cdrom
[[email protected] ~]#cd /etc/yum .repos.d/
[[email protected] yum.repos.d]#vim CentOS-Base.repo
[centosplus]
name=CentOS-$releasever -Plus
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
3,安装完成后,和其他服务器的搭建一样,接下来开始修改相关tftp服务的配置文件
[[email protected] ~]#vim /etc/xinetd.d/tftp
.......
server_args = -s /tftpboot
disable =no
修改完成后重新启动服务,使相关配置文件生效
[[email protected] ~]#service xinetd start
4,创建上一步配置文件中所需要使用的文件,并赋予其相关权限
[[email protected] ~]#mkdir /tftpboot
[[email protected] ~]#chmod 777 /tftpboot
5,tftp服务启动完成后,开始修改dhcp的相关配置文件,由于dhcp相关配置文件中并未给出详细配置文件只是给出了模板文件,故将模板文件复制到相应的配置文件下
[[email protected] ~]#vim /etc/dhcp/dhcpd.conf
#DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
[[email protected] ~]#cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
6,复制完成后,进入配置文件修改相关配置选项
[[email protected] ~]#vim /etc/dhcp/dhcpd.conf
#A slightly different configuration for an internal subnet.
subnet 192.168.247.0 netmask 255.255.255.0{
range 192.168.247.1 192.168.247.30
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1;
option broadcast-adress 192.168.247.255;
default-lease-time 600;
max-lease-time 7200
首先要配置dhcp服务所处的网络地址和子网掩码,其次要规定dhcp服务的作用域范围以及相关的路由选择等选项,配置完成重启dhcp服务使相应的配置选项生效
[[email protected] ~]#service dhcpd start
7,dhcp和tftp服务启动成功后开始准备安装源
[[email protected] ~]#mkdir /var/ftp/pub/dvd
[[email protected] ~]#chmod 777 /var/ftp/pub/dvd
8,开启vsftpd服务
[[email protected] ~]#service vsftpd start
9,vsftpd服务启动成功后,拷贝相关引导文件
[[email protected] ~]#cp /usr/share/syslinux/pxelinux.0 /tftpboot
10,拷贝完成,创建默认引导目录文件,重新挂载光盘,并赋予引导目录文件相应的权限
[[email protected] ~]#mkdir /tftpboot/pxelinux.cfg
[[email protected] ~]#umount -a
[[email protected] ~]#mount /dev/sr0 /var/ftp/pub/dvd
[[email protected] ~]#cp /var/ftp/pub/dvd/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
***拷贝时要特别注意,由于pxe启动时默认启用default为引导文件故不能随意更改该文件名否则可能导致实验失败
[[email protected] ~]#chmod 644 /tftpboot/pxelinux.cfg/default
[[email protected] ~]#cp /var/ftp/pub/dvd/isolinux/* /tftpboot
11,重新启动所有服务(为方便操作,也可设置开机自启chkconfig命令)
[[email protected] ~]#service dhcpd restart
[[email protected] ~]#service vsftpd restart
[[email protected] ~]#service xinetd restart
12,所有服务配置完成后,再次修改yum源,安装Kickstart工具
[[email protected] ~]#cd /etc/yum .repos.d/
[[email protected] yum.repos.d]#vim CentOS-Base.repo
[centosplus]
name=CentOS-$releasever -Plus
baseurl=file:///var/ftp/pub/dvd
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[[email protected] yum.repos.d]#yum -y install system-config-kickstart
13,安装完成后打开kick工具进行相关配置
[[email protected] yum.repos.d]#system-config-kickstart
选择要安装的安装包,用户可自行选择
14,修改完成后,修改相应的启动引导文件
[[email protected] yum.repos.d]#cd
[[email protected] ~]#cp ks.cfg /tftpboot/pxelinux.cfg
[[email protected] ~]#vim /tftpboot/pxelinux.cfg/default
........
append initrd=initrd.img ks=ftp://192.168.154.129/pub/ks.cfg
15,所有配置均已修改完成,打开另一台虚拟机进行验证,首先进入bios界面稍作修改
按下回车键即可进行自动安装系统操作