CentOS6.4下PXE环境搭建

一、实验环境:

主机名                  IP(Static)                             系统                                            配置                                用途
PXEServer       192.168.220.211        CentOS-6.4-x86_64-mini          2CPU,1G RAM,20G DISK,2网卡     PXEServer

PXEClient                none                                    none                         1CPU,1G RAM,20G DISK,1网卡     PXEClient

二、PXEServer IP配置:

网卡                   IP                              掩码                    网关               应用

eth0              10.1.1.1                   255.255.255.0            无                DHCP网络

eth1              192.168.20.100       255.255.255.0            无                管理网络

************************************************************************************


三、系统配置:


1.关闭selinux和iptables:

[root@PXEServer ~]# vi /etc/selinuc/config

SELINUX=disabled

[root@PXEServer ~]# service iptables stop

[root@PXEServer ~]# service ip6tables stop

[root@PXEServer ~]# chkconfig iptables off

[root@PXEServer ~]# chkconfig ip6tables off


2.安装必要软件包:

[root@PXEServer ~]# yum -y install perl nfs-utils tftp-server dhcp syslinux


3.创建目录结构和访问权限:

[root@PXEServer ~]# mkdir /tftpboot /iso

[root@PXEServer ~]# mkdir /tftpboot/pxelinux.cfg

[root@PXEServer ~]# mkdir /tftpboot/pxelinux.cfg/graphics /tftpboot/pxelinux.cfg/os_menu

[root@PXEServer ~]# mkdir /tftpboot/bootkernels

[root@PXEServer ~]# mkdir /tftpboot/bootkernels/centos6.4 /tftpboot/bootkernels/ubuntu12.04

[root@PXEServer ~]# mkdir -p /tftpboot/display/picture

上传图片并解压到该目录:下载地址

[root@PXEServer ~]# ls /tftpboot/display/picture

centos_back.jpg  pxe_back.jpg  ubuntu_back.png

[root@PXEServer ~]# cp -av /usr/share/syslinux/vesamenu.c32 /tftpboot/display/

[root@PXEServer ~]# ls /tftpboot/display

picture  vesamenu.c32

[root@PXEServer ~]# mkdir /tftpboot/kickstart

[root@PXEServer ~]# cp -av /usr/share/syslinux/pxelinux.0 /tftpboot/

[root@PXEServer ~]# ls /tftpboot/

bootkernels  display  kickstart  pxelinux.0  pxelinux.cfg


4.配置DHCP服务:

[root@PXEServer ~]# cp -av /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

[root@PXEServer ~]# vi /etc/dhcp/dhcpd.conf

DHCPDARGS="eth0";

ddns-update-style interim;

ignore client-updates;

allow booting;

allow bootp;

next-server     10.1.1.1;

filename        "/pxelinux.0";

log-facility local7;

# A slightly different configuration for an internal subnet.

subnet 10.1.1.0 netmask 255.255.255.0 {

   range 10.1.1.10 10.1.1.100;

#  option domain-name-servers ns1.internal.example.org;

#  option domain-name "chensh.com";

#  option routers 10.1.1.1;

   option broadcast-address 10.1.1.255;

   default-lease-time 600;

   max-lease-time 7200;

}

[root@PXEServer ~]# service dhcpd restart

[root@PXEServer ~]# chkconfig dhcpd on        /*按需配置此项*/


5.配置TFTP服务:

[root@PXEServer ~]# vi /etc/xinetd.d/tftp

service tftp

{

        socket_type             = dgram

        protocol                = udp

        wait                    = yes

        user                    = root

        server                  = /usr/sbin/in.tftpd

        server_args             = -u nobody -s /tftpboot

        disable                 = no

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

[root@PXEServer ~]# service xinetd restart

[root@PXEServer ~]# chkconfig xinetd on


6.配置NFS服务:

[root@PXEServer ~]# vi /etc/exports

/iso            *(rw,sync)

/tftpboot       *(rw,sync)

[root@PXEServer ~]# service nfs restart

[root@PXEServer ~]# chkconfig nfs on

[root@PXEServer ~]# service rpcbind restart

[root@PXEServer ~]# chkconfig rpcbind on


7.创建配置文件:

[root@PXEServer ~]# vi /tftpboot/pxelinux.cfg/default

default display/vesamenu.c32

timeout 600

MENU INCLUDE pxelinux.cfg/graphics/pxe_graphics.conf

MENU TITLE Welcome to PXE Install Main Menu !

LABEL Boot From Local Disk

        MENU LABEL ^[A] Boot From Local Drive

        LOCALBOOT 0xffff

LABEL Install Linux CentOS System

        MENU LABEL ^[B] Install Linux CentOS System

        KERNEL display/vesamenu.c32

        APPEND pxelinux.cfg/os_menu/centos_menu

LABEL Install Linux Ubuntu System

        MENU LABEL ^[C] Install Linux Ubuntu System

        KERNEL display/vesamenu.c32

        APPEND pxelinux.cfg/os_menu/ubuntu_menu

[root@PXEServer ~]# vi /tftpboot/pxelinux.cfg/graphics/pxe_graphics.conf

default display/vesamenu.c32

menu background display/picture/pxe_back.jpg

menu color border 0 #ffffffff #00000000

menu color sel 7 #ffffffff #ff000000

menu color title 0 #ffffffff #00000000

menu color tabmsg 0 #ffffffff #00000000

menu color unsel 0 #ffffffff #00000000

menu color hotsel 0 #ff000000 #ffffffff

menu color hotkey 7 #ffffffff #ff000000

menu color scrollbar 0 #ffffffff #00000000

[root@PXEServer ~]# vi /tftpboot/pxelinux.cfg/graphics/centos_graphics.conf

default display/vesamenu.c32

menu background display/picture/centos_back.jpg

menu color border 0 #ffffffff #00000000

menu color sel 7 #ffffffff #ff000000

menu color title 0 #ffffffff #00000000

menu color tabmsg 0 #ffffffff #00000000

menu color unsel 0 #ffffffff #00000000

menu color hotsel 0 #ff000000 #ffffffff

menu color hotkey 7 #ffffffff #ff000000

menu color scrollbar 0 #ffffffff #00000000

[root@PXEServer ~]# vi /tftpboot/pxelinux.cfg/graphics/ubuntu_graphics.conf

menu background display/picture/ubuntu_back.png

menu color title        * #FFFFFFFF *

menu color border       * #00000000 #00000000 none

menu color sel          * #ffffffff #76a1d0ff *

menu color hotsel       1;7;37;40 #ffffffff #76a1d0ff *

menu color tabmsg       * #ffffffff #00000000 *

menu color help         37;40 #ffdddd00 #00000000 none

menu vshift 12

menu rows 10

menu helpmsgrow 15

menu cmdlinerow 16

menu timeoutrow 16

menu tabmsgrow 18

menu tabmsg Press ENTER to boot or TAB to edit a menu entry

[root@PXEServer ~]# vi /tftpboot/pxelinux.cfg/os_menu/centos_menu

default display/vesamenu.c32

timeout 600

MENU INCLUDE pxelinux.cfg/graphics/centos_graphics.conf

MENU TITLE Welcome to CentOS OS Install Menu !

LABEL Return to PXE Main Menu

        MENU LABEL ^[A] Return to PXE Main Menu

        KERNEL display/vesamenu.c32

        APPEND pxelinux.cfg/default

LABEL Auto install CentOS6.4 64bit

        MENU LABEL ^[B] Auto install CentOS6.4 64bit

        KERNEL bootkernels/centos6.4/vmlinuz

        APPEND ks=nfs:10.1.1.1:/tftpboot/kickstart/centos6.4_mini-base.cfg initrd=bootkernels/centos6.4/initrd.img ksdevice=link devfs=nomount ramdisk_size=8192

LABEL Manual install CentOS6.4 64bit

        MENU LABEL ^[C] Manual install CentOS6.4 64bit

        KERNEL bootkernels/centos6.4/vmlinuz

        APPEND initrd=bootkernels/centos6.4/initrd.img ksdevice=link devfs=nomount ramdisk_size=8192

[root@PXEServer ~]# vi /tftpboot/pxelinux.cfg/os_menu/ubuntu_menu

default display/vesamenu.c32

timeout 600

MENU INCLUDE pxelinux.cfg/graphics/ubuntu_graphics.conf

MENU TITLE Welcome to Ubuntu OS Install Menu !

LABEL Return to PXE Main Menu

        MENU LABEL ^[A] Return to PXE Main Menu

        KERNEL display/vesamenu.c32

        APPEND pxelinux.cfg/default

LABEL Auto install Ubuntu12.04 64bit

        MENU LABEL ^[B] Auto install Ubuntu12.04 64bit

        KERNEL bootkernels/ubuntu12.04/vmlinuz

        APPEND ks=nfs:10.1.1.1:/tftpboot/kickstart/ubuntu12.04-base.cfg initrd=bootkernels/ubuntu12.04/initrd.img ksdevice=link devfs=nomount ramdisk_size=8192

LABEL Manual install Ubuntu12.04 64bit

        MENU LABEL ^[C] Manual install Ubuntu12.04 64bit

        KERNEL bootkernels/ubuntu12.04/vmlinuz

        APPEND initrd=bootkernels/ubuntu12.04/initrd.img ksdevice=link devfs=nomount ramdisk_size=8192

[root@PXEServer ~]# vi /tftpboot/kickstart/centos6.4_mini-base.cfg

# Kickstart file automatically generated by anaconda.

#version=DEVEL

install

nfs --server=10.1.1.1  --dir=/iso/centos6.4

lang zh_CN.UTF-8

keyboard us

network --onboot yes --bootproto dhcp --hostname=CentOS6 --noipv6

rootpw  password

firewall --disabled

authconfig --enableshadow --passalgo=sha512

skipx

selinux --disabled

timezone --utc Asia/Shanghai

bootloader --location=mbr

clearpart --all --initlabel

part /boot --fstype=ext4 --size=200

part swap --size=2048

part / --fstype=ext4 --grow --size=200

# repo --name="CentOS"  --baseurl=file:///mnt/source --cost=100

reboot

%packages --nobase

@core

%end

[root@PXEServer ~]# vi /tftpboot/kickstart/ubuntu12.04-base.cfg

#Generated by Kickstart Configurator

#platform=x86

#Install OS instead of upgrade

install

#Use CDROM installation media

nfs --server=10.1.1.1  --dir=/iso/ubuntu12.04 

network --onboot yes --bootproto dhcp --hostname=ubuntu --noipv6

#System language

lang zh_CN.UTF-8

#Language modules to install

langsupport en_HK.UTF-8 en_DK.UTF-8 en_IN en_ZM en_ZW.UTF-8 en_NZ.UTF-8 en_PH.UTF-8 en_NG en_US.UTF-8 en_GB.UTF-8 en_AU.UTF-8 en_SG.UTF-8 en_BW.UTF-8 en_AG en_ZA.UTF-8

 en_CA.UTF-8 en_IE.UTF-8 zh_CN en_US.UTF-8 zh_SG.UTF-8 --default=zh_CN.UTF-8

#System keyboard

keyboard us

#System mouse

mouse

#System timezone

timezone Asia/Chongqing

#Root password

rootpw --disabled

#Initial user

user user --fullname="user" --password password

#Config firewall

firewall --disabled

auth --useshadow --enablemd5

skipx

#Clear the Master Boot Record

zerombr yes

#Partition clearing information

bootloader --location=mbr

clearpart --all --initlabel

part /boot --fstype ext4 --size 200  

part swap --size 1024  

part / --fstype ext4 --size 1 --grow

#Package install information

%packages

accountsservice

acpid

adduser

apparmor

apport

apport-symptoms

apt

apt-transport-https

apt-utils

apt-xapian-index

aptitude

at

base-files

base-passwd

bash

bash-completion

bc

bind9-host

bsdmainutils

bsdutils

busybox-initramfs

busybox-static

byobu

bzip2

ca-certificates

command-not-found

command-not-found-data

console-setup

coreutils

cpio

cron

curl

dash

dbus

debconf

debconf-i18n

debianutils

diffutils

dmidecode

dmsetup

dnsutils

dosfstools

dpkg

e2fslibs

e2fsprogs

ed

eject

file

findutils

fonts-ubuntu-font-family-console

friendly-recovery

ftp

fuse

gcc-4.6-base

geoip-database

gettext-base

gir1.2-glib-2.0

gnupg

gpgv

grep

groff-base

grub-common

grub-gfxpayload-lists

grub-pc

grub-pc-bin

grub2-common

gzip

hdparm

hostname

ifupdown

info

initramfs-tools

initramfs-tools-bin

initscripts

insserv

install-info

installation-report

iproute

iptables

iputils-ping

iputils-tracepath

irqbalance

isc-dhcp-client

isc-dhcp-common

iso-codes

kbd

keyboard-configuration

klibc-utils

krb5-locales

landscape-common

language-pack-en

language-pack-en-base

language-pack-zh-hans

language-pack-zh-hans-base

language-selector-common

laptop-detect

less

libaccountsservice0

libacl1

libapt-inst1.4

libapt-pkg4.12

libasn1-8-heimdal

libattr1

libbind9-80

libblkid1

libboost-iostreams1.46.1

libbsd0

libbz2-1.0

libc-bin

libc6

libcap-ng0

libclass-accessor-perl

libclass-isa-perl

libcomerr2

libcurl3

libcurl3-gnutls

libcwidget3

libdb5.1

libdbus-1-3

libdbus-glib-1-2

libdevmapper1.02.1

libdns81

libdrm-intel1

libdrm-nouveau1a

libdrm-radeon1

libdrm2

libedit2

libelf1

libept1.4.12

libevent-2.0-5

libexpat1

libffi6

libfreetype6

libfribidi0

libfuse2

libgc1c2

libgcc1

libgcrypt11

libgdbm3

libgeoip1

libgirepository-1.0-1

libglib2.0-0

libgmp10

libgnutls26

libgpg-error0

libgpm2

libgssapi-krb5-2

libgssapi3-heimdal

libhcrypto4-heimdal

libheimbase1-heimdal

libheimntlm0-heimdal

libhx509-5-heimdal

libidn11

libio-string-perl

libisc83

libisccc80

libisccfg82

libiw30

libjs-jquery

libk5crypto3

libkeyutils1

libklibc

libkrb5-26-heimdal

libkrb5-3

libkrb5support0

libldap-2.4-2

liblocale-gettext-perl

liblockfile-bin

liblockfile1

liblwres80

liblzma5

libmagic1

libmount1

libncurses5

libncursesw5

libnewt0.52

libnfnetlink0

libnih-dbus1

libnih1

libnl-3-200

libnl-genl-3-200

libp11-kit0

libpam-modules

libpam-modules-bin

libpam-runtime

libpam0g

libparse-debianchangelog-perl

libparted0debian1

libpcap0.8

libpci3

libpciaccess0

libpcre3

libpcsclite1

libpipeline1

libplymouth2

libpng12-0

libpolkit-gobject-1-0

libpopt0

libpython2.7

libreadline6

libroken18-heimdal

librtmp0

libsasl2-2

libsasl2-modules

libselinux1

libsigc++-2.0-0c2a

libslang2

libsqlite3-0

libss2

libssl1.0.0

libstdc++6

libsub-name-perl

libswitch-perl

libtasn1-3

libtext-charwidth-perl

libtext-iconv-perl

libtext-wrapi18n-perl

libtimedate-perl

libtinfo5

libudev0

libusb-0.1-4

libusb-1.0-0

libuuid1

libwind0-heimdal

libwrap0

libx11-6

libx11-data

libxapian22

libxau6

libxcb1

libxdmcp6

libxext6

libxml2

libxmuu1

linux-firmware

linux-generic-lts-raring

linux-headers-3.8.0-29

linux-headers-3.8.0-29-generic

linux-headers-generic-lts-raring

linux-image-3.8.0-29-generic

linux-image-generic-lts-raring

locales

lockfile-progs

login

logrotate

lsb-base

lsb-release

lshw

lsof

ltrace

makedev

man-db

manpages

mawk

memtest86+

mime-support

mlocate

module-init-tools

mount

mountall

mtr-tiny

multiarch-support

nano

ncurses-base

ncurses-bin

net-tools

netbase

netcat-openbsd

ntfs-3g

ntpdate

openssh-client

openssh-server

openssl

os-prober

parted

passwd

patch

pciutils

perl

perl-base

perl-modules

plymouth

plymouth-theme-ubuntu-text

popularity-contest

powermgmt-base

ppp

pppconfig

pppoeconf

procps

psmisc

python

python-apport

python-apt

python-apt-common

python-chardet

python-crypto

python-dbus

python-dbus-dev

python-debian

python-gdbm

python-gi

python-gnupginterface

python-httplib2

python-keyring

python-launchpadlib

python-lazr.restfulclient

python-lazr.uri

python-minimal

python-newt

python-oauth

python-openssl

python-pam

python-pkg-resources

python-problem-report

python-serial

python-simplejson

python-twisted-bin

python-twisted-core

python-wadllib

python-xapian

python-zope.interface

python2.7

python2.7-minimal

readline-common

resolvconf

rsync

rsyslog

screen

sed

sensible-utils

sgml-base

ssh-import-id

strace

sudo

sysv-rc

sysvinit-utils

tar

tasksel

tasksel-data

tcpd

tcpdump

telnet

time

tmux

tzdata

ubuntu-keyring

ubuntu-minimal

ubuntu-standard

ucf

udev

ufw

unattended-upgrades

update-manager-core

update-notifier-common

upstart

ureadahead

usbutils

util-linux

uuid-runtime

vim

vim-common

vim-runtime

vim-tiny

w3m

wget

whiptail

whoopsie

wireless-tools

wpasupplicant

xauth

xkb-data

xml-core

xz-lzma

xz-utils

zlib1g


8.上传系统镜像:

光驱放入CentOS6.4_mini光盘:

[root@PXEServer ~]# mount /dev/cdrom /mnt

[root@PXEServer ~]# cp -av /mnt /iso/

[root@PXEServer ~]# mv /iso/mnt /iso/centos6.4

[root@PXEServer ~]# cp -av /iso/centos6.4/isolinux/vmlinuz /tftpboot/bootkernels/centos6.4/

[root@PXEServer ~]# cp -av /iso/centos6.4/isolinux/initrd.img /tftpboot/bootkernels/centos6.4/

光驱放入Ubuntu12.04光盘:

[root@PXEServer ~]# mount /dev/cdrom /mnt

[root@PXEServer ~]# cp -av /mnt /iso/

[root@PXEServer ~]# mv /iso/mnt /iso/ubuntu12.04

[root@PXEServer ~]# cp -av /iso/ubuntu12.04/install/vmlinuz /tftpboot/bootkernels/ubuntu12.04/

[root@PXEServer ~]# cp -av /iso/ubuntu12.04/install/initrd.gz /tftpboot/bootkernels/ubuntu12.04/


9.设置目录权限:

[root@PXEServer ~]# chmod -R 755 /tftpboot

[root@PXEServer ~]# chmod -R 755 /iso

10.启动PXEClient:

(1).PXE主菜单显示:

(2).CentOS菜单显示

(3).Ubuntu菜单显示


**********************************************

*******************说   明********************

**********************************************

上述配置在centos安装上已经实现,但是ubuntu server的安装上还是存在些问题,网上有很多以http的方式安装ubuntu,但是没有nfs安装的成功案例,如果有成功的朋友希望能得到指教。

原文地址:https://www.cnblogs.com/myiaas/p/4161354.html