PXE自動化安裝Centos7

一、PXE介紹

    PXE: Preboot Excution Environment,由Intel公司研發,可以使沒有任何操作系統的主機能夠基于網絡完成系統的安裝工作,實現服務器的自動化安裝系統

二、PXE工作原理

  • Client向PXE Server上的DHCP發送IP地址請求消息,DHCP檢測Client是否合法(主要是檢測Client的網卡MAC地址),如果合法則返回Client的IP地址,同時將啟動文件pxelinux.0的位置信息一并傳送給Client
  • Client向PXE Server上的TFTP發送獲取pxelinux.0請求消息, TFTP接收到消息之后再向Client發送pxelinux.0大小信息,試探Client是否滿意,當TFTP收到Client發回的同意大小信息之后,正式向Client發送pxelinux.0
  • Client執行接收到的pxelinux.0文件
  • Client向TFTP Server發送針對本機的配置信息文件(在TFTP 服務的pxelinux.cfg目錄下), TFTP將配置文件發回Client,繼而Client根據配置文件執行后續操作
  • Client向TFTP發送Linux內核請求信息, TFTP接收到消息之后將內核文件發送給Client
  • Client向TFTP發送根文件請求信息, TFTP接收到消息之后返回Linux根文件系統
  • Client啟動Linux內核
  • Client下載安裝源文件,讀取自動化安裝腳本

三、PXE Server 的配置

   PXE自動化安裝Centos7

                                                            圖1 PXE Server 的依賴服務

1. DHCP服務的配置

 安裝包:dhcp-4.2.5-47.el7.centos.x86_64

[root@centos7 ~]#cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf  --> 使用模本配置文件
[root@centos7 ~]#vi /etc/dhcp/dhcpd.conf

subnet 192.168.196.0 netmask 255.255.255.0 {                --> 定義網段
  range 192.168.196.10 192.168.196.40;                      --> 定義分配IP范圍
  option routers 192.168.196.1;                             --> 配置路由
  filename "pxelinux.0";                                    --> 啟動文件名稱
  next-server 192.168.196.188;                              --> dhcp服務器地址                           
}
[root@centos7 ~]#systemctl start dhcpd
[root@centos7 ~]#systemctl enable dhcpd

配置完成,并設置DHCP靜態IP192.168.196.188。目標主機開機獲取IP后,可以訪問PXE Sever

2. tftp、httpd服務的配置

安裝包:tftp-5.2-13.el7.x86_64    httpd-2.4.6-45.el7.centos.x86_64

[root@Centos7 ~]#yum -q -y tftp  
[root@Centos7 ~]#yum -q -y httpd
[root@Centos7 ~]#systemctl start tftpd.socket httpd
[root@Centos7 ~]#systemctl enable tftp.socket
[root@Centos7 ~]#systemctl enable httpd

注意:centos6里tftp是由xinetd服務代理的,需要先安裝xinetd服務,再chkconfig tftp on 命令開啟tftp服務

3.關閉SElinux、防火墻

[root@Centos7 ~]#setenforce 0
[root@Centos7 ~]#vi /etc/selinux/config                      --> 修改配置文件
    SELINUX=permissive
[root@Centos7 ~]#systemctl stop firewalld
[root@Centos7 ~]#systemctl disable firewalld

4.kickstart應答文件準備

[root@centos7 ~]#mkdir /var/www/html/{centos7,ks}                       --> PXE Sever http服務會提供網絡源于ks文件
[root@centos7 ~]#cp ~/anaconda-ks.cfg /var/www/html/ks/centos7-m.cfg    --> 以系統安裝ks文件為范本
[root@centos7 ks]#vi centos7-m.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
url --url=http://192.168.196.188/centos7/                                --> 網絡源由PXE Sever http服務提供
text                                                                     --> 文本界面安裝
# Run the Setup Agent on first boot
firstboot --disable
reboot                                                                    --> 安裝完成后重啟
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network  --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate  -->網卡配置
network  --hostname=centos7.ffu.com
# Root password
rootpw --iscrypted $6$8sIxlzOyC1RQ4g.X$UXgct3LHH67rVNH5StXAall/82K/5OkK6.QijHagr.DB4zw8IbnI0CYIUUAhTSDa.dfVfnZabRVZ8nFq5Cc1c1
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --none --initlabel
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=2048
part /app --fstype="ext4" --ondisk=sda --size=50000
part / --fstype="ext4" --ondisk=sda --size=100000
part /boot --fstype="ext4" --ondisk=sda --size=1000

%packages                                                                   --> 安裝包選擇
@^minimal
@core
kexec-tools
%end                                                                        -->各個模塊要以%end結束

%addon com_redhat_kdump --enable --reserve-mb='auto'
%end

%post                                                                       -->安裝完成后運行自定義腳本
useradd ffu
echo 123456|passwd --stdin ffu rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo << EOF
[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
EOF
%end

%anaconda
pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --notempty
%end
 
[root@centos7 ks]#chmod a+r centos7-m.cfg                                      --> 為other加讀權限,以便能通過http訪問
[root@centos7 ks]#ll
-rw-r--r--. 1 root root 2042 Jul 24 15:00 centos7-m.cfg

5. 安裝源準備

[root@centos7 ks]# mount /dev/sr0 /var/www/html/centos7/

6. 啟動菜單、內核等相關文件準備

a.相關文件準備

[root@centos7 tftpboot]#mkdir /var/lib/tftpboot/pxelinux.cfg
[root@centos7 tftpboot]#cp /var/www/html/centos7/isolinux/isolinux.cfg  pxelinux.cfg/default    -->復制安裝光盤啟動菜單并重命名
[root@centos7 tftpboot]#cp /usr/share/syslinux/menu.c32 /usr/share/syslinux/pxelinux.0  ./      -->復制syslinux的菜單及啟動文件
[root@centos7 tftpboot]#cp /var/www/html/centos7/isolinux/vmlinuz /var/www/html/centos7/isolinux/initrd.img ./
[root@centos7 tftpboot]#tree                                                                    -->目錄結構
.
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│   └── default
└── vmlinuz

b.啟動菜單定制

[root@centos7 tftpboot]#vi pxelinux.cfg/default
default menu.c32                                                            -->所用菜單文件
timeout 600
menu title PXE CentOS Linux 7 Install Menu

label linux-mini
  menu label ^Auto-install CentOS Linux 7 Mini
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.196.188/ks/centos7-m.cfg      -->ks文件由PXE Sever http服務提供

label linux-desktop
  menu label Test Auto-install CentOS Linux 7 ^Desktop
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.196.188/ks/centos7.cfg        -->可根據不同目的定制不同應答文件
label linux-manual
  menu label Test ^Manual-Install CentOS Linux 7
  kernel vmlinuz
  append initrd=initrd.img

label local
  menu label Boot from ^local drive
  menu default
  localboot 0xffff

四、主機自動化安裝系統實現

a.使用VMware實驗,根據以上步驟配置PXE Server,然后新建虛擬機

PXE自動化安裝Centos7

b.開機進入啟動菜單,選擇最小化安裝

PXE自動化安裝Centos7

c.安裝完成

PXE自動化安裝Centos7

原創文章,作者:ffu,如若轉載,請注明出處:http://www.www58058.com/82613

(1)
ffuffu
上一篇 2017-07-24 21:00
下一篇 2017-07-25 09:14

相關推薦

  • linux一周學習總結

          對于linux,之前也完全沒有接觸過,完全零基礎小白。來到馬哥以后,進入學習也有一周時間 ,一周里老師帶我們學習了很多指令,下面,我就自己的理解和老師講授的內容對linux中的一些指令做一個簡單的小總結。 一、關于SHELL Shell     查詢當前系統使用了哪個shell   &n…

    2017-07-15
  • GlusterFS測試報告-02(結合samba為windows提供服務)

    在掛載glusterFS的客戶機的目錄下,使用samba分享給windows機器使用 1、samba服務的安裝 [root@client01 ~]# yum -y install samba [root@client01 ~]# /etc/init.d/smb restart S…

    Linux干貨 2016-07-22
  • linux之netfilter與 iptables學習

    Linux之netfilter與iptables學習 一、為什么我們的主機需要防火墻 二、Linux下防火墻如何實現 三、四表五鏈學習 四、主機防火墻 五、網絡防火墻 六、iptables命令學習 七、主機防火墻規則備份與恢復 ====================================== 一、為什么我們的主機需要防火墻?  &nbs…

    Linux干貨 2016-06-23
  • 使用pyenv管理不同版本的python

    安裝: 安裝: $ curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash 在你的shellrc文件中添加: export PATH=”$HOME/.pyenv/bin:$PATH” eval “$(pyenv init …

    Linux干貨 2015-03-12
  • nginx在linux系統應用詳解之一基礎介紹和全局配置

    一、nginx簡介       1、特點:           (1)nginx服務器既可以作為HTTP服務器,也可以作為反向代理服務器,還可以作為郵件服務器;           (2)能夠快速響應靜態頁面的請求;  …

    2017-06-19
  • 第1周-1:計算機的組成及其功能以及部分常見Linux發行版簡介

    一、計算機的組成及其功能: 計算機主要由硬件部分和軟件部分組成。 1、硬件部分 (1)中央處理器 由控制器和運算器兩大部分組成,是計算機的大腦,硬件部分里最關鍵的部分。決定著整個計算機系統的性能。 控制器負責協調計算機硬件的其他部分同步工作,對其他的硬件進行發號施令。是計算機系統的司令??刂破鲝拇鎯ζ髦凶x取指令,分析指令的含義,要完成什么操作,需要什么數據,…

    Linux干貨 2016-11-01
欧美性久久久久