CentOS5.4 遠程安裝(PXE+DHCP+tftp+HTTP+kickstart)

爲避免到數據中心重裝CentOS,需要研究一下如何自動安裝,經過一番努力終獲成功。前提是將一臺局域網內已經裝好的CentOS服務器做成 DHCP/TFTP/HTTP/Kickstart Server,要重裝的服務器網卡要支持PXE網絡啓動就可以。配置過程記錄如下:

1. 安裝配置DHCP: 

  1. #yum install dhcp  
  2. #vi /etc/dhcpd.conf  
  3. #  
  4. # DHCP Server Configuration file.  
  5. #   see /usr/share/doc/dhcp*/dhcpd.conf.sample    
  6. ddns-update-style interim;  
  7. allow booting;  
  8. allow bootp;  
  9. next-server 10.1.1.204;  
  10. filename "/pxelinux.0";  
  11.  
  12. default-lease-time 1800;  
  13. max-lease-time 7200;  
  14. ping-check true;  
  15. option domain-name-servers 4.2.2.2;  
  16.  
  17. subnet 10.1.1.0 netmask 255.255.255.0  
  18. {   
  19. range 10.1.1.10  10.1.1.20;  
  20. option broadcast-address 10.1.1.255;  
  21. }  
  22. #/etc/rc.d/init.d/dhcpd restart 

如果服務器有多張網卡用/usr/sbin/dhcpd eth1 -d -f指定工作的網卡名(如eth1)。

2. TFTP server:

  1. #yum install -y xinetd tftp-server  
  2. #vi /etc/xinetd.d/tftp  
  3. service tftp  
  4. {  
  5.         socket_type             = dgram 
  6.         protocol                = udp 
  7.         wait                    = yes 
  8.         user                    = root 
  9.         server                  = /usr/sbin/in.tftpd  
  10.         server_args             = -s /tftpboot  
  11.         disable                 = no 
  12.         per_source              = 11 
  13.         cps                     = 100 2  
  14.         flags                   = IPv4 
  15. }  
  16. #/etc/init.d/xinetd start
  17.  
  18.  

3. HTTP server以及給tftp加載內容:

  1. #yum install httpd  
  2. #mount -o loop /tmp/CentOS_5.iso /var/www/html/C/  
  3. #yum install syslinux  
  4. #cp /usr/lib/syslinux/pxelinux.0 /tftpboot  
  5. #cp /usr/lib/syslinux/menu.c32 /tftpboot  
  6. #cp /usr/lib/syslinux/memdisk /tftpboot  
  7. #cp /usr/lib/syslinux/mboot.c32 /tftpboot  
  8. #cp /usr/lib/syslinux/chain.c32 /tftpboot  
  9. #cd /tftpboot/  
  10. #mkdir /tftpboot/pxelinux.cfg  
  11. #mkdir -p /tftpboot/p_w_picpaths/centos/x86_64  
  12. #mkdir -p /tftpboot/p_w_picpaths/centos/x86_64/5.4  
  13. #cp /var/www/html/C/CentOS//p_w_picpaths/pxeboot/initrd.img  /tftpboot/p_w_picpaths/centos/x86_64/5.4/  
  14. #cp /var/www/html/C/CentOS//p_w_picpaths/pxeboot/vmlinuz /tftpboot/p_w_picpaths/centos/x86_64/5.4/  
  15. #yum install system-config-netboot  
  16. #mkdir /tftpboot/msgs  
  17. #cp /usr/share/system-config-netboot/msgs/*.* /tftpboot/msgs  
  18. #vi /tftpboot/pxelinux.cfg/default  
  19.     default local  
  20.     timeout 100  
  21.     prompt 1  
  22.     display msgs/boot.msg  
  23.     F1 msgs/boot.msg  
  24.     F2 msgs/general.msg  
  25.     F3 msgs/expert.msg  
  26.     F4 msgs/param.msg  
  27.     F5 msgs/rescue.msg  
  28.     F7 msgs/snake.msg  
  29.     label local  
  30.     localboot 1  
  31.  
  32.     label 0  
  33.     localboot 1  
  34.  
  35.     label 1  
  36.     KERNEL p_w_picpaths/centos/x86_64/5.4/vmlinuz  
  37.     APPEND ks=http://10.1.1.204/ks/ks.cfg initrd=p_w_picpaths/centos/x86_64/5.4/initrd.img ramdisk_size=100000 ksdevice=list noipv6  
  38.  
  39.     label 2  
  40.     kernel memtest86  
  41.       
  42.     label 3  
  43.     kernel vmlinuz  
  44.     append initrdinitrd=initrd.img text  
  45. #service xinetd restart 

4. 配置Kickstart,模板可參考/root/anaconda-ks.cfg。

  1. vi /var/www/html/ks/ks.cfg  
  2. # Kickstart file automatically generated by anaconda.  
  3.  
  4. install  
  5. #network --device eth1 --bootproto dhcp  
  6. # Repository Location  
  7. url --url=http://10.1.1.204/C/  
  8. lang en_US.UTF-8  
  9. keyboard us  
  10. network --device eth0 --bootproto static --ip x.x.x.x --netmask 255.255.255.x --gateway y.y.y.y --nameserver d.d.d.d --hostname YourName.com  
  11. network --device eth1 --bootproto static --ip x.x.x.x --netmask 255.255.255.x --nameserver d.d.d.d --hostname YourName.com   
  12. rootpw --iscrypted $Xw0jjc1sdkadkadfa   
  13. #(可以從/etc/shadow中獲得)  
  14. firewall --enabled --port=22:tcp  
  15. authconfig --enableshadow --enablemd5  
  16. selinux --enforcing  
  17. timezone --utc Asia/Shanghai  
  18. bootloader --location=mbr --driveorder=cciss/c0d0  
  19. # The following is the partition information you requested  
  20. # Note that any partitions you deleted are not expressed  
  21. # here so unless you clear all partitions first, this is  
  22. # not guaranteed to work  
  23. clearpart --all --drives=cciss/c0d0  
  24. part /boot --fstype ext3 --size=100 
  25. part swap --size=2048 
  26. part / --fstype ext3 --size=100 --grow --asprimary  
  27.  
  28. %packages  
  29. @base  
  30. @core  
  31. @dialup  
  32. @editors  
  33. @text-internet  
  34. keyutils  
  35. trousers  
  36. fipscheck  
  37. device-mapper-multipath  
  38.  

5. 用KVM控制新服務器重啓,按F11(HP )或F12(Dell)進入網絡啓動,按1開始按照指定流程工作,(DHCP過程需要耐心等待)如果配置正確,可以看到完全的自動安裝,最好提示重啓系統。

6. 安裝過程troubleshooting, 可以在Kickstart服務器上#tail /var/log/messages來檢查DHCP地址分配情況,#tail /var/log/httpd/err_log(access_log)可查看web數據讀取情況。

參考:http://hi.baidu.com/luyaolot/blog/item/eb374643fc163a1d72f05d6a.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章