环境准备
两台主机:
一台DHCP,HTTPD,TFTP服务器(一个网卡,仅主机):192.168.37.101
一台测试机(一个网卡,仅主机):
关闭仅主机的vmware中dhcp服务
安装服务需要的软件包:
yum install httpd tftp-server dhcp syslinux systemctl start httpd tftp
systemctl enable httpd tftp
准备yum 源
mkdir /var/www/html/centos/{6,7}/os/x86_64 -pv
mount /dev/sr0 /var/www/html/centos/7/os/x86_64
mount /dev/sr1 /var/www/html/centos/6/os/x86_64
准备ks文件
system-config-kickstart mkdir /var/www/html/ksdir/ ls /var/www/html/ksdir/ ks6_mini.cfg ks7_desktop.cfg ks7_mini.cfg
配置dhcp服务
准备dhcp配置文件
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cat >/etc/dhcp/dhcpd.conf <<EOF
option domain-name "magedu.com";
option domain-name-servers 114.114.114.114, 180.76.76.76;
default-lease-time 86400;
max-lease-time 864000;
subnet 192.168.37.0 netmask 255.255.255.0 {
range 192.168.37.50 192.168.37.100;
option routers 192.168.37.2;
next-server 192.168.37.101;
filename "pxelinux.0";
}
EOF
启动dhcp服务,并设为开机自起
systemctl start dhcpd systemctl enable dhcp
准备相关文件
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/centos{6,7}
cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7
cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6
mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@centos7 tftpboot]#tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default
准备启动菜单
cat > /var/lib/tftpboot/pxelinux.cfg/default <<EOF default menu.c32 timeout 600 menu title CentOS Auto Install label mini7 menu label Install CentOS ^Mini 7 kernel centos7/vmlinuz append initrd=centos7/initrd.img ks=http://192.168.37.7/ksdir/ks7_mini.cfg label desktop menu label Install CentOS ^Desktop 7 kernel centos7/vmlinuz append initrd=centos7/initrd.img ks=http://192.168.37.7/ksdir/ks7_desktop.cfg label mini6 menu label Install CentOS Mi^ni 6 kernel centos6/vmlinuz append initrd=centos6/initrd.img ks=http://192.168.37.7/ksdir/ks6_mini.cfg label local menu default menu label Boot from ^local drive localboot 0xffff EOF
测式机网卡启动
以下是相关模板文件,可以直接拿来用,也可以自己加以修改:
ks7_mini.cfg
#platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --plaintext centos # Use network installation url --url="http://192.168.37.7/centos/7/os/x86_64" # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text firstboot --disable # SELinux configuration selinux --disabled # Firewall configuration firewall --disabled # Network information network --bootproto=dhcp --device=eth0 # Reboot after installation reboot # System timezone timezone Asia/Shanghai # System bootloader configuration bootloader --append="net.ifnames=0" --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all # Disk partitioning information part / --fstype="xfs" --size=100000 part /boot --fstype="xfs" --size=1000 part swap --fstype="swap" --size=2000 %packages @^minimal autofs %end %post mkdir /root/.ssh chmod 700 /root/.ssh cat > /root/.ssh/authorized_keys <<EOF ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSi4WucaraQXLsyyrluMBuKjClLscLulnLLzTshTX/L3t7c6Lw+Ap0zMbPuGer0NRuvnkESfsRNtnBXmuTDcuOYeOosMe59zGGmv04BZFipyDi7Acw94IeNF2HaU3pk6WIqkpqYlOnUAvAJg0fN+hEkVBy0S1pghVK7SWA0KFAUKuSrvd8ZNj3NK1Vj+ZPLXGDrnF8JyvfBz8oq+M+70dZRNhSsXCegHUfLY2tRvXOkjYb6tLQlQAgSifzI+FqB0Ix/VmsIspdAep/jwsKNjTf93fngoQ1ovdSu5ybzo95VF+UxAou1+9kNhr9/qJhSGp3StQHAVbERJdgjguhoA7h root@centos7.localdomain EOF chmod 600 /root/.ssh/authorized_keys mkdir /etc/yum.repos.d/bak mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak cat > /etc/yum.repos.d/test.repo <<EOF [base] baseurl=http://192.168.37.7/centos/7/os/x86_64 gpgcheck=0 EOF %end
ks6_mini.cfg
# Kickstart file automatically generated by anaconda. #version=DEVEL install text reboot url --url=http://192.168.32.6/centos/6/ lang en_US.UTF-8 keyboard us network --onboot yes --device eth0 --bootproto static --ip 192.168.32.16 --netmask 255.255.255.0 --noipv6 rootpw --iscrypted $6$b6C5mM/BwOMBoK8H$cYZFrHoNlOL0iDsxOTRhwnWJ3yfFmf7mRJBOxEqGoI56UMrT8J7qlrGwX7tSnOf7wKxYR2hAvAREILDgOgsFe1 firewall --disabled authconfig --enableshadow --passalgo=sha512 selinux --disabled timezone Asia/Shanghai bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" # The following is the partition information you requested # Note that any partitions you deleted are not expressed # here so unless you clear all partitions first, this is # not guaranteed to work zerombr clearpart --all --initlabel part /boot --fstype=ext4 --size=1024 part / --fstype=ext4 --size=50000 part /data --fstype=ext4 --size=30000 part swap --size=2048 repo --name="CentOS" --baseurl=http://192.168.32.6/centos/6/ --cost=100 %packages @core @server-policy @workstation-policy autofs vim-enhanced %end %post useradd wang echo magedu | passwd --stdin wang &> /dev/null mkdir /etc/yum.repos.d/bak mv /etc/yum.repos.d/* /etc/yum.repos.d/bak cat > /etc/yum.repos.d/base.repo <<EOF [base] name=base baseurl=file:///misc/cd gpgcheck=0 EOF mkdir /root/.ssh cat > /root/.ssh/authorized_keys <<EOF ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCZRMD+7Zx9BAajEqj7RegvU5NpwqtxT987GfBm1t3/HJ69f3VTIWZ7+Y9ySMDeZpT8aw5RQ+DBARVA79GGoZkELC8nZsPZiBxGf56abVwGL9EMJjkZiVuC1ifEuYNqh5RJM7TedwAaZESwEKMoxHlj678ORdsXJFMwO5BAXyDIkBRPwQ8YNBGrNssQNtflmdkJimM3woBGx/mrYN75tWCAp8U7dBzrXG7vjaMSb2ZdRsafKAJIzB3aXLcuuPUhxyHr6VTH43YEpN00Ca4rx5DloNOjmyfIpgWR+kP1GXbR5pat8pKFOxZbK96STclmUMSnYhqGy559aR7L0XF/urjh root@centos7.localdomain EOF chmod 600 /root/.ssh/authorized_keys chmod 700 /root/.ssh %end
default文件模板
[root@centos7 pxelinux.cfg]# cat default
default menu.c32
timeout 600
menu title CentOS Auto Install
label mini7
menu label Install CentOS ^Mini 7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.37.101/ksdir/ks7_mini.cfg
label desktop
menu label Install CentOS ^Desktop 7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.37.{6,7}/ksdir/ks7_desktop.cfg
label mini6
menu label Install CentOS Mi^ni 6
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://192.168.37.101/ksdir/ks6_mini.cfg
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
[root@centos7 pxelinux.cfg]#
浙公网安备 33010602011771号