新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
SHELL腳本之配置PXE批量無人值守裝機-創(chuàng)新互聯(lián)
PXE批量無人值守裝機腳本
準備2個網卡:
第一個網卡使用NET,用來安裝服務
第2個網卡用來提供dhcp服務

#!/bin/bash
#部署pxe批量裝機服務
#配置雙網卡
#定義網卡配置文件位置
k=/etc/sysconfig/network-scripts
#復制網卡配置文件模板
cd /etc/sysconfig/network-scripts
cp -p ifcfg-ens33 ifcfg-ens36
#修改第2塊網卡配置文件
sed -i 's/dhcp/static/' $k/ifcfg-ens36
sed -i 's/ens33/ens36/' $k/ifcfg-ens36
sed -i '/UUID/d' $k/ifcfg-ens36
cat >>$k/ifcfg-ens36 <<-EOF
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
EOF
#重啟網絡服務
systemctl restart network
#防止yum安裝進程休眠
rm -rf /var/run/yum.pid
#安裝必要服務
yum install dhcp syslinux tftp-server vsftpd -y
#修改DHCP服務配置文件
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cat >>/etc/dhcp/dhcpd.conf <<-EOF
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.10 192.168.100.20;
option routers 192.168.100.100;
next-server 192.168.100.100;
filename "pxelinux.0";
}
EOF
#定義要經常用的tftp站點
tftp=/var/lib/tftpboot
#復制引導程序到tftp站點
cp /usr/share/syslinux/pxelinux.0 $tftp/
#修改tftp配置文件
sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
#創(chuàng)建鏡像文件掛載點
cd /var/ftp
mkdir centos7
#掛載鏡像文件
mount /dev/sr0 /var/ftp/centos7
#復制壓縮內核和系統(tǒng)初始化文件到tftp站點
cd centos7/images/pxeboot
cp initrd.img vmlinuz $tftp
#在tftp站點中創(chuàng)建啟動菜單存放位置
cd $tftp
mkdir pxelinux.cfg
cd pxelinux.cfg
#創(chuàng)建啟動菜單文件
cat >default <<-EOF
default auto
prompt 1
label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
EOF
#安裝系統(tǒng)工具
yum install system-config-kickstart -y
#創(chuàng)建系統(tǒng)安裝過程文件
cat >/var/ftp/ks.cfg <<-EOF
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
#Install OS instead of upgrade
install
#Keyboard layouts
keyboard 'us'
#Root password
rootpw --plaintext 123
#Use network installation
url --url="ftp://192.168.100.100/centos7/"
#System language
lang zh_CN
#System authorization information
auth --useshadow --passalgo=sha512
#Use graphical install
graphical
firstboot --disable
#SELinux configuration
selinux --disabled
#Firewall configuration
firewall --disabled
#Network information
network --bootproto=dhcp --device=ens33
#Reboot after installation
reboot
#System timezone
timezone Asia/Shanghai
#System bootloader configuration
bootloader --location=mbr
#Partition clearing information
clearpart --all
#Disk partitioning information
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=4096
part /home --fstype="xfs" --size=4096
part / --fstype="xfs" --grow --size=1
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
kexec-tools
%end
EOF
#關閉防火墻
systemctl stop firewalld.service
setenforce 0
#啟動所有服務
systemctl start dhcpd
systemctl start tftp
systemctl start vsftpd另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
名稱欄目:SHELL腳本之配置PXE批量無人值守裝機-創(chuàng)新互聯(lián)
文章源于:http://www.dlmjj.cn/article/dhoiii.html


咨詢
建站咨詢
