PXE全自动远程安装


#1).安装部署:

yum install dhcp httpd tftp-server.x86_64 syslinux
[[email protected] ~]# vim /etc/xinetd.d/tftp
PXE全自动远程安装
                                                                                
[[email protected] ~]# systemctl restart xinetd.service
[[email protected] ~]# netstat -antlupe | grep 69

udp        0      0 0.0.0.0:69              0.0.0.0:*                           0          38911      2649/xinetd

PXE全自动远程安装


[[email protected] ~]# cd /var/www/html/rhel7.0/isolinux/

[[email protected] isolinux]# scp * [email protected]:/var/lib/tftpboot

PXE全自动远程安装   

 [[email protected] tftpboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[[email protected] tftpboot]# ls
boot.cat  grub.conf   isolinux.bin  memtest     TRANS.TBL    vesamenu.c32
boot.msg  initrd.img  isolinux.cfg  pxelinux.0  splash.png  upgrade.img  vmlinuz
[[email protected] tftpboot]# mkdir pxelinux.cfg
[[email protected] tftpboot]# cp isolinux.cfg pxelinux.cfg/default

PXE全自动远程安装


[[email protected] tftpboot]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[[email protected] tftpboot]# vim /etc/dhcp/dhcpd.conf

PXE全自动远程安装


[[email protected] tftpboot]# systemctl restart dhcpd

将要安装系统的主机通过网卡启动,会通过dhcpd服务获得一个ip来进行安装。但是会卡到第二幅图的界面,因为default里指定的安装源是镜像文件。所以要对安装源重新进行指定。

PXE全自动远程安装


PXE全自动远程安装

#2).配置
[[email protected] tftpboot]# vim pxelinux.cfg/default
default vesamenu.c32
timeout 600                    #等待时间
menu background haha.png            #背景
menu title Red Hat Enterprise Linux 7.0        #标题


默认的安装源:

PXE全自动远程安装

label linux
  menu label ^Install Red Hat Enterprise Linux 7.0
  kernel vmlinuz

  append initrd=initrd.img repo=http://172.25.254.26/rhel7.0 quiet

新指定的安装源:

PXE全自动远程安装


label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.0
  menu default                    #光标默认位置
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rd.live.check quiet

修改背景要注意原背景的分辨率大小

PXE全自动远程安装  

用convert命令可以对图片做细些简单的修改。 

   [[email protected] tftpboot]# yum whatprovides convert            

    [[email protected] tftpboot]# yum install ImageMagick-6.7.8.9-10.el7.x86_64    
    [[email protected] tftpboot]# convert -resize 640x480! westos.png haha.png    
    [[email protected] tftpboot]# file haha.png                     
    haha.png: PNG image data, 640 x 480, 8-bit/color RGBA, non-interlaced  
  

    PXE全自动远程安装


至此就可以通过网络进行正常的安装了。

PXE全自动远程安装


#3).自动安装

将kickstart与远程安装结合,就可以实现远程自动安装了。

制作kickstart:

PXE全自动远程安装PXE全自动远程安装PXE全自动远程安装PXE全自动远程安装


[[email protected] tftpboot]# vim pxelinux.cfg/default

label linux
  menu label ^Install Red Hat Enterprise Linux 7.0
  kernel vmlinuz

  append initrd=initrd.img repo=http://172.25.254.26/rhel7.0 ks=http://172.25.254.160/ks.cfg quiet      #指定ks的位置

PXE全自动远程安装


[[email protected] tftpboot]# vim /var/www/html/ks.cfg
%packages          #要安装的包
@base
%end

%post        #安装后执行的动作
cat >> /etc/yum.repos.d/yum.repo <<EOF  #配置yum源
[rhel7]
name=rhel7
baseurl=http://172.25.254.26/rhel7.0
gpgcheck=0
EOF

rm -fr /etc/sysconfig/network-scriptd/ifcfg-eth0     #配置网络
cat >>/etc/sysconfig/network-scriptd/ifcfg-eth0<< EOF
DEVICE=eth0
ONBOOT =yes
BOOTPROTO=none
IPADDR=172.25.254.266
PREFIX=24
EOF

yum install httpd -y              #搭建httpd服务
systemctl start httpd
systemctl enable httpd
firewall-cmd --permanent --add-service=http
firewall-cmd--reload
%end


自动安装过程实现。至此我们只需要将要安装系统的主机通过网卡启动即可让它自动安装了。

PXE全自动远程安装