PXE装机(无人值守安装)

版权声明:转载请通知 https://blog.csdn.net/qq_41674452/article/details/85318041

搭建PXE远程装机服务器


实验环境:
一台centos7系统服务器
一台测试客户端,无任何操作系统


1.先搭建本地YUM源:

[root@localhost ~]# rm -rf /etc/yum.repos.d/*									##删除原仓库所有内容
[root@localhost ~]# vi /etc/yum.repos.d/CentOS7.repo							##配置yum仓库
[development]						#此处一定要配置一样的不然一会儿会有报错
name=centos7	
baseurl=file:///mnt
enabled=1
gpgcheck=0                                                                                                            
:wq
[root@localhost ~]# mount /dev/cdrom /mnt/

2.安装配置依赖的服务:
1)安装vsftp并配置共享源

[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# mkdir /var/ftp/centos7
[root@localhost ~]# cp -rf /mnt/* /var/ftp/centos7/
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# yum -y install tftp-server									##安装TFTP-server
[root@localhost ~]# vi /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
:wq
[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl enable tftp

准备Linux内核、初始化镜像文件
[root@localhost ~]# cd /var/ftp/centos7/images/pxeboot/
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot
#准备PXE引导程序、启动菜单文件
#pxe网络安装引导的文件为pxelinux.0,由软件包syslinux提供,安装好软件包syslinux,然后文件pxelinux.0也复制到tftp服务的跟目录下
[root@localhost pxeboot]# yum -y install syslinux
[root@localhost pxeboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# mkdir -p /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default auto															##指定默认入口名称
prompt 1																##1表示等待用户控制/0表示不等待用户控制
label auto
   kernel vmlinuz
   append initrd=initrd.img method=ftp://192.168.3.1/centos7
label linux text
   kernel vmlinuz
   append text initrd=initrd.img method=ftp://192.168.3.1/centos7

label linux rescue
   kernel vmlinuz
   append rescue initrd=initrd.img method=ftp://192.168.3.1/centos7

:wq

2)安装并启用dhcp服务

[root@localhost ~]# yum -y install dhcp									##安装DHCP
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.3.0 netmask 255.255.255.0 {
        option routers 192.168.3.1;
        option subnet-mask 255.255.255.0;
        option domain-name "benet.com";
        option domain-name-servers 192.168.3.30,202.106.0.20;
        default-lease-time 21600;
        max-lease-time 43200;
        range 192.168.3.100 192.168.3.200;
        next-server 192.168.3.1;                              ##指定TFTP服务器的地址
        filename "pxelinux.0";   								##指定PXE引导程序的文件名
}
:wq
[root@localhost ~]# systemctl start dhcpd.service
[root@localhost ~]# systemctl enable dhcpd.service

3.配置PXE无人值守安装:

[root@localhost ~]# yum -y install system-config-kickstart
[root@localhost ~]# system-config-kickstart ##打开图形配置工具
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
##如果你出现如下错误检查你的YUM源配错了一定是,检查重新生成文件
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
[root@localhost ~]# ls
anaconda-ks.cfg ks.cfg 模板 图片 下载 桌面
initial-setup-ks.cfg 公共 视频 文档 音乐

#先要用到图形化配置生成一个PXE装机的配置文件#

[root@localhost ~]# grep -v ^# /root/ks.cfg 
install
keyboard 'us'
rootpw --iscrypted $1$nN4grZjY$CjKJ7hxMdB1FNBjCcX6QM0
url --url="ftp://192.168.3.1/centos"
lang zh_CN
firewall --disabled
auth  --useshadow  --passalgo=sha512
graphical
firstboot --disable
selinux --disabled

network  --bootproto=dhcp --device=ens32
reboot
timezone Asia/Shanghai
bootloader --location=none
clearpart --all
part /boot --fstype="xfs" --size=500
part /home --fstype="xfs" --size=4096
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --size=1

%post --interpreter=/bin/bash
rm -f /etc/yum.repo.d/*
echo -e '[base]\nname=CentOS7.4\nbaseurl=ftp://192.168.3.1/centos7\nenabled=1\ngp
%end

[root@localhost ~]# cp /root/ks.cfg /var/ftp/ks.cfg
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default 
default auto
prompt 0                                                ##0表示不等待用户控制
label auto
   kernel vmlinuz
   append initrd=initrd.img method=ftp://192.168.3.1/centos7
   ks=ftp://192.168.3.1/ks.cfg
:wq

4.测试:
#只需要开机
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41674452/article/details/85318041