1. 需要使用到的服务:PXE + DHCP+TFTP+ Kickstart+ FTP
2. 配置本地yum源,把光盘镜像挂载到/mnt目录下
[root@wyq ~]# cat /etc/yum.repos.d/CD-source.repo #配置本地yum源
[CD-source]
name=CD-source
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@wyq ~]# mount /dev/sr0 /mnt/ #挂载镜像
3. 安装配置DHCP服务
① [root@wyq ~]# yum -y install dhcp #yum安装dhcp
② 修改dhcp配置文件
[root@wyq ~]# cat /etc/dhcp/dhcpd.conf
subnet 10.10.10.0 netmask 255.255.255.0 { #指定网段
range 10.10.10.100 10.10.10.200; #指定ip范围
option domain-name-servers 10.10.0.2; #指定dns
option domain-name "internal.example.org";
option routers 10.10.10.2; #指定网关
option broadcast-address 10.10.10.255;
default-lease-time 600;
max-lease-time 7200;
next-server 10.10.10.10; #TFTP服务器
filename "pxelinux.0";#镜像名称
}
③ [root@wyq ~]# systemctl start dhcpd #启动服务
④ [root@wyq ~]# systemctl enable dhcpd #开机运行服务
4. 安装配置FTP服务(这里ftp配置默认即可)
⑤ [root@wyq ~]# yum -y install vsftpd #yum安装
⑥ [root@wyq ~]# systemctl start vsftpd #启动服务
⑦ [root@wyq ~]# systemctl enable vsftpd #开机运行服务
5. 安装配置TFTP服务
⑧ [root@wyq ~]# yum -y install tftp tftp-server xinetd #yum安装
⑨ [root@wyq ~]# cat /etc/xinetd.d/tftp #配置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 /tftpboot#服务器默认目录
disable= no
per_source = 11
cps = 100 2
flags = IPv4
}
⑩ [root@wyq ~]# systemctl start xinetd #启动服务
⑪ [root@wyq ~]# systemctl enable xinetd #开机运行服务
6. 配置使用PXE启动所需的相关文件
⑫ [root@wyq ~]# yum -y install system-config-kickstart syslinux#安装服务
⑬ 准备tftp需要共享出去的文件
[root@wyq ~]# mkdir /tftpboot
[root@wyq ~]# mkdir /tftpboot/pxelinux.cfg
[root@wyq ~]# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
#只有安装了syslinux软件包,才会有/usr/share/syslinux/目录及目录中的文件。
[root@wyq ~]# cp /mnt/images/pxeboot/initrd.img /tftpboot/
[root@wyq ~]# cp /mnt/images/pxeboot/vmlinuz /tftpboot/
[root@wyq ~]# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
[root@wyq ~]# chmod 644 /tftpboot/pxelinux.cfg/default
⑭ 修改default,指定安装操作系统的方式和ks.cfg文件路径
[root@wyq ~]# vim /tftpboot/pxelinux.cfg/default
label linux
menu label ^^Install RHEL 7.0
menu default
kernel vmlinuz
append initrd=initrd.img inst.ks=ftp://10.10.10.10/ks.cfg
label linux
menu label ^Install Red Hat Enterprise Linux 7.0
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 quiet
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
⑮ 接下来我们制作kickstart的无人值守安装文件
[root@wyq ~]# system-config-kickstart
#调出图形界面(需要安装图形界面)
安装脚本:在"预安装脚本","安装后脚本"对话框中,可以分别添加在安装前、安装后自动动行的可执行语句。此项设置可以使服务器自动化配置变得更加容易。
到此所有关于安装的配置已经配置完毕,保存:
点击左上角的文件选择保存,选择下保存的路径
[root@test1 ~]#cp ks.cfg /var/ftp #复制ks.cfg文件到/var/ftp目录下
注:ks.cfg就是无人值守安装时要用的Kickstart文件。
要对应:/tftpboot/pxelinux.cfg/default文件中设置过ks=ftp://10.10.10.10/ks.cfg
# 因为system-config-kickstart编辑模板时不能选择软件安装包,所以可以把anaconda-ks.cfg的软件包安装脚本拷贝到ks.cfg中,只要拷贝%packages ----- %end之间的,然后复制到ks.cfg的最下面即可
# 最小化安装
%packages
@^minimal
@core
kexec-tools
%end
7. 配置完成,开始测试
在同一网段(10.10.10.0/24)开启一台机器,开机进入BIOS界面,把启动首选项调整为网络启动,F10保存,开机实现无人值守安装