CentOS7 PXE安裝批量安裝操做系統

1.安裝相關軟件

yum -y install tftp-server httpd dhcp syslinuxhtml

2.配置DHCP

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
egrep -v "^#|^$" /etc/dhcp/dhcpd.conflinux

option domain-name "contoso.com";
option domain-name-servers ns1.contoso.com, contoso.com;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.10.0 netmask 255.255.255.0 {  //服務端IP網段及掩碼
option routers 192.168.10.254; //網關
option subnet-mask 255.255.255.0; //掩碼
option domain-name-servers 192.168.10.2;
range dynamic-bootp 192.168.10.100 192.168.10.120;  //dhcp分發的地址範圍
default-lease-time 21600; //設置默認的IP租用期限
max-lease-time 43200; //設置最大的IP租用期限
next-server 192.168.10.7;  //TFTP服務器地址
filename "pxelinux.0"; //指定引導文件位置,這裏是TFTP根目錄下的pxelinux.0
}

測試部署,DHCP由路由提供,需配置 Next server 、Boot File Name pxelinux.0

  • 啓動DHCP服務
    systemctl start dhcpd.service

3.配值tftp-server (基本不用修改配置文件)

  • cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
#   protocol.  The tftp protocol is often used to boot diskless \
#   workstations, download configuration files to network-aware printers, \
#   and to start the installation process for some operating systems.
service tftp
{
    socket_type     = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server          = /usr/sbin/in.tftpd
    server_args     = -s /var/lib/tftpboot
    disable         = yes
    per_source      = 11
    cps         = 100 2
    flags           = IPv4
}
  • cat /usr/lib/systemd/system/tftp.service
[Unit]
Description=Tftp Server
Requires=tftp.socket
Documentation=man:in.tftpd

[Service]
ExecStart=/usr/sbin/in.tftpd -s /var/lib/tftpboot
StandardInput=socket

[Install]
Also=tftp.socket
  • 啓動tftp-server服務
    systemctl start tftp.socketvim

  • 設定PXE相關的文件:
    cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
    cp /usr/share/syslinux/{chain.c32,mboot.c32,menu.c32,memdisk} /var/lib/tftpboot/
    cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/ #基於pxe安裝使用的光盤上的文件(本身本地掛載光盤便可)或者是yum倉庫裏
    mkdir /var/lib/tftpboot/pxelinux.cfg/
  • vim default #default的文件內容以下
default menu.c32        #加載時顯示的默認菜單控制的程序(配置沒法啓動,menu.c32 改爲Linux)
  prompt 5          #顯示提示符時間
  timeout 30            #超時時長
  MENU TITLE CentOS 7 PXE Menu          #標題爲CentOS7 PXE Menu
 
  LABEL linux           #指明下面菜單項的label
  MENU LABEL Install CentOS 7 x86_64        #菜單的label
  KERNEL vmlinuz        #指明kernel文件
  APPEND initrd=initrd.img inst.repo=http://192.168.121.17/centos7 ks=http://192.168.121.17/centos7.cfg     #附加給kernel的參數,inst.repo能夠是教室的ftp服務器,或者把光盤當作yum倉庫,把它做爲一個網站的訪問就能夠了

4.掛載ISO文件

mkdir -pv /media/cdrom
mount -r /dev/cdrom /media/cdrom
mkdir -pv /var/www/html/centos7/
mount --bind /media/cdrom /var/www/html/centos7centos

5. 配置kickstart文件:

  • 該kickstart文件是CentOS7 最小化安裝的一部分+system-config-kickstart 命令建立的kickstart文件(強烈建議在desktop centos7 上面操做system-config-kickstart命令)的合集
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$kncWgT41$Z37pYAKljSaTTQ4EadDqE1
# Use network installation
url --url="http://10.2.1.10/centos7"
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
network  --hostname=localhost.pxe
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1

%post
systemctl disable postfix.service
%end

%packages
@^minimal
@compat-libraries
@debugging
@development
bash-completion
dos2unix
lrzsz
nmap
sysstat
tree
vim
wget

%end
相關文章
相關標籤/搜索