實驗名稱:PXE網路裝機實驗
實驗要求:搭建PXE服務,對裸機進行自動化安裝centos7作業系統
實驗環境:centos7虛擬機一臺,搭建pxe進行網路裝機;一臺裸機,用于驗證
實驗步驟:
1),準備環境
配置網路源yum
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir yum.repos.d.bak
[root@localhost yum.repos.d]# mv C* yum.repos.d.bak
[root@localhost yum.repos.d]# vim yum.repo
# CentOS-Base.repo
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
2),安裝配置所需程式
清空yum快取,重新加載資料,安裝yum擴展包
[root@localhost yum.repos.d]# yum clean all #清空快取
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up everything
[root@localhost yum.repos.d]# yum makecache #加載資料
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/10): base/7/x86_64/primary_db | 6.1 MB 00:00:00
(3/10): base/7/x86_64/other_db | 2.6 MB 00:00:00
(4/10): base/7/x86_64/filelists_db | 7.2 MB 00:00:06
(5/10): extras/7/x86_64/filelists_db | 224 kB 00:00:05
(6/10): extras/7/x86_64/other_db | 134 kB 00:00:00
(7/10): extras/7/x86_64/primary_db | 222 kB 00:00:06
(8/10): updates/7/x86_64/primary_db | 3.7 MB 00:00:01
(9/10): updates/7/x86_64/other_db | 227 kB 00:00:00
(10/10): updates/7/x86_64/filelists_db | 2.1 MB 00:00:01
Determining fastest mirrors
Metadata Cache Created
[root@localhost yum.repos.d]# yum -y install yum-utils #安裝yum擴展程式
安裝dhcp服務程式,編輯dhcp的組態檔
[root@localhost yum.repos.d]# yum -y install dhcp 安裝dhcp服務程式
[root@localhost yum.repos.d]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf #復制檔案,強行覆寫
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@localhost yum.repos.d]# vim /etc/dhcp/dhcpd.conf 配置dhcp
subnet 192.168.22.0 netmask 255.255.255.0 { #網段和子網掩碼
range 192.168.22.80 192.168.22.150; #IP地址池
option domain-name-servers ns1.internal.example.org; #DNS域名服務器
option domain-name "internal.example.org"; #域
option routers 192.168.22.254; #網關
option broadcast-address 192.168.22.255; #廣播
default-lease-time 600; #默認組約時間,單位秒
max-lease-time 7200; #最大租約時間
next-server 192.168.22.100; #PXE服務器IP
filename "pxelinux.0"; #制定引導檔案
}
[root@localhost yum.repos.d]# systemctl start dhcpd #開啟dhcp服務
安裝所需程式
[root@localhost yum.repos.d]# yum -y install syslinux xinetd tftp-server vsftpd #安裝程式
[root@localhost yum.repos.d]# mkdir /var/ftp/centos7 #創建鏡像存放目錄
[root@localhost yum.repos.d]# cp -rf /media/* /var/ftp/centos7/ #復制鏡像資料
[root@localhost yum.repos.d]# cd #切換作業目錄
[root@localhost ~]# vim /etc/xinetd.d/tftp #進行編輯,關閉配置中自動關閉tftf-server服務,yes為默認關閉
disable = no #把此行yes改為no
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg #創建pxelinux.cfg目錄
[root@localhost ~]# cp /media/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #復制模板
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# cp /media/isolinux/vmlinuz /var/lib/tftpboot/
[root@localhost ~]# cp /media/isolinux/initrd.img /var/lib/tftpboot/
[root@localhost ~]# cp /media/isolinux/vesamenu.c32 /var/lib/tftpboot/
[root@localhost ~]# cp /media/isolinux/boot.msg /var/lib/tftpboot/
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 編輯配置,進行修改
label linux
menu label ^Install CentOS Linux 7
kernel vmlinuz
append initrd=initrd.img inst.repo=ftp://192.168.22.100/centos7 inst.ks=ftp://192.168.22.100/ks.cfg
label check
menu label Test this ^media & install CentOS Linux 7
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=ftp://192.168.22.100/yum inst.ks=ftp://192.168.22.100/yum/ks.cfg quiet
[root@localhost ~]# setenforce 0 #暫時關閉沙河
[root@localhost ~]# systemctl start vsftpd #開啟服務
[root@localhost ~]# systemctl start xinetd #開啟服務
安裝使用自動化工具
[root@localhost ~]# yum -y install system-config-kickstart 安裝kickstart自動化工具
[root@localhost ~]# system-config-kickstart 啟動工具










保存后Ctrl+c退出
[root@localhost ~]# vim /root/anaconda-ks.cfg #進入復制內容

[root@localhost ~]# vim ks.cfg 添加復制的anaconda-ks.cfg檔案中內容
[root@localhost ~]# mv ks.cfg /var/ftp/centos7/ #移動

設定防火墻規則
[root@localhost ~]# firewall-cmd --add-service=ftp --permanent
success
[root@localhost ~]# firewall-cmd --add-service=dhcp --permanent
success
[root@localhost ~]# firewall-cmd --add-port=69/udp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
3),使用裸機,進行裝機
需注意運行記憶體至少2G,硬碟大小不小于kickstart設定的大小,裸機和PXE服務器位于同一物理網路


自動安裝


【等安裝完畢,至此PXE網路安裝完成】
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/232114.html
標籤:其他
上一篇:DNS反向決議、主從域名服務器以及域名服務器分離決議(實驗詳解)
下一篇:靜態綜合實驗
