利用Kickstart+DHCP+VSFTP+FTP实现Centos5.5批量网络安装

        在纠结了半个月之久,终于通过参照网络上的各种文档,做出来了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调为网络启动即可,收工!

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