在糾結了半個月之久,終於通過參照網絡上的各種文檔,做出來了PXE批量安裝系統的實驗,這只是實現了PXE批量安裝的一個框架,有一些小的細節並未做太多的研究,由於本人的工作非linux系統方面,但是興趣愛好始終是要保持的;
實驗環境:
一臺用vmware安裝好Centos5.5_64bit的操作系統,網卡選擇vm1;
靜態ip地址:192.168.10.10;
PXE客戶機也是用vmware創建的,只是在我新建的時候沒有掛在光盤而已;
1.創建yum源,安裝所需軟件包:
[root@localhost ~]# vim /etc/yum.repos.d/yum.repo name=server baseurl=file:///media enable=1 gpgcheck=0
[root@localhost ~]#yum install -y vsftp* && yum install -y tftp* && yum install dhcp* -y && yum install -y *kickstart* -y
2.確保這些軟件都安裝上之後。在做配置文件的修改:
(1):配置DHCP服務:
[root@localhost ~]#cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf [root@localhost ~]#vim /etc/dhcpd.conf ddns-update-style interim; ignore client-updates; subnet 192.168.10.0 netmask 255.255.255.0 { #->以上內容需修改爲與本機同一網段 # --- default gateway option routers 192.168.10.10; #->指向自己即可 option subnet-mask 255.255.255.0; #->無需修改 # option nis-domain "domain.org"; # option domain-name "domain.org"; # option domain-name-servers 192.168.1.1; 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; filename "pxelinux.0"; next-server 192.168.10.10; #->以上兩項必須添加的(分號不要忘記打) range dynamic-bootp 192.168.10.20 192.168.10.30;#->分配的IP地址段 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; } } #->置完以上內容過後即可重啓服務,並加入開機啓動項: [root@localhost ~]# service dhcpd restart && chkconfig dhcpd on
(2)配置TFTP服務:
[root@localhost ~]# vim /etc/xinetd.d/tftp #->修改配置文件 service tftp { disable = no #->將這裏更改爲no. socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot per_source = 11 cps = 100 2 flags = IPv4 } ~ #->配置完以上內容過後即可重啓服務,並加入開機啓動項: [root@localhost ~]# service xinetd restart && chkconfig xinetd on
(3)配置Vsftp服務:(此服務不作其他配置,只需啓動,並加入開機啓動項即可,後續再作其他操作)
3.從本地和光盤上覆制PXE啓動時所需要的文件:
[root@localhost ~]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/ #->如果以上覆制pxelinux.0時會出現沒有的情況,這是需要安裝syslinux這個軟件包,將它複製到tftp默認的文件夾內; [root@localhost ~]# mkdir -p /tftpboot/pxelinux.cfg #->在tftp默認的文件夾內創建一個pxelinux.cfg的文件夾 [root@localhost ~]# cp /media/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default #->此文件用於指定ks.cfg的存放位置 [root@localhost ~]# cp /media/images/pxeboot/initrd.img /tftpboot/ #->系統引導文件 [root@localhost ~]# cp /media/images/pxeboot/vmlinuz /tftpboot/ #->系統引導文件 ~ ~ ~ ~
4.修改相關配置文件:
[root@localhost ~]# vim /tftpboot/pxelinux.cfg/default default linux prompt 1 timeout 5 #->超時時間,默認爲600秒,可以不用更改 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 ks=ftp://192.168.10.10/ks.cfg #->這是通過vsftp存放ks.cfg的路徑 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.通過system-config-kickstart圖形工具生成ks.cfg文件(截圖略):
修改ks.cfg文件並將其保存到/var/ftp/
[root@localhost ~]# vim /var/ftp/ks.cfg #platform=x86, AMD64, or Intel EM64T # System authorization information auth --useshadow --enablemd5 # System bootloader configuration bootloader --location=mbr # Partition clearing information clearpart --none key --skip #->添加此項,不然不叫自動化安裝了。 # Use graphical install graphical # Firewall configuration firewall --disabled # 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 network installation url --url=ftp://192.168.10.10/pub #這是安裝文件的存放路徑 # Network information network --bootproto=dhcp --device=eth0 --onboot=on #Root password rootpw --iscrypted $1$f8SyLEwO$J6VmGy6bMDQz1N39A/3Cl0 # SELinux configuration selinux --disabled # System timezone timezone America/New_York # Install OS instead of upgrade install # X Window System configuration information xconfig --defaultdesktop=GNOME --depth=8 --resolution=640x480 # Disk partitioning information #->以下三行是對新系統即pxe客戶機的分區情況; part /boot --bytes-per-inode=4096 --fstype="ext3" --size=200 part swap --bytes-per-inode=4096 --fstype="swap" --size=1024 part / --bytes-per-inode=4096 --fstype="ext3" --size=20000 #->以下這些內容來自於PXE服務器上/root/anaconda-ks.cfg 這是pxe服務器在第一次安裝時系統所記錄下來的信息,如果你也想要你的pxe客戶端也和服務器端的安裝一樣,則可以將他們複製到ks.cfg裏面,你也可以自行定義。 %packages @base @core @development-libs @development-tools @dialup @editors @gnome-desktop @games @graphical-internet @graphics @legacy-software-development @office @printing @ruby @text-internet @x-software-development @base-x keyutils trousers fipscheck device-mapper-multipath imake java-1.6.0-openjdk libsane-hpaio mesa-libGLU-devel xorg-x11-server-Xnest xorg-x11-server-Xvfb #->配置完以上內容過後即可保存退出,並將ks.cfg文件保存到/var/ftp/ ~ ~ ~
6.安裝文件
將光盤鏡像掛載到/var/ftp/pub
[root@localhost ~]# mount /dev/cdrom /var/ftp/pub/ -o loop [root@localhost ~]# mount | grep iso #->檢查是否掛在成功
7.重啓相關服務,將客戶機的BIOS調爲網絡啓動即可,收工!