注:文中出现的sed 命令可根据后面注释说明使用vim代替
原理:
PXE网卡启动
-=>
DHCP服务器获得IP
-=>
TFTP下载"pxelinux.0"、"vmlinuz"、"initrd"
-=>启动系统
-=> FTP下载文件
-=>系统安装
1、IP:172.16.7.1
netmask:255.255.0.0
2、hostname
tiga.jk.com
3、mount /dev/sr0
/media
1、DHCP
[root@tiga ~]# rpm
-ivh/media/Packages/dhcp-4.2.5-27.el7.x86_64.rpm
[root@tiga ~]# grep -vE
'#|^$'/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example >
/etc/dhcp/dhcpd.conf//将dhcp.conf.example文件中的非空行和非注释行取出,写入dhcp.conf中
[root@tiga ~]# vi /etc/dhcp/dhcpd.conf
option domain-name
"jk.com";//默认分配域名
option domain-name-servers
172.16.7.1;//指定DNS服务器
default-lease-time
600;//默认DHCP租约时间
max-lease-time
7200;//DHCP服务最大租约时间
log-facility local7;
allow
booting;//允许从DHCP网卡启动
allow
bootp;//允许从DHCP网卡启动
subnet 172.16.0.0 netmask255.255.0.0 {
range 172.16.7.50
172.16.7.80;//设置dhcp地址池范围
optionrouters
172.16.7.1;//设置默认网关,一般为本机
next-server
172.16.7.1;//设置tftp服务器地址
filename "pxelinux.0";
}
#host PChostname
{//设置特定机器的主机名,可不设置
#hardware ethernet
00:50:56:C0:00:01;//特定机器网卡的MAC地址
#fixed-address
172.16.7.77;//特定机器的IP
#}
[root@tiga ~]# systemctl restart dhcpd.service
[root@tiga ~]# chkconfig dhcpd on
[root@tiga ~]# firewall-cmd
--permanent--add-service=dhcp
[root@tiga ~]# systemctl restart
firewalld.service
2、TFTP
[root@tiga ~]# rpm
-ivh/media/Packages/{tftp-server*,xinetd-*}//tftp安装包依赖xinet,两个包都要装
[root@tiga ~]# sed -i
'/disable/s/yes/no/'/etc/xinetd.d/tftp//修改/etc/xinetd.d/tftp文件中disable行的yes为no
[root@tiga ~]# systemctl restart xinetd.service
[root@tiga ~]# systemctl status xinetd |
grepActive//可以看到Active状态为running
Active:
active(running) since Wed 2014-08-13 15:18:02 CST; 24s
ago
[root@tiga ~]# firewall-cmd
--permanent--add-port=69/udp//在防火墙上打开tftp需要的69号端口
[root@tiga ~]# systemctl restart
firewalld.service
3、syslinux
[root@tiga~]# rpm -ivh
/media/Packages/syslinux-4.05-8.el7.x86_64.rpm
[root@tiga~]# cd /var/lib/tftpboot
[root@tigatftpboot]# cp /usr/share/syslinux/pxelinux.0
./
[root@tigatftpboot]# cp
/media/images/pxeboot/{initrd.img,vmlinuz} ./
[root@tigatftpboot]# mkdir pxelinux.cfg
[root@tigatftpboot]# cp
/media/isolinux/{vesamenu.c32,*.msg} ./
[root@tigatftpboot]# cp /media/isolinux/isolinux.cfg
pxelinux.cfg/default
[root@tigatftpboot]# sed
-i'/inst.stage2/s/=hd:LABEL=RHEL-7.0\\\x20Server.x86_64/=ftp:\/\/172.16.7.1/'/var/lib/tftpboot/pxelinux.cfg/default
//把default文件中的"=hd:LABEL=RHEL-7.0\x20Server.x86_64"改成"ftp://172.16.7.1"
4、vsftp
[root@tiga ~]# rpm
-ivh/media/Packages/vsftpd-3.0.2-9.el7.x86_64.rpm
[root@tiga ~]# service vsftpd start
[root@tiga ~]# chkconfig vsftpd on
[root@tiga ~]# firewall-cmd
--permanent--add-service=ftp
[root@tiga ~]# service firewalld restart
[root@tiga ~]# cp -r /mediatimezone Asia\/Shanghai/'
/var/ftp/pub/ks.cfg
//把ks.cfg文件中的"timezone"行替换为"timezone
Asia/Shanghai"
[root@tiga ~]# sed
-i'/append/s?quiet?ks=ftp://172.16.7.1/pub/ks.cfg
quiet?'/var/lib/tftpboot/pxelinux.cfg/default
//把default文件中的quiet替换为ks=ftp://172.16.7.1/pub/ks.cfg
quiet
6、Client setup
关闭vmware dhcp
service服务设置从网卡启动开机
(注:如果是更改BIOS启动项的话,一定要把硬盘启动设置为第一项,然后再是网卡启动,否则会循环安装)