目录
一、实验环境准备
二、CentOS7 pxe准备:
三、操作步骤
1.安装dhcp、tftp、http、syslinux
2.配置dhcp服务
3.配置tftp服务器
?4.拷贝PXE服务器的相关文件到/var/lib/tftpboot(tftp的根目录)
5.配置http服务器
6.配置ks.cfg文件
7.重启所有服务
四、创建虚拟机进行测试
一、实验环境准备
1.CentOS7:192.168.150.141
2.若干安装的CentOS虚拟机
二、CentOS7 pxe准备:
1.关闭防火墙
systemctl stop firewalld.service
2.关闭selinux
[root@192 ~]# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled ###修改为 :SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
三、操作步骤
1.安装dhcp、tftp、http、syslinux
2.配置dhcp服务
yum -y install dhcp
安装后,?DHCP?服务的主配置文件为?/etc/dhcp/dhcp.conf?,我们可以修改配置文件以实现为客户端分配网络参数。
copy样例文件到/etc/dhcp/dhcp.conf,如下操作:
[root@192 ~]# cd /etc/dhcp/
[root@192 dhcp]# ls
dhclient.d dhclient-exit-hooks.d dhcpd6.conf dhcpd.conf scripts
[root@192 dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example ./
修改配置文件?:??vim /etc/dhcp/dhcpd.conf 如下修改:
[root@192 dhcp]# cat dhcpd.conf
subnet 192.168.150.0 netmask 255.255.255.0 {
range 192.168.150.10 192.168.150.100;
default-lease-time 3600;
filename "pxelinux.0";
next-server 192.168.150.141;
}
重启服务
systemctl restart dhcpd
3.配置tftp服务器
TFTP?服务为客户端提供一种简单的文件共享,非常适用于传输小且简单的?PXE?启动文件
yum install?tftp-server -y
编辑/etc/xinetd.d/tftp?
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
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
}
disable?=?no?#把原来的yes改成no
改完重启服务
systemctl restart tftp?
?4.拷贝PXE服务器的相关文件到/var/lib/tftpboot(tftp的根目录)
安装syslinux并拷贝pxelinux.0文件到TFTP服务器
yum install syslinux?-y?#通过安装syslinux获取引导文件
cp?/usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/? ? ##引导文件
cp?/usr/share/syslinux/menu.c32??/var/lib/tftpboot/? ? ##菜单文件
将镜像放在光驱并运行如下命令,从光盘中复制启动镜像文件和启动配置文件到TFTP共享目录
mount?-o?loop?-t?iso9660 /dev/sr0 /media?
将镜像中的相关文件复制到tftp根目录
cp? /media/isolinux/vmlinuz??/var/lib/tftpboot/? ?##安装引导文件1
cp? /media/isolinux/initrd.img? /var/lib/tftpboot/? ?##安装引导文件2
在tftpboot目录下创建目录pxelinux.cfg
cd /var/lib/tftpboot/ mkdir pxelinux.cfg cd pxelinux.cfg
创建如下default文件?:
default menu.c32
timeout 300
prompt 0
label 1
menu label ^1) Install CentOS7
menu default
kernel vmlinuz
append initrd=initrd.img method=http://192.168.150.141/CentOS7 ks=http://192.168.150.141/ks.cfg
5.配置http服务器
yum install httpd -y
在/var/www/html/目录下创建目录CentOS7?
[root@192 pxelinux.cfg]# cd /var/www/html/
[root@192 html]# mkdir CentOS7
?将/dev/cdrom挂载在该目录下:
?mount /dev/cdrom /var/www/html/CentOS7/
保证能看到安装光盘的内容:http://192.168.150.141/CentOS7/
6.配置ks.cfg文件
先看模板文件:
[root@192 ~]# ll
total 4
-rw-------. 1 root root 1492 Sep 14 08:02 anaconda-ks.cfg
cp anaconda-ks.cfg ?/var/www/html/
?然后改名为ks.cfg
mv anaconda-ks.cfg ks.cfg
??保证能看到安装脚本文件的信息:http://192.168.150.141/ks.cfg
chmod +r ks.cfg
?修改里面内容:
开头修改部分:
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#cdrom
url --url http://192.168.150.141/CentOS7 ###第一处修改
# Use graphical install
#graphical ###第二处修改
text ###第三次修改
中间修改部分:
# Partition clearing information
#clearpart --none --initlabel ###第一处修改
clearpart --all --initlabel ###第二处修改
# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=500
part pv.253 --fstype="lvmpv" --ondisk=sda --size=19979
volgroup centos --pesize=4096 pv.253
logvol / --fstype="xfs" --size=17927 --name=root --vgname=centos
logvol swap --fstype="swap" --size=2048 --name=swap --vgname=centos
结尾处修改:
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
reboot ###加个reboot
7.重启所有服务
?systemctl restart httpd ?systemctl restart tftp ?systemctl restart dhcpd
四、创建虚拟机进行测试
点击开启虚拟机:
?自动安装中:
?等待几分钟就ok了:
|