PXE批量自动部署linux系统环境

1、基础网络建设与搭建DHCP服务

1)配置静态IP地址并重起网卡

cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.0.4
NETMASK=255.255.255.0
GATEWAY=10.0.0.2

/etc/init.d/network restart
ifconfig eth0

2)安装配置DHCP服务

yum -y install dhcp
vim /etc/dhcp/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
option domain-name-servers 202.106.0.20;   #DNS地址可配置2个用逗号分隔
ignore client-updates;

subnet 10.0.0.0 netmask 255.255.255.0 {
  range 10.0.0.100 10.0.0.150;              #宣告获取地址段
  option subnet-mask 255.255.255.0;         #子网
  option routers 10.0.0.2;                  #获取网关地址
  next-server 10.0.0.4;                     #重点配置PEX地址
  filename "pxelinux.0";                    #内核文件名

#配置开机自启动
chkconfig --add dhcpd
chkconfig dhcpd on
chkconfig --list dhcpd
#查看DHCP监听端口好UDP 67
netstat -lntup|grep 67

2、搭建TFTP服务

yum -y install tftp-server tftp

vim /etc/xinetd.d/tftp
#配置TFTP配置文件:
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /tftpboot          #修改TFTP服务目录
        disable                 = no                    #修改为no,启动TFTP
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

#配置自启动
chkconfig tftp on
chkconfig --list tftp
chkconfig --list xinetd
#重启动xinetd服务,TFTP是由xinetd服务运行的
/etc/init.d/xinetd restart
netstat -lntup|grep 69 ;netstat -a|grep tftp
udp 0 0 0.0.0.0:69 0.0.0.0:* 1877/xinetd
udp 0 0 *:tftp
#TFTP端口号为UDP的69
#测试下载
mkdir /tftpboot
cd /tftpboot/
touch test.txt
ls
test.txt
cd ..
tftp 10.0.0.4 -c get test.txt
ls #下载成功!
test.txt

3、搭建HTTP服务

yum -y install httpd
#配置自启动
chkconfig --add httpd
chkconfig httpd on
chkconfig --list httpd
#启动http服务
/etc/init.d/httpd start
netstat -lntup|grep 80

#使用浏览器测试
http://10.0.0.4

4、组建PXE服务环境

1)安装syslinux包
yum -y install syslinux
#如不安装syslinux包就没有pxelinux.0文件
find / -type f -name "pxelinux.0"
/usr/share/syslinux/pxelinux.0
#将pxelinux.0拷贝到tftp服务目录
cp /usr/share/syslinux/pxelinux.0 /tftpboot/
#在tftp服务目录下创建pxelinux.cfg目录
mkdir /tftpboot/pxelinux.cfg -p
2)挂载linux系统盘,拷贝linux内核,初始化镜像文件
mkdir -p /media/cdrom
mount -t iso9660 -o loop /dev/sr0 /media/cdrom
cd /media/cdrom/images/pxeboot
cp vmlinuz initrd.img /tftpboot/
cd /tftpboot/
ls
initrd.img pxelinux.0 pxelinux.cfg vmlinuz
#配置启动菜单文件,将系统自带的启动文件拷贝到TFTP目录下改名为
cp /media/cdrom/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
#修改启动菜单文件

cat default 

default auto   #指定默认启动项
prompt 0       #为0时不选择自动按默认安装,为1时可选择选项安装

label auto     #配置选项auto
  kernel vmlinuz   #指定内核
  append initrd=initrd.img ks=http://10.0.0.4/ks.cfg devfs=nomount ramdisk_size=8192   #指定自动安装文件ks.cfg
label linux text
  kernel vmlinuz
  append initrd=initrd.img devfs=nomount ramdisk_size=8192
label rescue
  kernel vmlinuz
  append initrd=initrd.img rescue
#重启动TFTP服务加载配置
/etc/init.d/xinetd restart

5、创建kickstart文件

1)安装system-config-kickstart
yum -y install system-config-kickstart
#注意安装桌面服务才能启动KICKSTART,创建启动文件
/usr/bin/system-config-kickstart

cat ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration关闭防火墙
firewall --disabled
# Install OS instead of upgrade 安装系统
install
# Use network installation  使用网络安装,这里配置http获取安装包
url --url="http://192.168.146.128/"
key --skip
# Root password  配置ROOT密码
rootpw --iscrypted $1$jIsDXG2F$EGT.VAhEBlZ/ww9GNOTo7.
# System authorization information 系统授权信息
auth  --useshadow  --passalgo=md5
# Use graphical install 图形安装
graphical
# System keyboard 配置键盘
keyboard us
# System language 配置系统语言
lang en_US
# SELinux configuration 关闭selinux
selinux --disabled
# Do not configure the X Window System 不安装图形界面
skipx
# Installation logging level 安装系统日志记录级别
logging --level=info
# Reboot after installation 安装完重新引导
reboot
# System timezone  #配置时区
timezone  Asia/Shanghai
# Network information 配置网络为自动获取
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration 系统引导程序配置
bootloader --location=mbr
# Clear the Master Boot Record 清除主引导记录
zerombr
# Partition clearing information 分区信息
clearpart --all  
# Disk partitioning information  指定分区大小
part swap --fstype="swap" --size=2048
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --grow --size=1

%packages
@base
@compat-libraries
@debugging
@development

%end

#将应答脚本拷贝到http目录,并赋予权限
cp ks.cfg /var/www/html/
chown apache.apache /var/www/html/ks.cfg

6、启动客户机安装

注意:客户机要和服务器在同一个局域网内
如果使用vmware做实验,需要关闭VMware自带的DHCP功能

排除思路:
1)客户机是否获取IP地址,可查看网络和DHCP服务
2)查看链接TFTP是否正常
如链接正常在获取IP地址后会显示:
TFTP prefix:
trying to load: pxelinux.cfg/default ok
然后加载内核:
loading vmlinuz........
loading initrd.img.........
3)加载完内核后会链接下载安装系统文件,如tfp,http获取等

posted @ 2017-04-18 15:01  Py.qi  阅读(4181)  评论(0编辑  收藏  举报