您的位置:首页 > 理论基础 > 计算机网络

CentOS5.4 远程安装(PXE+DHCP+tftp+HTTP+kickstart)

2011-03-04 12:21 996 查看
为避免到数据中心重装CentOS,需要研究一下如何自动安装,经过一番努力终获成功。前提是将一台局域网内已经装好的CentOS服务器做成DHCP/TFTP/HTTP/Kickstart Server,要重装的服务器网卡要支持PXE网络启动就可以。配置过程记录如下:

1. 安装配置DHCP:

#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)。

2. TFTP server:

#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加载内容:

#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/images/centos/x86_64
#mkdir -p /tftpboot/images/centos/x86_64/5.4
#cp /var/www/html/C/CentOS//images/pxeboot/initrd.img  /tftpboot/images/centos/x86_64/5.4/
#cp /var/www/html/C/CentOS//images/pxeboot/vmlinuz /tftpboot/images/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 images/centos/x86_64/5.4/vmlinuz
APPEND ks=http://10.1.1.204/ks/ks.cfg initrd=images/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数据读取情况。

参考:http://hi.baidu.com/luyaolot/blog/item/eb374643fc163a1d72f05d6a.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息