系统版本:Centos7.3
软件版本:yum epel源
主机IP: 192.168.8.35
需要软件:tftp-server dhcp syslinux xinetd system-config-kickstart nginx
PXE_详细介绍:http://baike.baidu.com/link?url=okrIOCs-JFnARocvi5ZdsT1Sf0akYgnjLpiQF6wz4Dl-E6pbQSCIM3QFWmG_NPhPMTsUlZeYFi8wj3dV7Xa-FK
[root@node1 ~]# yum -y install tftp-server dhcp syslinux xinetd system-config-kickstart
[root@node1 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@node1 ~]# vim /etc/dhcp/dhcpd.conf # 添加如下行
subnet 192.168.8.0 netmask 255.255.255.0 {
option routers 192.168.8.35;
range 192.168.8.103 192.168.8.200;
option domain-name-servers 192.168.8.35;
filename "pxelinux.0";
next-server 192.168.8.35;
default-lease-time 600;
max-lease-time 7200;
}
# 改完之后重新dhcpd
# 命令详解
# option routers dhcp路由地址
# range dhcp分配地址池
# default-lease-time dhcp默认时长
# filename pxe服务名称
# next-server pxe服务器地址
# allow members pxe最大值
vim /etc/xinetd.d/tftp
disable = no
# 将disable 改为no 改完之后重新瞬间守护进程
# 配置nginx
[root@node1 ~]# vim /etc/nginx/nginx.conf 添加一个server段
server {
listen 80;
server_name 192.168.8.35;
location / {
root /mnt/cdrom;
autoindex on;
}
location /ks {
alias /var/lib/tftpboot;
autoindex on;
}
}
[root@node1 cdrom]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@node1 cdrom]# cp /mnt/cdrom/isolinux/boot.msg /var/lib/tftpboot/
[root@node1 cdrom]# cp /mnt/cdrom/isolinux/vesamenu.c32 /var/lib/tftpboot/
[root@node1 cdrom]# cp /mnt/cdrom/isolinux/splash.png /var/lib/tftpboot/
[root@node1 ~]# cp /mnt/cdrom/p_w_picpaths//pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/
[root@node1 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@node1 ~]# cp /mnt/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@node1 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
label linux Centos 7.2
menu label ^Install Centos 7.2 system
menu default
kernel vmlinuz
append initrd=initrd.img inst.ks=http://192.168.8.35/ks/ks.cfg quiet
[root@node1 ~]# systemctl restart xinetd.service
[root@node1 ~]# systemctl restart dhcpd.service
[root@node1 ~]# systemctl restart nginx
# 挂载光盘镜像至/opt/cdrom以下的格式必须为[development] 否则将报错
# yum源 格式强制 否则会报软件无法加载错误
[development]
name=yum
baseurl=file:///mnt/cdrom/
enable=1
gpgcheck=0
[epel]
name=epel_rpm
baseurl=http://192.168.9.19:81/epel7/
enable=1
gpgcheck=0
# 安装kickstart软件包配置启动文件
[root@node1 ~]# 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$fu4CwNue$NpzCFx7OTL4w9xPWv4TEN1
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://192.168.8.35/"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1
%post
wget -O /tmp/install.sh http://192.168.8.35/ks/install.sh &>/dev/null
/bin/bash /tmp/install.sh
%end
%packages
@development
wget
vim
net-tools
ntpdate
%end
cat /var/lib/tftpboot/install.sh
#!/bin/bash
##############################################################
# File Name: install cenos 7.2
# Version: V1.0
# Created Time : 2017年06月13日 17:35:05
# Description: Linux system initialization
##############################################################
yum -y install net-tools vim ntpdate
rm -rf /etc/yum.repos.d/Cent*
cat << EOF >> /etc/yum.repos.d/yum.repo
[development]
name=yum
baseurl=file:///opt/cdrom/
enable=1
gpgcheck=0
[epel]
name=epel_rpm
baseurl=http://192.168.9.19:81/epel7/
enable=1
gpgcheck=0
EOF
IPADDR=`ifconfig | grep "192.168.8.255" | awk '{print $2}'`
cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-eno16777984
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777984
UUID=fbacacf0-ee9a-4c3a-af76-c49d4789170b
DEVICE=eno16777984
ONBOOT=yes
IPADDR=$IPADDR
PREFIX=24
GATEWAY=192.168.8.1
DNS1=114.114.114.114
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_PRIVACY=no
EOF
echo "* */1 * * * ntpdate 192.168.8.35 2&> /dev/null &" > /var/spool/cron/root