2017年6月30日 星期五

PXE Server ON CentOS7

目標:


1.將PXE 服務安裝在CENTOS7上


2.提供CentOS6 , CentOS7客製化安裝


利用 yum 安裝 tftp Server、DHCP Server、Vsftp Server 以及 syslinux 等套件:


#yum install tftp-server dhcp syslinux vsftpd -y

配置dhcp.conf

#vi /etc/dhcp/dhcpd.conf

ddns-update-style interim;
ignore client-updates;
authoritative;
allow booting;
allow bootp;
allow unknown-clients;

#想配發的dhcp範圍
subnet 192.168.x.0 netmask 255.255.255.0 {
  range 192.168.x.10 192.168.x.100;
  option domain-name-servers 168.95.1.1, 8.8.8.8;
  option domain-name "internal.example.org";
#dhcp gateway
  option routers 192.168.x.x;
  option broadcast-address 192.168.x.255;
  default-lease-time 600;
  max-lease-time 7200;
#PXE Server
  next-server 192.168.x.x;
  filename "pxelinux.0";
}


修改 tftp 套件內容:

 /usr/lib/systemd/system/tftp.service

[Unit]
Description=Tftp Server
Requires=tftp.socket
Documentation=man:in.tftpd

[Service]
ExecStart=/usr/sbin/in.tftpd -s /tftpboot  ##修改本行至tftp家目錄
StandardInput=socket

[Install]
Also=tftp.socket


將 syslinux 檔案,複製到 tftp Server 分享目錄內:

#cd /usr/share/syslinux
#cp pxelinux.0 menu.c32 memdisk mboot.c32 chain.c32 /tftpboot/
#chmod 644 -R /tftpboot
#chmod 755 /tftpboot


 Linux OS ISO 檔案內容,複製到 vsftp 分享目錄上:

#mkdir /var/ftp/pub/centos7.2_1511_x64
#mkdir /var/ftp/pub/centos6.9_x64
#mount CentOS-7-x86_64-DVD-1611.iso /mnt/
#cp -r /mnt/* /var/ftp/pub/centos7.2_1511_x64
#umont /mnt
#mount CentOS-7-x86_64-DVD-1611.iso /mnt/
#cp -r /mnt/* /var/ftp/pub/centos6.9_x64



將 Linux PXE 開機核心檔案,放置於 tftp Server 分享目錄上:

#cd /var/ftp/pub/centos7.2_1511_x64/images/pxeboot
#cp vmlinuz initrd.img /tftpboot/centos7.2_1511_x64
#cd /var/ftp/pub/centos6.9_x64/images/pxeboot
#cp vmlinuz initrd.img /tftpboot/centos6.9_x64

在ftp 目錄下建立Linux Kstart 檔案

1. var/ftp/pub/centos7.2_1511_x64/ks.cfg

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#Linux OS IOS位置
url --url="ftp://192.168.x.x/pub/centos7.2_1511_x64"
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=xvda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=eth0 --onboot=no --noipv6
network  --bootproto=dhcp --device=eth1 --onboot=yes --noipv6
network  --hostname=dhcpdclient.wegames

# Root password
rootpw --iscrypted $6$TXQDofxdXufoq$L.TIvt8IdzvbfTGUNf3zqbIDqr.Y.NOiJk0ZubdBlw.Dq7VYipq.
# System services
selinux --disabled
services --disabled="chronyd"
# System timezone
timezone Asia/Taipei --isUtc --nontp
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=xvda
# Partition clearing information
clearpart --none --initlabel
# Disk partitioning information
#配置/boot  swap2G,其餘/
part /boot --fstype="xfs" --ondisk=xvda --size=500
part swap --fstype="swap" --ondisk=xvda --size=2049
part / --fstype="xfs" --ondisk=xvda --grow --size=10240 --maxsize=1024000
repo --name="CentOS7.2_1511_x64"  --baseurl=ftp://192.168.199.1/pub/centos7.2_1511_x64 --cost=100

#最小安裝
%packages
@^minimal
@core
kexec-tools

%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
#安裝完後重開機

reboot

#進行安裝完後的套件環境配置
%post --log=/root/postinstall.log

systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl stop firewalld
systemctl disable firewalld
/etc/init.d/netword restart
chkconfig network on

yum install epel-release wget net-tools net-snmp ntpdate vim  -y

yum update glibc bash openssl -y


cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.bk
cat /dev/null > /etc/snmp/snmpd.conf
echo "rocommunity testmonitor x.x.x.x" > /etc/snmp/snmpd.conf
echo "rocommunity testmonitor  x.x.x.x" >> /etc/snmp/snmpd.conf
systemctl enable snmpd

ntpdate ntpserver && hwclock -w
echo "59 11 0 0 0 root ntpdate ntpserver && hwclock -w" >> /etc/crontab
echo "#GATEWAY=x.x.x.x" >> /etc/sysconfig/network
echo "#nameserver 168.95.1.1" > /etc/resolv.conf
echo "#nameserver 8.8.8.8" >> /etc/resolv.conf
%end




2. var/ftp/pub/centos6.9_x64/ks.cfg

#version=DEVEL
install
#text
#Linux OS IOS位置
url --url="ftp://192.168.x.x/pub/centos6.9_x64"
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth1 --bootproto dhcp --noipv6
rootpw --iscrypted 
$$TXQDCvxdXufoT8IdXCzvbfTGUNf3zqbIDqr.Y.NOiJk0ZubdBlw.Dq7VY
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Taipei
bootloader --location=mbr --driveorder=sda,xvda --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
#clearpart --linux --drives=sda
zerombr
clearpart  --all
part /boot --fstype=ext4 --size=200
part swap --fstype="swap" --size=2048
part / --fstype=ext4 --grow --size=10240 --maxsize=1024000
repo --name="centos6.9_x64"  --baseurl=ftp://192.168.x.x/pub/centos6.9_x64 --cost=100
reboot

#最小安裝
%packages
@base
@core
@server-policy
sgpio

#進行安裝完後的套件環境配置
%post --log=/root/postinstall.log
/etc/init.d/iptables stop
chkconfig iptables off
yum install epel-release wget net-snmp ntpdate vim  -y
yum update glibc bash openssl -y
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.bk
cat /dev/null > /etc/snmp/snmpd.conf
echo "rocommunity testmonitor" x.x.x.x" > /etc/snmp/snmpd.conf
echo "rocommunity testmonitor" x.x.x.x >> /etc/snmp/snmpd.conf

chkconfig snmpd on
ntpdate x.x.x.x && hwclock -w
echo "59 11 0 0 0 root ntpdate x.x.x.x && hwclock -w" >> /etc/crontab
echo "#GATEWAY=x.x.x.x" >> /etc/sysconfig/network
echo "#nameserver 168.95.1.1" > /etc/resolv.conf
echo "#nameserver 8.8.8.8" >> /etc/resolv.conf

編寫 PXE Server 開機選單:

/tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
timeout 300
MENU Wegames G12 PXE Menu

#選單一,預設硬碟開機
LABEL local
  MENU LABEL Boot from local drive
  MENU DEFAULT
  localboot 0

#選單二 ,CentOS7
LABEL CentOS7.2_x64
MENU LABEL CentOS 7.2.1511 X86_64_VM
KERNEL /centos7.2_1511_x64/vmlinuz
APPEND initrd=./centos7.2_1511_x64/initrd.img inst.repo=ftp://192.168.x.x/pub/centos7.2_1511_x64/ ks=ftp://192.168.x.x/pub/centos7.2_1511_x64/ks.cfg ksdevice=eth1

#選單三,CentOS6.9
LABEL CentOS6.9_x64
MENU LABEL CentOS 6.9_x64_VM
KERNEL /centos6.9_x64/vmlinuz
APPEND initrd=./centos6.9_x64/initrd.img inst.repo=ftp://192.168.x.x/pub/centos6.9_x64/ ks=ftp://192.168.x.x/pub/centos6.9_x64/ks.cfg ksdevice=eth1



更正tftpserver正確權限


#chmod 755 /tftpboot
#chmod 755 /tftpboot/centos7.2_1511_x64
#chmod 755 /tftpboot/centos6.9_x64

#chmod 755 /tftpboot/pxelinux.cfg
#chmod 644 /var/ftp/pub/centos7.2_1511_x64/ks.cfg
#chmod 644 /var/ftp/pub/centos6.9_x64/ks.cfg



啟動各項服務:


#systemctl enable vsftpd
#systemctl start vsftpd
#systemctl enable tftp
#systemctl start tftp
#systemctl daemon-reload
#systemctl enable dhcpd

#systemctl start dhcpd

沒有留言:

張貼留言