PXE

批量部署 可以更简单更快的安装多个服务器的系统,无需值守
用到的服务 dhcp xinetd  httpd
 
过程:
#安装dhcp,分配ip,并然新服务器读取本机的pxe0
yum install dhcp
vim /etc/dhcp/dhcpd.conf
########################
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
 
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
 
subnet 192.168.10.0 netmask 255.255.255.0 {    #分发IP的网段,需要网卡所在的网段,看自己虚拟机的网络配置
    range 192.168.10.150 192.168.10.200;       #IP的分发范围,最好不要包含本机的IP
    option routers 192.168.10.102;             #被分发机器使用的路由,最好写本机
    filename "pxelinux.0";               #被分发机器要读取的文件
    next-server 192.168.10.102;               #去哪读,当然是本机IP
}
##########################
 
#安装xinetd
yum -y install tftp-server xinetd
vim /etc/xinetd.d/tftp
##################
service tftp
{
        socket_type             = dgram
        protocol                = udp        #服务的网络类型
        wait                    = yes
        user                    = root        #服务的使用者
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /tftpboot/linux-install   #服务所在的路径,可以自定义,记得创建
        disable                 = no                   #把yes 改成no 才是打开
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
###################
#建立所用的目录
mkdir /tftpboot/linux-install
 
#安装httpd
yum -y install httpd syslinux
 
#挂载光盘
mkdir /var/www/html/os7
mount /dev/cdrom /var/www/html/os7
 
#复制配置文件
cd /var/www/html/os7/isolinux/
cp vmlinuz /tftpboot/linux-install/vmlinuz
mkdir -p /tftpboot/linux-install/pxelinux.cfg
cp initrd.img /tftpboot/linux-install/initrd.img
cp isolinux.cfg  /tftpboot/linux-install/pxelinux.cfg/default
cp /usr/share/syslinux/pxelinux.0 /tftpboot/linux-install/
 
#编辑pxe默认启动项
cd /tftpboot/linux-install/pxelinux.cfg/
vim default
##############
default ks         #在第一行修改
 
 
 
label ks             #在文件中后部分进行添加
  MENU LABEL Install CentOS 7 x86_64
  KERNEL vmlinuz
  APPEND initrd=initrd.img method=http://192.168.10.102/os7 ks=http://192.168.10.102/ks7.cfg devfs=nomount
#################
 
#编辑ks文件
cd /var/www/html/
cp /root/anaconda-ks.cfg ./ks7.cfg
vim ks7.cfg
##############################################
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$1Yz7yBap$ULm/SsQw.7sOa73ZgXgOH1
# System timezone
timezone Asia/Shanghai
# Use network installation
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
?
# Network information
network  --bootproto=dhcp --device=eno33
# Halt after installation
halt
# System bootloader configuration
bootloader --location=none
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information    #分区设定
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
?
%packages    #最小化安装
@^minimal
@core
kexec-tools
?
%end
?
%addon com_redhat_kdump --enable --reserve-mb='auto'
?
%end
############################
#给ks文件可读权限
chmod 644 ks7.cfg
 
#重启所有服务
systemctl restart dhcpd xinetd httpd
 
#使用netstat -anp |grep 服务名 查看服务是否启动及端口号
netstat -anp |grep httpd
netstat -anp |grep dhcpd
netstat -anp |grep xinetd
 
#把以上服务端口加入防火墙
firewall-cmd --list-all
 
#建一个新虚拟机 改2G以上内存,开机验证
posted @ 2018-11-06 15:00  huifeidezhu  阅读(135)  评论(0编辑  收藏  举报