主机IP配置: 静态指定 静态IP 动态获取: bootp:bootprotocol MAC与IP一一静态对应 DHCP: Dynamic Host Configuration Protocol 动态主机配置协议基于UTP协议 主要用途:自动化分配IP地址,实现集中管理,解决IP地址不足的问题。 DHCP的4种报文 DHCP DISCOVER OFFER REQUEST ACK 申请过程: Client--> DHCPDISCOVER DHCPOFFER <-- Server Client--> DCHPREQUEST DCHPACK <-- Server Client--> DHCPREQUEST DHCPACK <-- Server 续租IP: 50% :租赁时间达到50%时来续租,刚向DHCP服务器发向新的DHCPREQUEST请求。如果dhcp服务没有拒绝的理由,则回应DHCPACK信息。当DHCP客户端收到该应答信息后,就重新开始新的租用周期 87.5%:如果之前DHCP Server没有回应续租请求,等到租约期的7/8时,主机会再发送一次广播请求 Linux DHCP协议的实现程序:dhcp, dnsmasq(dhcp,dns) DhcpServer /usr/sbin/dhcpd /etc/dhcp/dhcpd.conf--> /etc/rc.d/init.d/dhcpd /etc/dhcp/dhcpd6.conf--> /etc/rc.d/init.d/dhcpd6 /usr/sbin/dhcrelay /etc/rc.d/init.d/dhcrelay dhcpserver:67/udp dhcpclient: 68/udp dhcpv6 client:546/udp vDhcpclient 地址分配记录:/var/lib/dhcpd/dhcpd.leases dhclient 自动获取的IP信息:/var/lib/dhclient 配置示例 option domain-name "magedu.com"; //域名 option domain-name-servers 192.168.0.1,8.8.8.8; //指定DNS服务器 default-lease-time 86400; max-lease-time 86400; subnet 192.168.100.0 netmask 255.255.255.0 { //网段 range 192.168.100.1 192.168.100.200; //可用IP option routers 192.168.100.1; //默认网关 } DHCP服务器由路由器隔开,可在路由器上配置 Router1#configure terminal Router1(config)#interface Ethernet0 Router1(config-if)#ip helper-address 172.25.1.1 Router1(config-if)#ip helper-address 172.25.10.7 Router1(config-if)#end Router1#
实验:基于网络PXE自动化安装CentOS 7
远程客户端计算机启动,由于BIOS设置了网卡启动,所以网卡PXE ROM中的程序被调入内存执行。首先,客户端在网络中寻找DHCP服务器,然后请求一个IP地址;同时DHCP服务器联系到TFTP服务器为此客户端发送一个bootstrap(引导程序)。客户端收到bootstrap(文件pxelinux.0)后执行,bootstrap会请求TFTP传送bootstrap的配置文件(pxelinux.cfg)。收到后读配置文件。根据配置文件内容和客户情况,客户端请求TFTP传送内核映象文件(vmlinuz)和根文件系统文件(initrd.img)。最后启动内核。这就是一个完整的pxe构建过程。然而要使网卡启动后再继续网络安装系统,则最后还需要FTP服务将系统所需安装文件放置FTP相应目录中进行传输安装
1安装前准备:关闭防火墙和SELINUX,DHCP服务器静态IP
2安装相关软件包
yum install httpd tftp-server dhcp syslinux
3 配置文件共享服务和yum源
systemctl enable httpd
systemctl start httpd
mkdir /var/www/html/centos/7
mount /dev/sr0 /var/www/html/centos/7
4 准备kickstart文件
cp /root/anaconda-ks.cfg /var/www/html/ksdir/myks.cfg
chmod +r /var/www/html/ksdir/myks.cfg
vim /var/www/html/ksdir/myks.cfg
cat myks.cfg
#version=DEVEL
# System authorization information
auth –enableshadow –passalgo=sha512
# Use CDROM installation media
url –url=http://192.168.25.107/centos/7
# Use graphical install
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=on –ipv6=auto –activate
network –hostname=centos7.magedu.com
# Root password
rootpw –iscrypted $6$Z7LBEUpwj3iQdYZ3$olYQ.Lj1xV2VAGS1UiNflKF0oMGip3b6tU9QFcp0i2JBjwKlY/Yaexul57NHpIJc.Y2V1hWAOueaqwjuWDGMk0
# System services
services –disabled=”chronyd”
# System timezone
timezone Asia/Shanghai –isUtc –nontp
user –name=wang –password=$6$v.VphW/puRblcrFB$uaSrdEhGAwMXap27WIKTn5lyOOfoFyB/SNxyyL3og6s9/VQoAKoL2KQjKmeYFmoYTuYkSNL7BBxgbJzeryKr9. –iscrypted –gecos=”wang”
# X Window System configuration information
xconfig –startxonboot
# System bootloader configuration
bootloader –append=” crashkernel=auto” –location=mbr –boot-drive=sda
# Partition clearing information
zerombr
clearpart –all
# Disk partitioning information
part swap –fstype=”swap” –ondisk=sda –size=2048
part /app –fstype=”xfs” –ondisk=sda –size=51200
part / –fstype=”xfs” –ondisk=sda –size=51200
part /boot –fstype=”xfs” –ondisk=sda –size=1024
reboot
%packages
@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=50 –notstrict –nochanges –notempty
pwpolicy user –minlen=6 –minquality=50 –notstrict –nochanges –notempty
pwpolicy luks –minlen=6 –minquality=50 –notstrict –nochanges –notempty
%end
%post
systemctl enable autofs
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo <<eof
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
eof
%end
5配置tftp服务
systemctl enable tftp.socket
systemctl start tftp.socket
6配置DHCP服务
vim /etc/dhcp/dhcpd.conf
option domain-name “example.com”;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.25.0 netmask 255.255.255.0 {
range 192.168.25.50 192.168.25.100;
next-server 192.168.25.107;
filename “pxelinux.0”;
}
systemctl enable dhcpd
systemctl start dhcpd
7 准备PXE相关文件
mkdir/var/lib/tftpboot/pxelinux.cfg/
cp/usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
cp/misc/cd/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/
cp/misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
8 制作启动菜单文件
vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600
menu title CentOS Linux 7 PXE Install
label desktop
menu label Auto Install CentOS Linux 7 ^Desktop
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.25.107/ksdir/myks.cfg
label mini
menu label Auto Install CentOS Linux 7 M^ini
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.25.107/ksdir/ks7-2.cfg
label manual
menu label ^Manual Install CentOS Linux 7
kernel vmlinuz
append initrd=initrd.img inst.repo=http://192.168.25.107/centos/7
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
menu end
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/87346