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
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
1 /etc/xinetd.d/tftp
2 /usr/lib/systemd/system/tftp.service
3 /usr/lib/systemd/system/tftp.socket
4 /usr/sbin/in.tftpd
5 /usr/share/doc/tftp-server-5.2
6 /usr/share/doc/tftp-server-5.2/CHANGES
7 /usr/share/doc/tftp-server-5.2/README
8 /usr/share/doc/tftp-server-5.2/README.security
9 /usr/share/man/man8/in.tftpd.8.gz
10 /usr/share/man/man8/tftpd.8.gz
11 /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
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
dhcpd.conf
[root@t2 ~]# systemctl start dhcpd.service
通過另外一台伺服器配置dhcp設定網卡後,在dhcp伺服器上存在租賃記錄:
[root@t2 /etc/dhcp]# tail /var/lib/dhcpd/dhcpd.leases
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
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
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
1 default menu.c32
2 prompt 5
3 timeout 15
4 MENU TITLE Hello , luomr
5
6 LABEL linux
7 MENU LABEL Install CentOS / x86_64
8 KERNEL vmlinuz
9 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/
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
1 #platform=x86, AMD64, 或 Intel EM64T
2 #version=DEVEL
3 # Install OS instead of upgrade
4 install
5 # Keyboard layouts
6 keyboard 'us'
7 # Root password
8 rootpw --plaintext 000000
9 # Use network installation
10 url --url="http://10.0.10.1/Centos7"
11 # System language
12 lang zh_CN
13 # Firewall configuration
14 firewall --disabled
15 # System authorization information
16 auth --useshadow --passalgo=sha512
17 # Use graphical install
18 graphical
19 # SELinux configuration
20 selinux --disabled
21 # Do not configure the X Window System
22 skipx
23
24 # Network information
25 network --bootproto=dhcp --device=eth0
26 # Reboot after installation
27 reboot
28 # System timezone
29 timezone Asia/Shanghai
30 # System bootloader configuration
31 bootloader --location=mbr
32 # Partition clearing information
33 clearpart --all --initlabel
34 # Disk partitioning information
35 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 %packages
41 @development
42 @remote-system-management
43 ElectricFence
44 ant
45 babel
46 bzr
47 chrpath
48 cmake
49 cvs
50 expect
51 imake
52 ksc
53 lrzsz
54 libstdc++-docs
55 mercurial
56 nasm
57 net-tools
58 perltidy
59 rpmdevtools
60 rpmlint
61 vim
62 systemtap-sdt-devel
63 systemtap-server
64
65 %end
66
67 %post --interpreter=/bin/sh
68 #!/bin/bash
69 #by luomr
70
71 #deploy yum
72 rm -rf /etc/yum.repos.d/*.repo
73 cat>/etc/yum.repos.d/local.repo << EOF
74 [Centos7]
75 name=This is a local repo
76 baseurl=http://10.0.10.1/Centos7
77 enabled=1
78 gpgcheck=0
79 EOF
80 yum clean all && yum list
81
82 #network
83 systemctl restart network.service
84
85 ifconfig |grep inet|awk 'NR==1{print $2}' >/tmp/ip_local
86 ip=`cat /tmp/ip_local`
87 #nwn : network name
88 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_n
93 cat>>$path_n <<EOF
94 IPADDR=$ip
95 NETMASK=255.255.255.0
96 EOF
97
98 ifdown $nwn && ifup $nwn
99
100 %end
ks.cfg
配置完畢,測試,本人實操成功!
-------------------------------------------------------------
作者:
羅穆瑞出處:
http://www.cnblogs.com/kazihuo/轉載請保留此段聲明,且在文章頁面明顯位置給出原文連結,謝謝!
------------------------------------------------------------------------------
如果覺得這篇文章對你有小小的幫助的話,記得在右下角點個“推薦”哦,部落客在此感謝!