无人值守装机PXE
Centos 6.8 部署无人值守装机pxe
PXE原理
1.定义
PXE (Pre-boot Execution Environment) 是由Intel设计的协议,它可以使计算机通过网络启动。协议分为client和server两端,PXE client在网卡的ROM中,当计算机引导时,BIOS把PXE client调入内存执行,并显示出命令菜单,经用户选择后,PXE client将放置在远端的操作系统通过网络下载到本地运行。
2.安装过程图解
PXE服务构建
1.注意事项
- 虚拟环境中注意是否将自带DHCP功能关闭;
- 注意测试安装机器是否将网络与PXE服务器网络对齐;
2.安装流程记录
-
安装centos 6.8系统,关闭dhcp
-
本地挂载iso配置本地yum
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount -o loop /dev/cdrom /mnt/cdrom/
[root@localhost ~]# vim /etc/fstab
/dev/cdrom /mnt/cdrom/ iso9660 loop 0 0
配置yum
[root@localhost ~]# vim /etc/yum.repos.d/rhel-source.repo
[CDROM]
name=localyum yum
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-6
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache -
安装环境
[root@localhost ~]# yum install vsftpd dhcp tftp syslinux tftp-server -y
-
拷贝镜像文件到ftp服务器目录
[root@localhost ~]# cd /var/ftp/pub/
[root@localhost pub]# mkdir dvd
[root@localhost pub]# chown ftp:ftp dvd/
[root@localhost pub]# cp -rf /mnt/cdrom/* dvd/ -
配置DHCP服务
[root@localhost ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 10.10.10.0 netmask 255.255.255.0 {
range 10.10.10.100 10.10.10.200;
option routers 10.10.10.10;
next-server 10.10.10.10; # tftp server的IP
filename "pxelinux.0";
} -
开启tftp服务
[root@localhost ~]# vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot # 设置默认工作目录
disable = no # 设置开机自启动
per_source = 11
cps = 100 2
flags = IPv4
}
[root@localhost ~]# mkdir /tftpboot -
创建相关目录并拷贝所需文件
[root@localhost ~]# mkdir -p /tftpboot/pxelinux.cfg
[root@localhost ~]# cp /var/ftp/pub/dvd/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
[root@localhost ~]# chmod 644 /tftpboot/pxelinux.cfg/default
[root@localhost ~]# cp /var/ftp/pub/dvd/isolinux/* /tftpboot/ -
开启相关服务并设置开机自启
[root@localhost ~]# service httpd restart && chkconfig dhcpd on
[root@localhost ~]# service xinetd restart && chkconfig xinetd on
[root@localhost ~]# service vsftpd restart && chkconfig vsftpd on -
关闭防火墙和selinux
[root@localhost ~]# service iptables stop
[root@localhost ~]# setenforce 0 -
配置kisckstart无人值守安装脚本
[root@localhost ~]# yum install -y system-config-kickstart
[root@localhost ~]# system-config-kickstart
[root@localhost ~]# mv ks.cfg /var/ftp/
本机文件/root/anaconda-ks.cfg内容的%packages-%end中间是本机所装的rpm包,可以讲此段内容复制到ks.cfg中
[root@localhost ~]# vim /tftpboot/pxelinux.cfg/default
default linux
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz append initrd=initrd.img ks=ftp://10.10.10.10/ks.cfg