2021-05-12 14:32:11
PXE+Kickstart安裝CentOS 7.3
Linux系統版本:CentOS 7.3
軟體版本:yum epel源
主機IP: 192.168.8.35
需要軟體:tftp-server dhcp syslinux xinetd system-config-kickstart nginx
[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/images//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
cat /var/lib/tftpboot/ks.cfg
#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
/bin/bash /tmp/install.sh
%end
%packages
@development
%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
本文永久更新連結地址:http://www.linuxidc.com/Linux/2017-06/144789.htm
相關文章