基于网络PXE自动化安装CentOS 7

PXE原理:

Preboot Excution Environment 预启动执行环境,是Intel公司研发
基于Client/Server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统PXE可以引导和安装Windows,linux等多种操作系统。PXE自动安装系统过程如下所示:

这里写图片描述
基于PXE安装centos7 过程:

  • 1.安装前准备:关闭防火墙和SELINUX
[root@centos7 ~]#getenforce 检查selinux 状态
Disabled
[root@centos7 ~]#iptables -vnL
Chain INPUT (policy ACCEPT 201K packets, 8505K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 201K packets, 2597M bytes)
 pkts bytes target     prot opt in     out     source               destination     

防火墙可以通过 iptables -F 来关闭。
selinux 可以通过 setenforce 0 临时关闭。

  • 2安装相关软件包

yum install httpd tftp-server dhcp syslinux

  • 3 配置文件共享服务和yum源

systemctl enable httpd 设置为开机启动
systemctl start httpd 启动httpd 服务
mkdir /var/www/html/centos/7
mount /dev/sr0 /var/www/html/centos/7 把光盘挂载到目录下,也可以copy 到该目录下。

  • 4 准备kickstart文件
cp /root/anaconda-ks.cfg   /var/www/html/ksdir/ks7-1.cfg  
chmod +r /var/www/html/ksdir/ks7-1.cfg
vim /var/www/html/ksdir/ks7-1.cfg 
cat ks7-1.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
 url --url=http://192.168.10.33/centos/7
# Use graphical install
 text
# Run the Setup Agent on first boot
firstboot --enable
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.magedu.com

# Root password
rootpw --iscrypted $6$Z7LBEUpwj3iQdYZ3$olYQ.Lj1xV2VAGS1UiNflKF0oMGip3b6tU9QFcp0i2JBjwKlY/Yaexul57NHpIJc.Y2V1hWAOueaqwjuWDGMk0
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --password=$6$v.VphW/puRblcrFB$uaSrdEhGAwMXap27WIKTn5lyOOfoFyB/SNxyyL3og6s9/VQoAKoL2KQjKmeYFmoYTuYkSNL7BBxgbJzeryKr9. --iscrypted --gecos="wang"
# X Window System configuration information
xconfig  --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
 zerombr
 clearpart --all
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=2048
part /app --fstype="xfs" --ondisk=sda --size=51200
part / --fstype="xfs" --ondisk=sda --size=51200
part /boot --fstype="xfs" --ondisk=sda --size=1024
 reboot
%packages
@^graphical-server-environment
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@x11
kexec-tools
 autofs
%end

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

%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
%post
systemctl enable autofs
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo <<eof
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
eof
%end
  • 5.配置tftp

systemctl enable tftp.socket 设置开机启动
systemctl start tftp.socket 启动tftp服务
netstat -unl 检查状态DHCP服务

  • 6.配置DHCP服务
vim /etc/dhcp/dhcpd.conf
option domain-name "example.com";
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.10.0 netmask 255.255.255.0 {
        range 192.168.10.50 192.168.10.100;
        next-server 192.168.10.33;
        filename "pxelinux.0";
}
systemctl enable dhcpd
systemctl start dhcpd
  • 7 准备PXE相关文件

mkdir /var/lib/tftpboot/pxelinux.cfg/ 创建目录
cp/usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
cp /misc/cd/isolinux/{vmlinuz,initrd.img,} /var/lib/tftpboot/ 把光盘里的内核文件和伪根文件拷贝到tftpboot 目录下
cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

  • 8 制作启动菜单文件

vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600

menu title CentOS Linux 7 PXE Install

label desktop
menu label Auto Install CentOS Linux 7 ^Desktop
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.10.33/ksdir/ks7-1.cfg #tftp server 地址

label mini
menu label Auto Install CentOS Linux 7 M^ini
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.10.33/ksdir/ks7-2.cfg

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

文件列表如下:
[root@centos7 ~]#tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│ └── default
└── vmlinuz

  • 9 新机器系统安装

这里写图片描述
安装时候可以根据需要选择,我们选桌面版,这样就可以顺利完成安装了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值