Pxe+kickstart 無人值守安裝centos7.2(最小化)
1.什麼是pxe
PXE(preboot execute environment,預啟動執行環境)是由Intel公司開發的技術,
工作於Client/Server的網路模式,支援工作站通過網路從遠端伺服器下載映像,並由此支援通過網路啟動作業系統,在啟動過程中,終端要求伺服器分配IP地址,
再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)
下載一個啟動軟體包到本機記憶體中執行,由這個啟動軟體包完成終端(客戶端)基本軟體設定,
從而引導預先安裝在伺服器中的終端作業系統。
2.流程圖
原理介紹:
1.Client向PXE Server上的DHCP傳送IP地址請求訊息,DHCP檢測Client是否合法(主要是檢測Client的網絡卡MAC地址),如果合法則返回Client的IP地址,同時將啟動檔案pxelinux.0的位置資訊一併傳送給Client
2.Client向PXE Server上的TFTP傳送獲取pxelinux.0請求訊息,TFTP接收到訊息之後再向Client傳送pxelinux.0大小資訊,試探Client是否滿意,當TFTP收到Client發回的同意大小資訊之後,正式向Client傳送pxelinux.0
3.Client執行接收到的pxelinux.0檔案
4.Client向TFTP Server傳送針對本機的配置資訊檔案(在TFTP服務的pxelinux.cfg目錄下,這是系統選單檔案,格式和isolinux.cfg格式一樣,功能也是類似),TFTP將配置檔案發回Client,繼而Client根據配置檔案執行後續操作。
5.Client向TFTP傳送Linux核心請求資訊,TFTP接收到訊息之後將核心檔案傳送給Client
6.Client向TFTP傳送根檔案請求資訊,TFTP接收到訊息之後返回Linux根檔案系統
7.Client啟動Linux核心
8.Client下載安裝原始檔,讀取自動化安裝指令碼
二、安裝步驟:
1.需要安裝的服務
①.DHCP
②.TFTP
③.HTTP
④.PXE
⑤.syslinux
2.系統環境
2.1系統版本
[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
2.2系統ip
[[email protected] ~]# ifconfig eno16777736
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.134 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe03:1e48 prefixlen 64 scopeid 0x20<link
2.3系統核心版本
[[email protected] ~]# uname -r
3.10.0-327.el7.x86_64
3.關閉防火牆與selinux
[[email protected] ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[[email protected] ~]# setenforce 0
4.安裝服務,我這裡使用的是阿里雲的ym源。
[[email protected] ~]# yum install dhcp httpd tftp-server httpd xinetd -y
5.建立目錄並掛載映象
[[email protected] ~]# mkdir /var/www/html/Centos-7.2
[[email protected] ~]# mount /dev/cdrom /var/www/html/Centos-7.2/
mount: /dev/sr0 is write-protected, mounting read-only
6.啟動http服務
[[email protected] ~]# rm -f /etc/httpd/conf.d/welcome.conf
[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
7.配置tftp[[email protected] ~]# vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no(yes改為no)
per_source = 11
cps = 100 2
flags = IPv4
}
7.1啟動tftp服務
[[email protected] ~]# systemctl enable xinetd
[[email protected] ~]# systemctl start xinetd
7.2將pxelinux.0 複製到tftpboot/目錄下
[[email protected] ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
7.3建立pxelinux.cfg目錄,將映象檔案拷到/var/lib/tftpboot/目錄下
[[email protected] ~]# mkdir /var/lib/tftpboot/pxelinux.cfg[[email protected] ~]# cp /var/www/html/Centos-7.2/isolinux/* /var/lib/tftpboot/
[[email protected] ~]# cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
8.配置dhcp
[[email protected] ~]# cat /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example >>/etc/dhcp/dhcpd.conf
[[email protected] ~]# vim /etc/dhcp/dhcpd.conf
45 subnet 10.0.0.0 netmask 255.255.255.0{
46 range dynamic-bootp 10.0.0.100 10.0.0.200;
47 option subnet-mask 255.255.255.0;
48 next-server 10.0.0.134;
49 filename "pxelinux.0";
50 }
8.1啟動dhcp服務
[[email protected] ~]# systemctl start dhcpd
[[email protected] ~]# systemctl enable dhcpd
9.配置ks.cfg檔案
[[email protected] ~]# yum install system-config-kickstart -y
9.1安裝完成後,在桌面環境下,執行system-config-kickstart開始配置ks.cfg檔案
[[email protected] ~]# system-config-kickstart
9.2配置時區與登入密碼
9.3映象掛載的http地址
9.4後面的不再多做解釋,沒有截圖的即是不需要配置
9.5將ks檔案複製到/var/www/html/目錄下
[[email protected] ~]# cp ks2.cfg /var/www/html/
在ks檔案最後新增(最小化安裝)
39 %packages --nobase
40
41 @core
42
43 %end
通過網址驗證:
10.修改default檔案(修改大概第64行,並刪除大概第69行的“menu default”)
[[email protected] ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
61 label linux
62 menu label ^Install CentOS 7
63 kernel vmlinuz
64 append initrd=initrd.img repo=http://10.0.0.134/Centos-7.2/ ks=http://10.0.0.134/ks2.cfg
65
66 label check
67 menu label Test this ^media & install CentOS 7
68 kernel vmlinuz
69 append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
70
11.重啟服務
[[email protected] ~]# systemctl restart xinetd dhcpd httpd12.建立虛擬機器測試
因為我的服務端使用的是nat地址轉換網路模式,所以客戶機也設定一樣
13.ks檔案配置
[[email protected] ~]# cat /var/www/html/ks2.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$4PiIy2LI$sfi.D9Pn4VueLuayH1sRF/
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.134/Centos-7.2/"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1
%packages --nobase
@core
%end
借鑑部落格:https://blog.csdn.net/ghost_leader/article/details/52985811