一、实验环境准备
- CentOS7:192.168.239.12(自定ip,要在所选网卡的网段内)
必须要配置网络,使得能ping通百度就ok
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
- 若干台预安装的CentOS虚拟机(建议内存设置为2G)
如上选择了VMnet8作为主机网卡,则需要部署的若干台虚拟机都要选择此网卡。
CentOS7 pxe准备:
1、关闭防火墙(systemctl status firewalld / service iptables status
暂时关闭防火墙:systemctl stop firewalld / service iptables stop)
2、关闭selinux(临时关闭selinux:# setenforce 0
也可以编辑# vim /etc/selinux/config
SELINUX=disabled
重启生效)cd 查看状态
1,Enforcing (记录警告且阻止可疑行为)
2,Permissive (代表仅记录安全警告但不阻止可疑行为)
3,Disabled (禁用状态)
3、配置yum源文件
<1>、通过yum安装wget下载工具
yum install -y wget
<2>、将系统默认的yum源备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
<3>、通过wget下载aliyun的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
<4>、通过aliyun的yum源安装epel源
yum install -y epel-release
<5>、清除yum
yum clean all
<6>、创建yum缓存
yum makecache
二、实验步骤
(创建cdrom文件夹:cd /media
mkdir cdrom)
(挂载镜像:mount /dev/cdrom /media/cdrom)
1、安装dhcp、tftp-server、http、syslinux
yum -y install dhcp tftp-server httpd syslinux
2、配置dhcp服务
subnet 192.168.239.0 netmask 255.255.255.0 {
range 192.168.239.30 192.168.239.99;
default-lease-time 600;
filename "pxelinux.0";
next-server 192.168.239.12;
}
注意pxelinux.0颜色。
3、配置tftp服务器
启用tftp服务:
vim /etc/xinetd.d/tftp
----> disable = no;
重启服务
systemctl restart tftp.socket
4、拷贝PXE服务器的相关文件---->tftp的根目录
[root@192 xinetd.d]# cd /var/lib/tftpboot
[root@192 tftpboot]# ls
[root@192 tftpboot]# cp /usr/share/syslinux/pxelinux.0 ./ 引导文件
[root@192 tftpboot]# cp /usr/share/syslinux/menu.c32 ./ 菜单文件
[root@192 tftpboot]# cp /media/cdrom/isolinux/vmlinuz ./ 安装引导文件1
[root@192 tftpboot]# cp /media/cdrom/isolinux/initrd.img ./ 安装引导文件2
[root@192 tftpboot]# ls
initrd.img menu.c32 pxelinux.0 vmlinuz
5、制作安装的菜单文件
mkdir /var/lib/tftpboot/pxelinux.cfg/
touch /var/lib/tftpboot/pxelinux.cfg/default
编辑default文件:
cd /var/lib/tftpboot/pxelinux.cfg/default
vim default
default menu.c32
timeout 30
prompt 0
label 1
menu label ^1) Install CentOS7
menu default
kernel vmlinuz
append initrd=initrd.img method=http://192.168.239.12/CentOS7 ks=http://192.168.239.12/ks.cfg
6、配置web服务器
保证用户可以看到安装光盘的内容:
访问:http://192.168.239.12/CentOS7
保证用户可以看到安装脚本文件的信息:
访问:http://192.168.239.12/ks.cfg
[root@192 pxelinux.cfg]# systemctl restart httpd
[root@192 pxelinux.cfg]# cd /var/www/html/
[root@192 html]# ls
[root@192 html]# mkdir CentOS7
[root@192 html]# ls
CentOS7
[root@192 html]# cd CentOS7/
[root@192 CentOS7]# ls
[root@192 CentOS7]# cd
[root@192 ~]# mount /dev/cdrom /var/www/html/CentOS7/
mount: /dev/sr0 is write-protected, mounting read-only
[root@192 ~]# cd -
/var/www/html/CentOS7
[root@192 CentOS7]# ls
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
7、编辑ks.cfg文件
[root@192 CentOS7]# cd
[root@192 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg
[root@192 ~]# cp anaconda-ks.cfg /var/www/html/
[root@192 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg
[root@192 ~]# cd /var/www/html/
[root@192 html]# mv anaconda-ks.cfg ks.cfg
[root@192 html]# ls
CentOS7 ks.cfg
[root@192 html]# ll
total 6
drwxrwxr-x. 8 huaxin huaxin 2048 Nov 26 2018 CentOS7
-rw-------. 1 root root 1718 Sep 3 10:06 ks.cfg
[root@192 html]# chmod +r ks.cfg
[root@192 html]# vim ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#cdrom
url --url http://192.168.239.12/CentOS7
# Use graphical install
#graphical
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=ens33 --onboot=off --ipv6=auto --no-activate
network --hostname=localhost.localdomain
# Root password
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
#clearpart --all --initlabel --drives=sda
clearpart --all --initlabel --drives=sda
%packages
@^graphical-server-environment
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@x11
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%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
8、重启所有的服务,使配置生效
[root@192 html]# systemctl restart httpd
[root@192 html]# systemctl restart tftp.socket
[root@192 html]# systemctl restart dhcpd
至此,pxe服务器安装配置完成,后续只要在vmware中开启dhcp就可以实现无人值守安装系统。