Linux系統PXE高效批量網絡裝機的配置


Linux系統PXE高效批量網絡裝機的配置

配置環境:

服務器IP地址為192.168.1.10,所在網段為192.168.1.0/24;

一、首先需要准備系統安裝源

 

[root@www ~]# mkdir -pv /var/ftp/centos6/
[root@www ~]# cp -rf /media/cdrom/* /var/ftp/centos6/

 

二、部署FTP服務

 

[root@www ~]# yum -y install vsftpd
[root@www ~]# service vsftpd start

 

三、部署TFTP服務

[root@www ~]# yum -y install tftp-server

編輯 /etc/xinetd.d/tftp配置文件,將disable=yes改為disable=no 重啟xinetd服務即可。

# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = no   //把yes改為no  
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no     //把yes改為no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

啟動服務

[root@www ~]# service xinetd start

四、准備linux內核和初始化文件。

Linux內核和初始化鏡像文件可以從linux鏡像中找到,位於文件夾/images/pxeboot中,將vmlinuz和initrd.img復制到tftp的根目錄/var/lib/tftpboot/下

Vmlinuz:linux內核                    

initrd.img:初始化鏡像文件

[root@www ~]# cd /media/cdrom/images/pxeboot/
[root@www pxeboot]# ls
initrd.img  TRANS.TBL  vmlinuz
[root@www pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/

五、接下來在准備PEX引導程序,啟動菜單文件

Linux引導程序為pxelinux.0 該文件由syslinux軟件包提供,因此我們要安裝syslinux軟件包,並復制到tftp根目錄下

 

[root@www ~]# yum -y install syslinux
[root@www ~]# cd /usr/share/syslinux/
[root@www syslinux]# cp pxelinux.0 /var/lib/tftpboot/

 

默認的啟動菜單為default,該文件應該放置在tftp根目錄的pxelinux.cfg中,並重命名為default。

[root@www ~]# cd /media/cdrom/
[root@www cdrom]# ls
CentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6
EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6
EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6
GPL              repodata                  TRANS.TBL
images           RPM-GPG-KEY-CentOS-6
[root@www cdrom]# cd isolinux/
[root@www isolinux]# ls
boot.cat  grub.conf   isolinux.bin  memtest     TRANS.TBL     vmlinuz
boot.msg  initrd.img  isolinux.cfg  splash.jpg  vesamenu.c32
[root@www isolinux]# cp isolinux.cfg /var/lib/tftpboot/

 

[root@www syslinux]# cd /var/lib/tftpboot/
[root@www tftpboot]# mkdir pxelinux.cfg
[root@www tftpboot]# cp isolinux.cfg pxelinux.cfg/default

修改default文件內容如下:

default linux       //名字隨便起
prompt 0           //0表示自動選擇,1表示等待用戶確認
timeout 600       //超時時間  60s



label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz
  append  initrd=initrd.img
label text            //文本安裝
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append text initrd=initrd.img xdriver=vesa nomodeset
label rescue        //救援模式
  menu label ^Rescue installed system
  kernel vmlinuz

六、安裝部署DHCP服務

[root@www ~]# yum -y install dhcp
[root@www ~]# cd /usr/share/doc/dhcp-4.1.1/
[root@www dhcp-4.1.1]# cp dhcpd.conf.sample /etc/dhcp/dhcpd.conf 

修改配置文件如下:

只需在配置文件里添加網段聲明即可;

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.10 192.168.1.20;
  option routers 192.168.1.10;
  filename "pxelinux.0";             //制定PXE引導程序名
  next-server 192.168.1.10;      //添加ftp服務器的
}
[root@www ~]# service dhcpd start

這里為了方便測試,我們把防火牆規則清空;

[root@www ~]# iptables -F
[root@www ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

最后就是新建虛擬機進行測試了,此過程略過,需要注意的是把新建的虛擬機網卡選擇在同一個網卡下;

在這里,我們一起成長!!!

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM