爲避免到數據中心重裝CentOS,須要研究一下如何自動安裝,通過一番努力終獲成功。前提是將一臺局域網內已經裝好的CentOS服務器作成 DHCP/TFTP/HTTP/Kickstart Server,要重裝的服務器網卡要支持PXE網絡啓動就能夠。配置過程記錄以下:html
1. 安裝配置DHCP: linux
- #yum install dhcp
- #vi /etc/dhcpd.conf
- #
- # DHCP Server Configuration file.
- # see /usr/share/doc/dhcp*/dhcpd.conf.sample
- ddns-update-style interim;
- allow booting;
- allow bootp;
- next-server 10.1.1.204;
- filename "/pxelinux.0";
- default-lease-time 1800;
- max-lease-time 7200;
- ping-check true;
- option domain-name-servers 4.2.2.2;
- subnet 10.1.1.0 netmask 255.255.255.0
- {
- range 10.1.1.10 10.1.1.20;
- option broadcast-address 10.1.1.255;
- }
- #/etc/rc.d/init.d/dhcpd restart
若是服務器有多張網卡用/usr/sbin/dhcpd eth1 -d -f指定工做的網卡名(如eth1)。web
2. TFTP server:express
- #yum install -y xinetd tftp-server
- #vi /etc/xinetd.d/tftp
- service tftp
- {
- socket_type = dgram
- protocol = udp
- wait = yes
- user = root
- server = /usr/sbin/in.tftpd
- server_args = -s /tftpboot
- disable = no
- per_source = 11
- cps = 100 2
- flags = IPv4
- }
- #/etc/init.d/xinetd start
3. HTTP server以及給tftp加載內容:centos
- #yum install httpd
- #mount -o loop /tmp/CentOS_5.iso /var/www/html/C/
- #yum install syslinux
- #cp /usr/lib/syslinux/pxelinux.0 /tftpboot
- #cp /usr/lib/syslinux/menu.c32 /tftpboot
- #cp /usr/lib/syslinux/memdisk /tftpboot
- #cp /usr/lib/syslinux/mboot.c32 /tftpboot
- #cp /usr/lib/syslinux/chain.c32 /tftpboot
- #cd /tftpboot/
- #mkdir /tftpboot/pxelinux.cfg
- #mkdir -p /tftpboot/p_w_picpaths/centos/x86_64
- #mkdir -p /tftpboot/p_w_picpaths/centos/x86_64/5.4
- #cp /var/www/html/C/CentOS//p_w_picpaths/pxeboot/initrd.img /tftpboot/p_w_picpaths/centos/x86_64/5.4/
- #cp /var/www/html/C/CentOS//p_w_picpaths/pxeboot/vmlinuz /tftpboot/p_w_picpaths/centos/x86_64/5.4/
- #yum install system-config-netboot
- #mkdir /tftpboot/msgs
- #cp /usr/share/system-config-netboot/msgs/*.* /tftpboot/msgs
- #vi /tftpboot/pxelinux.cfg/default
- default local
- timeout 100
- prompt 1
- display msgs/boot.msg
- F1 msgs/boot.msg
- F2 msgs/general.msg
- F3 msgs/expert.msg
- F4 msgs/param.msg
- F5 msgs/rescue.msg
- F7 msgs/snake.msg
- label local
- localboot 1
- label 0
- localboot 1
- label 1
- KERNEL p_w_picpaths/centos/x86_64/5.4/vmlinuz
- 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
- label 2
- kernel memtest86
- label 3
- kernel vmlinuz
- append initrdinitrd=initrd.img text
- #service xinetd restart
4. 配置Kickstart,模板可參考/root/anaconda-ks.cfg。服務器
- vi /var/www/html/ks/ks.cfg
- # Kickstart file automatically generated by anaconda.
- install
- #network --device eth1 --bootproto dhcp
- # Repository Location
- url --url=http://10.1.1.204/C/
- lang en_US.UTF-8
- keyboard us
- 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
- network --device eth1 --bootproto static --ip x.x.x.x --netmask 255.255.255.x --nameserver d.d.d.d --hostname YourName.com
- rootpw --iscrypted $Xw0jjc1sdkadkadfa
- #(能夠從/etc/shadow中得到)
- firewall --enabled --port=22:tcp
- authconfig --enableshadow --enablemd5
- selinux --enforcing
- timezone --utc Asia/Shanghai
- bootloader --location=mbr --driveorder=cciss/c0d0
- # The following is the partition information you requested
- # Note that any partitions you deleted are not expressed
- # here so unless you clear all partitions first, this is
- # not guaranteed to work
- clearpart --all --drives=cciss/c0d0
- part /boot --fstype ext3 --size=100
- part swap --size=2048
- part / --fstype ext3 --size=100 --grow --asprimary
- %packages
- @base
- @core
- @dialup
- @editors
- @text-internet
- keyutils
- trousers
- fipscheck
- device-mapper-multipath
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數據讀取狀況。app
參考:http://hi.baidu.com/luyaolot/blog/item/eb374643fc163a1d72f05d6a.htmlless