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
1 /etc/xinetd.d/tftp2 /usr/lib/systemd/system/tftp.service3 /usr/lib/systemd/system/tftp.socket4 /usr/sbin/in.tftpd5 /usr/share/doc/tftp-server-5.2
6 /usr/share/doc/tftp-server-5.2/CHANGES7 /usr/share/doc/tftp-server-5.2/README8 /usr/share/doc/tftp-server-5.2/README.security9 /usr/share/man/man8/in.tftpd.8.gz10 /usr/share/man/man8/tftpd.8.gz11 /var/lib/tftpboot # 默认共享路径
View Code
[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
dhcpd.conf
[root@t2 ~]# systemctl start dhcpd.service
通过另外一台服务器配置dhcp设置网卡后,在dhcp服务器上存在租赁记录:
[root@t2 /etc/dhcp]# tail /var/lib/dhcpd/dhcpd.leases
dhcpd.leases
1 lease 10.0.10.11{2 starts 6 2017/08/19 14:46:16;3 ends 6 2017/08/19 14:56:16;4 cltt 6 2017/08/19 14:46:16;5 binding state active;6 next binding state free;7 rewind binding state free;8 hardware ethernet 00:0c:29:e3:ea:af;9 client-hostname "t3";10 }
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
1 default menu.c322 prompt 5
3 timeout 15
4 MENU TITLE Hello , luomr5
6 LABEL linux7 MENU LABEL Install CentOS /x86_648 KERNEL vmlinuz9 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/
1 #platform=x86, AMD64, 或 Intel EM64T2 #version=DEVEL3 # Install OS instead of upgrade4 install
5 # Keyboard layouts6 keyboard 'us'
7 # Root password8 rootpw --plaintext 000000
9 # Use network installation10 url --url="http://10.0.10.1/Centos7"
11 # System language12 lang zh_CN13 # Firewall configuration14 firewall --disabled15 # System authorization information16 auth --useshadow --passalgo=sha51217 # Use graphical install
18 graphical19 # SELinux configuration20 selinux --disabled21 # Do not configure the X Window System22 skipx23
24 # Network information25 network --bootproto=dhcp --device=eth026 # Reboot after installation27 reboot28 # System timezone29 timezone Asia/Shanghai30 # System bootloader configuration31 bootloader --location=mbr32 # Partition clearing information33 clearpart --all --initlabel34 # Disk partitioning information35 part /boot --fstype="ext4" --ondisk=sda --size=200
36 part /usr/local --fstype="ext4" --ondisk=sda --size=8000
37 part swap --fstype="swap" --ondisk=sda --size=800
38 part / --fstype="ext4" --grow --ondisk=sda --size=1
39
40 %packages41 @development42 @remote-system-management43 ElectricFence44 ant45 babel46 bzr47 chrpath48 cmake49 cvs50 expect51 imake52 ksc53 lrzsz54 libstdc++-docs55 mercurial56 nasm57 net-tools58 perltidy59 rpmdevtools60 rpmlint61 vim62 systemtap-sdt-devel63 systemtap-server64
65 %end66
67 %post --interpreter=/bin/sh
68 #!/bin/bash69 #by luomr70
71 #deploy yum
72 rm -rf /etc/yum.repos.d/*.repo73 cat>/etc/yum.repos.d/local.repo << EOF74 [Centos7]75 name=This is a local repo76 baseurl=http://10.0.10.1/Centos7
77 enabled=178 gpgcheck=079 EOF80 yum clean all && yum list81
82 #network83 systemctl restart network.service84
85 ifconfig |grep inet|awk 'NR==1{print $2}' >/tmp/ip_local86 ip=`cat /tmp/ip_local`87 #nwn : network name88 nwn=`ifconfig |grep eno|awk -F: '{print $1}'`89 path_n=/etc/sysconfig/network-scripts/ifcfg-"$nwn"90
91
92 sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' $path_n93 cat>>$path_n <
98 ifdown $nwn && ifup $nwn99
100 %end
ks.cfg
配置完毕,测试,本人实操成功!