(基于vsftpd提供YUM软件仓库,基于PXE方式实现网络安装,基于kickstart配置文件实现自动应答。)
系统环境(本实验为RHEL6虚拟机环境操作)
软件环境:
vsftpd-2.2.2-6.el6_0.1.i686
sysstat-9.0.4-18.el6.i686
dhcp-4.1.1-19.P1.el6.i686
tftp-server-0.49-5.1.el6
xinetd-2.3.14-31.el6
system-config-kickstart-2.8.6.3-1.el6 一、搭建PXE远程安装服务器
1.准备RHEL6安装源
[root@localhost ~]# rpm -ivh
vsftpd-2.2.2-6.el6_0.1.i686 //安装vsftpd软件包
[root@localhost ~]# mkdir /var/ftp/rhel6
[root@localhost ~]# cp -rf /media/cdrom/*
/var/ftp/rhel6/ [root@localhost ~]# iptables -I INPUT -p tcp --dport 21 -j
ACCEPT
[root@localhost ~]# service vsftpd start
[root@localhost ~]# chkconfig vsftpd on
---YUM客户机配置---
[root@localhost ~]# vi /etc/yum.repos.d/rhel6.repo
[base]
name=Red Hat Enterprise Linux
baseurl=ftp://192.168.4.254/rhel6
enabled=1
gpgcheck=1
2. 安装并启用TFTP服务 [root@localhost ~]# yum -y install tftp-server
xinetd
[root@localhost ~]# vi /etc/xinetd.d/tftp
service tftp
{
......
protocol =
udp //TFTP采用UDP传输协议
server = /usr/sbin/in.tftpd
server_args =
-s
/var/lib/tftpboot //指定TFTP根目录
disable = no
}
[root@localhost ~]# iptables -I INPUT -p udp --dport 69 -j
ACCEPT
[root@localhost ~]# service iptables save
[root@localhost ~]# service xinetd start
[root@localhost ~]# chkconfig xinetd on
3.
准备Linux内核、初始化镜像、PXE引导程序、启动菜单配置 [root@localhost ~]# cd
/media/cdrom/images/pxeboot/
[root@localhost pxebot]# cp vmlinuz initrd.img
/var/lib/tftpboot/
4.准备PXE引导程序、启动菜单文件
[root@localhost ~]# yum -y install syslinux (注:若安装报错,需卸载光盘)
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0
/var/lib/tftpboot/
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default
auto //指定默认入口名称prompt
1 //1表示等待用户控制
label
auto //图形安装 kernel vmlinuz append
initrd=initrd.img devfs=nomount ramdisk_size=8192
label linux text //文本安装 kernel vmlinuz
append text
initrd=initrd.img devfs=nomount ramdisk_size=8192
label linux rescue //救援模式 kernel vmlinuz
append
rescue initrd=initrd.img devfs=nomount ramdisk_size=8192
5. 启用DHCP服务 [root@localhost ~]# yum -y install dhcp
[root@localhost ~]# vi /etc/dhcp/dhcpd.conf
...... //省略部分信息
subnet 192.168.4.254 netmask 255.255.255.0 {
option
routers 192.168.4.254;
option
subnet-mask 255.255.255.0;
option
domain-name "benet.com";
option
domain-name-servers 192.168.4.254 202.106.0.20;
default-lease-time 21600;
max-lease-time 43200;
range
192.168.4.100 192.168.4.200;
next-server
192.168.4.254; //指定TFTP服务器的地址
filename
"pxelinux.0"; //指定PXE引导程序的文件名
}
[root@localhost ~]# service dhcpd start
[root@localhost ~]# chkconfig dhcpd on
6. 验证PXE网络装机
将客户机以PXE方式引导,即可通过服务器192.168.4.254来远程安装RHEL6系统。 二、配置kickstart无人值守安装
1. 准备自动应答文件
建议在图形桌面中运行system-config-kickstart配置工具,设置好各种安装应答参数,最后保存位ks-pxe.cfg响应文件。对应答配置语句比较熟练的用户,也可以直接参照/root/anaconda-ks.cfg文件进行修改。
[root@localhost ~]# yum -y install system-config-kickstart
[root@localhost ~]#
system-config-kickstart //在图形桌面下运行
......
[root@localhost ~]# vi /root/ks-pxe.cfg
firewall --disabled
selinux --disabled
install
url --url="ftp://192.168.4.254/rhel6"
rootpw --iscrypted $1$88pFSACUN$dYnvka2DtXCRhjOJz0PWe/
auto --useshadow --passalgo=sha512
......
%packages
@base
@development
@web-server
%end
%post --interpreter=/bin/bash
rm -rf /etc/yum.repos.d/*
echo '[base]
name=Red Hat Enterprise Linux
baseurl=ftp://192.168.4.254/rhel6
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release' >
/etc/yum.repos.d/rhel6.repo
%end
2. 调整PXE引导配置,加入对应答文件的调用 [root@localhost ~]# cp /root/ks-pxe.cfg
/var/ftp/rhel6/ks.cfg
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt
0 // 0 表示不等待用户控制
label auto
kernel
vmlinuz
append
ks=ftp://192.168.4.254/ks-pxe.cfg initrd=initrd.img devfs=nomount
ramdisk_size=8192
......
3. 验证PXE+kickstart无人值守自动安装 客户机安装完成以后,检查其YUM仓库配置,可以发现已经按照“安装后脚本”的设置自动建立了/etc/yum.repos.d/rhel6.repo。
[root@localhost ~]# cat /etc//yum.repos.d/rhel6.repo
[base]
name=Red Enterprise Linux
baseurl=ftp://192.168.4.254/rhel6
enabled=1
gpgcheck=1