首先修改作为DHCP服务器的网卡配置信息
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens192
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPADDR=15.1.1.1
NETMASK=255.255.255.0
NAME=ens192
DEVICE=ens192
ONBOOT=yes
安装httpd tftp-server dhcp syslinux xinetd
[root@localhost ~]# yum install httpd tftp-server dhcp syslinux xinetd –y
修改dhcp配置文件做广播服务器
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
authoritative;
allow booting;
allow bootp;
subnet 15.1.1.0 netmask 255.255.255.0 #指定网段
{ option routers 15.1.1.1; #指定网关
option subnet-mask 255.255.255.0;
range dynamic-bootp 15.1.1.2 15.1.1.200; #分配地址池
next-server 15.1.1.1; #DHCP服务器地址
filename "pxelinux.0"; #PXE所需文件
default-lease-time 21000;
max-lease-time 43200;
option time-offset -18000;
}
修改tftp配置将disable选项由yes改为no
[root@localhost ~]# vim /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
}
拷贝安装所有需要的cfg文件
[root@localhost ~]# cp /root/anaconda-ks.cfg /var/www/html/ks.cfg
[root@localhost ~]# chmod 555 /var/www/html/ks.cfg
修改cfg文件
[root@localhost ~]# vim /var/www/html/ks.cfg
#version=RHEL7
# Install OS instead of upgrade
install
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url "http://15.1.1.1/centos" #安装源修改为网络路径
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts=‘us‘
reboot
# System language
lang en_US.UTF-8
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Network information
network --bootproto=dhcp --device=ens160 --onboot=off --ipv6=auto
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$AtHUq/R7EaCq4m4t$j17qu0sg1DwO2vYoyOmaTtyqsLRjPD.PW0mrj92.OXWb9ujyAfx.Cp9SJQwYAzeBpd1KN4Lq8CsygWZRZw610/
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@core
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb=‘auto‘
%end
创建安装源和安装文件
[root@localhost ~]# mkdir /var/www/html/centos
[root@localhost ~]# mkdir /var/www/html/centos
[root@localhost ~]# mount /dev/cdrom /mnt/
[root@localhost ~]# cp -r /mnt/* /var/www/html/centos/
[root@localhost ~]# yum install tree –y
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# cp /var/www/html/centos/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@localhost ~]# cp /var/www/html/centos/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/
[root@localhost ~]# cp /var/www/html/centos/isolinux/{vesamenu.c32,boot.msg,splash.png} /var/lib/tftpboot/
[root@localhost ~]# tree -aL 2 /var/www/html/
/var/www/html/
├── centos
│ ├── CentOS_BuildTag
│ ├── EFI
│ ├── EULA
│ ├── GPL
│ ├── images
│ ├── isolinux
│ ├── LiveOS
│ ├── Packages
│ ├── repodata
│ ├── RPM-GPG-KEY-CentOS-7
│ ├── RPM-GPG-KEY-CentOS-Testing-7
│ └── TRANS.TBL
└── ks.cfg
7 directories, 7 files
修改default文件
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 60
display boot.msg
# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS 7
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
# Border Area
menu color border * #00000000 #00000000 none
# Selected item
menu color sel 0 #ffffffff #00000000 none
# Title bar
menu color title 0 #ff7ba3d0 #00000000 none
# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none
# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none
# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none
# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none
# Help text
menu color help 0 #ffffffff #00000000 none
# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none
# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label linux
menu label ^Install CentOS 7
kernel vmlinuz
menu default
#append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
append initrd=initrd.img inst.ks=http://15.1.1.1/ks.cfg quiet
label check
menu label Test this ^media & install CentOS 7
menu default
kernel vmlinuz
#append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
append initrd=initrd.img inst.ks=http://15.1.1.1/ks.cfg quiet
menu separator # insert an empty line
# utilities submenu
menu begin ^Troubleshooting
menu title Troubleshooting
label vesa
menu indent count 5
menu label Install CentOS 7 in ^basic graphics mode
text help
Try this option out if you‘re having trouble installing
CentOS 7.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet
label rescue
menu indent count 5
menu label ^Rescue a CentOS system
text help
If the system will not boot, this lets you access files
and edit config files to try to get it booting again.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet
label memtest
menu label Run a ^memory test
text help
If your system is having issues, a problem with your
system‘s memory may be the cause. Use this utility to
see if the memory is working correctly.
endtext
kernel memtest
menu separator # insert an empty line
label local
menu label Boot from ^local drive
localboot 0xffff
menu separator # insert an empty line
menu separator # insert an empty line
label returntomain
menu label Return to ^main menu
menu exit
menu end
[root@localhost ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot.msg
├── initrd.img
├── pxelinux.0
├── pxelinux.cfg
│ └── default
├── splash.png
├── vesamenu.c32
└── vmlinuz
1 directory, 7 files
开启服务并且查看服务开启情况
[root@localhost ~]# systemctl start httpd dhcpd tftp xinetd
[root@localhost ~]# systemctl enable httpd dhcpd tftp xinetd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# netstat -tupln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2385/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1079/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1077/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1758/master
tcp6 0 0 :::80 :::* LISTEN 5884/httpd
tcp6 0 0 :::22 :::* LISTEN 1079/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1077/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1758/master
udp 0 0 0.0.0.0:43741 0.0.0.0:* 5890/dhcpd
udp 0 0 192.168.122.1:53 0.0.0.0:* 2385/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 5890/dhcpd
udp 0 0 0.0.0.0:67 0.0.0.0:* 2385/dnsmasq
udp 0 0 0.0.0.0:69 0.0.0.0:* 5897/xinetd
udp 0 0 0.0.0.0:123 0.0.0.0:* 6105/ntpdate
udp 0 0 127.0.0.1:323 0.0.0.0:* 742/chronyd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 779/avahi-daemon: r
udp 0 0 0.0.0.0:1282 0.0.0.0:* 779/avahi-daemon: r
udp6 0 0 :::55402 :::* 5890/dhcpd
udp6 0 0 :::69 :::* 1/systemd
udp6 0 0 :::123 :::* 6105/ntpdate
udp6 0 0 ::1:323 :::* 742/chronyd
原文地址:http://10804685.blog.51cto.com/10794685/1794189