最近购买了抚琴煮酒的《构建高可用linux服务器》一书,其中有关于自动化安装linux系统的文章,自己就按照书中所讲,尝试了一下。其中也遇到了一些问题,自己也找到了相关的解决方法。现在自己就把整个过程写下来,也算是自己的总结。

本文只是自己个人总结,在实验中参照了酒哥书中的内容和网上的一些内容,所以可能与其他人相关文章有相似之处,敬请见谅。

第一步 安装操作系统,实验我是用的centos5.3最小化安装。因为Kickstart需要使用图形化安装,所以在安装系统时最好把桌面给选择上。如果没有选择,可以使用yum后期安装。

命令如下:

yum -y groupinstall 'X Window System' (安装X Window System)

yum -y groupinstall 'GNOME Desktop Environment' (安装GNOME Desktop)

第二步 安装tftp服务

使用yum安装tftp-server,并启用

yum -y install tftp-server

修改/etc/xinetd.d/tftp文件,将disable=yes改为no

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
}

启动xinetd服务

service xinetd start

第三步 复制相关的文件

因使用http提供系统安装的服务,所以把光盘里的内容复制到/var/www/html下

mount /dev/cdrom /media

cp -rfv /media /var/www/html

从xinetd中可以看到tftp服务在/(根)目录下创建了tftpboot目录,把需要的一些文件拷贝到这个目录下面。

复制pxelinux.0文件至tftpboot文件夹中,如下所示。

cp /usr/lib/syslinux/pxelinux.0 /tftpboot

DVD光盘上的/p_w_picpath/pxeboot/initrd.imgvmlinux复制到/tftpboot/中,如下所示。

cp /var/www/html/p_w_picpaths/pxeboot/vmlinuz /tftpboot

复制DVD光盘上的isolinux/*.msg/tftpboot目录下,如下所示:

cp /var/www/html/isolinux/*.msg /tftpboot/

tftpboot中新建一个pxelinux.cfg目录:

mkdir pxelinux.cfg

isolinux目录中的isolinux.cfg复制到pxelinux.cfg目录中,同时更改文件名称为default,命令如下所示:

cd pxelinux.cfg

cp /var/www/html/isolinux/isolinux.cfg   /tftpboot/pxelinux.cfg/default

第四步 安装dhcp服务

yum -y install dhcp

修改相关的配置文件

然后复制配置模板文件到指定的目录中,并重新命名。

cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf

接着修改/etc/dhcpd.conf配置文件,文件最后修改内容如下所示:

ddns-update-style interim;
ignore client-updates;
next-server 192.168.20.2;
filename "/pxelinux.0";

subnet 192.168.20.0 netmask 255.255.255.0 {

# --- default gateway
   option routers            192.168.20.1;
   option subnet-mask        255.255.255.0;

   option nis-domain        "domain.org";
   option domain-name        "domain.org";
   option domain-name-servers    192.168.20.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;

   range dynamic-bootp 192.168.20.128 192.168.20.254;
   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;
   }
}
最后启动dhcp服务:

service dhcpd start

第五步 使用yum工具安装Kickstart。

yum -y install system-config-kickstart

然后在gnome的桌面环境下配置kickstar,启动命令为:

system-config-kickstart

启动后如图所示:

142556442.jpg

这里需要注意的是,如果你自己更改过本地的yum源,在选择安装包的过程中会出现如下报错:

Package selection is disabled due to problems downloading package information.

这时只需要在/etc/yum.repos.d目录下建立一个以base命名的repo文件即可。

[root@guyi yum.repos.d]# cat base.repo
# CentOS-Media.repo
#
# This repo is used to mount the default locations for a CDROM / DVD on
#  CentOS-5.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c5-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c5-media [command]

[base]
name=base
baseurl=file:///media/
gpgcheck=1
enabled=1
gpgkey=
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5


在正常启动Kickstart后,可以对自动安装做一些调整。比如时区、root密码、分区等。这些网上有很多,这里就不过多叙述,我只提一些我自己遇到的问题。

在选择安装方法时,选择http服务时,http服务的目录直接填写“/”即可。

最后把生成的文件ks.cfg保存到/var/www/html目录下。

第六步 修改default文件。

)修改/tftpboot/pxelinux.cfg/default文件,指定读取ks.cfg的方法,即修改文件第一行内容,改动后文件第一行内容如下所示:

default text ks=http://192.168.20.2/ks.cfg(一定要是文件的第一行)

另外,也建议将timeout时间由原先的600改为1timeout时间是引导时等待用户手动选择的时间,设为“1”可直接引导。

最后重启所有服务:

service xinetd restart

service httpd restart

service dhcpd restart

重启后,就可以新建个虚拟机测试了(注意虚拟机的网卡模式要一致)

因本文只是作为自己总结所用,所以写的比较简单,如有错误之处,也请大家指出来。