PXE:preboot execute environment
环境实现:主服务器ip:10.0.10.1
1 tfpt
trivial简单文件共享服务,基于udp协议工作;
加载系统安装程序;
69/udp
[root@t2 ~]# yum list *tftp*
[root@t2 ~]# yum install tftp tftp-server
[root@t2 ~]# rpm -ql tftp-server
/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd..gz
/usr/share/man/man8/tftpd..gz
/var/lib/tftpboot # 默认共享路径
[root@t2 ~]# systemctl start tftp.service
2 dhcp
dynamic host configuration protocol
提供地址池(租约);不能跨路由器;
能提供的信息包括:ip, netmask, gateway, dns server, dns search domain, nis server, lease time
C/S:
Client :68/udp
Server:67/udp
C S C S
dhcpdiscover-->dhcppoffer-->dhcprequest-->dhcpack
注:因VM虚拟机提供dhcp服务功能,故测试不能使用自带的三种用户模式,应自建虚拟网络。
ifconfig eth1 10.0.10.1/24 up
[root@t2 ~]# yum -y install dhcp
[root@t2 ~]# rpm -ql dhcp
cp -p /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@t2 ~]# cat /etc/dhcp/dhcpd.conf
[root@t2 ~]# systemctl start dhcpd.service
通过另外一台服务器配置dhcp设置网卡后,在dhcp服务器上存在租赁记录:
[root@t2 /etc/dhcp]# tail /var/lib/dhcpd/dhcpd.leases
lease 10.0.10.11 {
starts // ::;
ends // ::;
cltt // ::;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet :0c::e3:ea:af;
client-hostname "t3";
}
3 http
[root@t2 ~]# yum -y install httpd
[root@t2 ~]# cat /etc/httpd/conf/httpd.conf|grep IncludeOptional
#IncludeOptional conf.d/*.conf
[root@t2 ~]# systemctl start httpd.service
mount /dev/sr0 /var/www/html/Centos7
准备系统文件:
[root@t2 ~]# yum -y install syslinux
[root@t2 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@t2 ~]# cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/
[root@t2 ~]# cp /usr/share/syslinux/{chain.c32,mboot.c32,menu.c32,memdisk} /var/lib/tftpboot/
[root@t2 ~]# mkdir -pv /var/lib/tftpboot/pxelinux.cfg
[root@t2 ~]# cat pxelinux.cfg/default
default menu.c32
prompt
timeout
MENU TITLE Hello , luomr LABEL linux
MENU LABEL Install CentOS / x86_64
KERNEL vmlinuz
APPEND initrd=initrd.img inst.repo=http://10.0.10.1/Centos7 ks=http://10.0.10.1/ks.cfg
default
确认文件:
[root@t2 /var/lib/tftpboot]# ls
chain.c32 mboot.c32 menu.c32 pxelinux.cfg
initrd.img memdisk pxelinux.0 vmlinuz
4 ks.cfg
注:以下为ks.cfg内容,可直接复制粘贴使用
[root@t2 ~]# cp ks.cfg /var/www/html/
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext
# Use network installation
url --url="http://10.0.10.1/Centos7"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx # Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --ondisk=sda --size=
part /usr/local --fstype="ext4" --ondisk=sda --size=
part swap --fstype="swap" --ondisk=sda --size=
part / --fstype="ext4" --grow --ondisk=sda --size= %packages
@development
@remote-system-management
ElectricFence
ant
babel
bzr
chrpath
cmake
cvs
expect
imake
ksc
lrzsz
libstdc++-docs
mercurial
nasm
net-tools
perltidy
rpmdevtools
rpmlint
vim
systemtap-sdt-devel
systemtap-server %end %post --interpreter=/bin/sh
#!/bin/bash
#by luomr #deploy yum
rm -rf /etc/yum.repos.d/*.repo
cat>/etc/yum.repos.d/local.repo << EOF
[Centos7]
name=This is a local repo
baseurl=http://10.0.10.1/Centos7
enabled=1
gpgcheck=0
EOF
yum clean all && yum list #network
systemctl restart network.service ifconfig |grep inet|awk 'NR==1{print $2}' >/tmp/ip_local
ip=`cat /tmp/ip_local`
#nwn : network name
nwn=`ifconfig |grep eno|awk -F: '{print $1}'`
path_n=/etc/sysconfig/network-scripts/ifcfg-"$nwn" sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' $path_n
cat>>$path_n <<EOF
IPADDR=$ip
NETMASK=255.255.255.0
EOF ifdown $nwn && ifup $nwn %end
ks.cfg
配置完毕,测试,本人实操成功!