PXE 批量部署 CentOS 7系统

安装dhcp服务

[root@pxe-server ~]# yum install dhcp -y

配置DHCP服务

[root@pxe-server ~]# cat >>/etc/dhcp/dhcpd.conf<<EOF
    subnet 192.168.0.0 netmask 255.255.255.0 {
    range 192.168.0.2 192.168.0.254;
    option subnet-mask 255.255.255.0;
    default-lease-time 21600;
    max-lease-time 43200;
    next-server 192.168.0.251;
    filename "/pxelinux.0";
    }
    EOF

启动DHCP服务

[root@pxe-server ~]# systemctl start dhcpd.service
[root@pxe-server ~]# systemctl enable dhcpd.service

安装tftp软件

[root@pxe-server ~]# yum install tftp-server -y

启动服务

[root@pxe-server ~]# systemctl start tftp.socket
[root@pxe-server ~]# systemctl status tftp.socket

获取pxelinux.0系统

[root@pxe-server ~]# yum install -y syslinux

复制pxelinux.0文件到tftp根目录

[root@pxe-server ~]# cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/
[root@pxe-server ~]# cd /var/lib/tftpboot/

添加pxelinux.0配置文件,将镜像挂载上

[root@pxe-server ~]# mkdir -p /var/www/html/CentOS7
[root@pxe-server ~]# mount /dev/cdrom /var/www/html/CentOS7 #或者 mount -o loop -t iso9660 /root/CentOS-7.6-x86_64-DVD-1810.iso /var/www/html/CentOS7

将镜像中的相关文件复制到tftp根目录

[root@pxe-server ~]# cp -a /var/www/html/CentOS7/isolinux/* /var/lib/tftpboot/
[root@pxe-server ~]# mkdir -p /var/lib/tftpboot/pxelinux.cfg
[root@pxe-server ~]# cp /var/www/html/CentOS7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

CentOS7实现自动化安装的default文件

[root@pxe-server ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default Automatic Installation By xiaoshuai.zhu
prompt 0

label Automatic lnstallation By xiaoshuai.zhu
  kernel vmlinuz
append initrd=initrd.img inst.stage2=http://192.168.0.251/CentOS7 inst.ks=http://192.168.0.251/ks_config/CentOS7-ks.cfg  quiet
default vesamenu.c32
timeout 10

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title Powered by xiaoshuai.zhu
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu end

配置httpd服务

[root@pxe-server ~]# yum install httpd -y

启动apache服务

[root@pxe-server ~]# systemctl start httpd.service
[root@pxe-server ~]# systemctl enable httpd.service

自动应答文件 (vi /var/www/html/ks_config/CentOS7-ks.cfg)


# Kickstart Configurator for CentOS 7 by xiaoshuai.zhu #命令段
install   #告知安装程序,这是一次全新安装,而不是升级
url --url="http://192.168.0.251/CentOS7/"  #通过http下载安装镜像
text     #以文本格式安装
lang en_US.UTF-8   #设置字符集格式
keyboard us  #设置键盘类型
zerombr   #清除mbr引导
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"    #指定引导记录被写入的位置
network --device em1 --bootproto static --ip 192.168.0.100 --netmask 255.255.255.0 --gateway 192.168.0.1 --nameserver 223.5.5.5 --hostname localhost
timezone Asia/Shanghai --isUtc
authconfig --enableshadow --passalgo=sha512  #设置密码格式
rootpw  --iscrypted $6$X20eRtuZhkHznTb4$dK0BJByOSAWSDD8jccLVFz0CscijS9ldMWwpoCw/ZEjYw2BTQYGWlgKsn945fFTjRC658UXjuocwJbAjVI5D6/     #密文密码
clearpart --all --initlabel  #清空分区
part /boot --fstype xfs --size 2048   #/boot分区
part swap --size 32768                    #swap分区
part biosboot --size 2
part / --fstype xfs --size 1 --grow   #/分区
firstboot --disable       #负责协助配置redhat一些重要的信息
selinux --disabled        #关闭selinux
firewall --disabled       #关闭防火墙
logging --level=info      #设置日志级别
poweroff                       #安装完成关机

%packages #包组段   @表示包组
@^minimal
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
wget
vim
bash-completion
%end

%post #脚本段,可以放脚本或命令
systemctl disable postfix.service   #关闭邮件服务开机自启动
%end

密文参考

perl -e ‘print crypt("123456",q($1$password)),"\n"’

上一篇
下一篇