Ubuntu12.04 nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 nginx+pxe+tftpd+samba/nfs+dhcpd
无盘安装windows & linux


参考文档:
http://www.debian-administration.org/article/478/Setting_up_a_server_for_PXE_network_booting
http://drbl.sourceforge.net/about/

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd



1.安装软件

sudo apt-get install smbfs samba tftpd tftp pxe isc-dhcp-server nfs-kernel-server

2.配置网卡(bridge)---kvm等虚拟机需要桥接,这样才能支持pxe
vim /etc/network/interfaces

auto lo
iface lo inet loopback

iface eth0 inet manual

auto br0

iface br0 inet static
address 192.168.0.1
netmask 255.255.255.0
bridge_ports eth0


3.配置samba (共享windows安装源)
mkdir /smb/{win2008,win2012,win7_x64,win7_x86,win8e_x64,win8e_x86,winxp}
vim /etc/samba/smb.conf

# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# For a step to step guide on installing, configuring and using samba,
# read the Samba-HOWTO-Collection. This may be obtained from:
http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# Many working examples of smb.conf files can be found in the
# Samba-Guide which is generated daily and can be downloaded from:
http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command "testparm"
# to check that you have not made any basic syntactic errors.
#
#---------------
# SELINUX NOTES:
#
# If you want to use the useradd/groupadd family of binaries please run:
# setsebool -P samba_domain_controller on
#
# If you want to share home directories via samba please run:
# setsebool -P samba_enable_home_dirs on
#
# If you create a new directory you want to share you should mark it as
# "samba_share_t" so that selinux will let you write into it.
# Make sure not to do that on system directories as they may already have
# been marked with othe SELinux labels.
#
# Use ls -ldZ /path to see which context a directory has
#
# Set labels only on directories you created!
# To set a label use the following: chcon -t samba_share_t /path
#
# If you need to share a system created directory you can use one of the
# following (read-only/read-write):
# setsebool -P samba_export_all_ro on
# or
# setsebool -P samba_export_all_rw on
#
# If you want to run scripts (preexec/root prexec/print command/...) please
# put them into the /var/lib/samba/scripts directory so that smbd will be
# allowed to run them.
# Make sure you COPY them and not MOVE them so that the right SELinux context
# is applied, to check all is ok use restorecon -R -v /var/lib/samba/scripts
#
#--------------
#
#======================= Global Settings =====================================
    
[global]
    
# ----------------------- Network Related Options -------------------------
#
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
#
# server string is the equivalent of the NT Description field
#
# netbios name can be used to specify a server name not tied to the hostname
#
# Interfaces lets you configure Samba to use multiple interfaces
# If you have multiple network interfaces then you can list the ones
# you want to listen on (never omit localhost)
#
# Hosts Allow/Hosts Deny lets you restrict who can connect, and you can
# specifiy it as a per share option as well
#
    workgroup = WORKGROUP
    server string = Samba Server Version %v
    
   netbios name = Jlive
    
   interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
   hosts allow = 127. 192.168.12. 192.168.13.
    
# --------------------------- Logging Options -----------------------------
#
# Log File let you specify where to put logs and how to split them up.
#
# Max Log Size let you specify the max size log files should reach
    
    # logs split per machine
    log file = /var/log/samba/log.%m
    # max 50KB per log file, then rotate
    max log size = 50
    
# ----------------------- Standalone Server Options ------------------------
#
# Scurity can be set to user, share(deprecated) or server(deprecated)
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.

    security = user
    passdb backend = tdbsam

#**********************************************************************#
    username map = /etc/samba/smbusers


# ----------------------- Domain Members Options ------------------------
#
# Security must be set to domain or ads
#
# Use the realm option only with security = ads
# Specifies the Active Directory realm the host is part of
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.
#
# Use password server option only with security = server or if you can't
# use the DNS to locate Domain Controllers
# The argument list may include:
  password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
# or to auto-locate the domain controller/s
  password server = *
    
    
   security = domain
   passdb backend = tdbsam
   realm = MY_REALM

   password server =

# ----------------------- Domain Controller Options ------------------------
#
# Security must be set to user for domain controllers
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.
#
# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don't use this
# if you already have a Windows NT domain controller doing this job
#
# Domain Logons let Samba be a domain logon server for Windows workstations.
#
# Logon Scrpit let yuou specify a script to be run at login time on the client
# You need to provide it in a share called NETLOGON
#
# Logon Path let you specify where user profiles are stored (UNC path)
#
# Various scripts can be used on a domain controller or stand-alone
# machine to add or delete corresponding unix accounts
#
   security = user
   passdb backend = tdbsam
    
   domain master = yes
   domain logons = yes
    
    # the login script name depends on the machine name
   logon script = %m.bat
    # the login script name depends on the unix user used
   logon script = %u.bat
   logon path = \\%L\Profiles\%u
    # disables profiles support by specifing an empty path
   logon path =          
    
   add user script = /usr/sbin/useradd "%u" -n -g users
   add group script = /usr/sbin/groupadd "%g"
   add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /nohome -s /bin/false "%u"
   delete user script = /usr/sbin/userdel "%u"
   delete user from group script = /usr/sbin/userdel "%u" "%g"
   delete group script = /usr/sbin/groupdel "%g"
    
    
# ----------------------- Browser Control Options ----------------------------
#
# set local master to no if you don't want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
#
# OS Level determines the precedence of this server in master browser
# elections. The default value should be reasonable
#
# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
   local master = no
   os level = 33
   preferred master = yes
    
#----------------------------- Name Resolution -------------------------------
# Windows Internet Name Serving Support Section:
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
#
# - WINS Support: Tells the NMBD component of Samba to enable it's WINS Server
#
# - WINS Server: Tells the NMBD components of Samba to be a WINS Client
#
# - WINS Proxy: Tells Samba to answer name resolution queries on
  behalf of a non WINS capable client, for this to work there must be
  at least one    WINS Server on the network. The default is NO.
#
# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups.
    
   wins support = yes
   wins server = w.x.y.z
   wins proxy = yes
    
   dns proxy = yes
    
# --------------------------- Printing Options -----------------------------
#
# Load Printers let you load automatically the list of printers rather
# than setting them up individually
#
# Cups Options let you pass the cups libs custom options, setting it to raw
# for example will let you use drivers on your Windows clients
#
# Printcap Name let you specify an alternative printcap file
#
# You can choose a non default printing system using the Printing option
    
    load printers = yes
    cups options = raw

   printcap name = /etc/printcap
    #obtain list of printers automatically on SystemV
   printcap name = lpstat
   printing = cups

# --------------------------- Filesystem Options ---------------------------
#
# The following options can be uncommented if the filesystem supports
# Extended Attributes and they are enabled (usually by the mount option
# user_xattr). Thess options will let the admin store the DOS attributes
# in an EA and make samba not mess with the permission bits.
#
# Note: these options can also be set just per share, setting them in global
# makes them the default for all shares

   map archive = no
   map hidden = no
   map read only = no
   map system = no
   store dos attributes = yes


#============================ Share Definitions ==============================
    
[homes]
    comment = Home Directories
    browseable = no
    writable = yes
   valid users = %S
   valid users = MYDOMAIN\%S
    
[printers]
    comment = All Printers
    path = /var/spool/samba
    browseable = no
    guest ok = no
    writable = no
    printable = yes
    
# Un-comment the following and create the netlogon directory for Domain Logons
   [netlogon]
   comment = Network Logon Service
   path = /var/lib/samba/netlogon
   guest ok = yes
   writable = no
   share modes = no
    
    
# Un-comment the following to provide a specific roving profile share
# the default is to use the user's home directory
   [Profiles]
   path = /var/lib/samba/profiles
   browseable = no
   guest ok = yes
    
    
# A publicly accessible directory, but read only, except for people in
# the "staff" group
   [public]
   comment = Public Stuff
   path = /home/samba
   public = yes
   writable = yes
   printable = no
   write list = +staff


#######################################################
    [software]
    comment = software for windows&linux
    path = /mnt/software
    browseable = yes
    public = no
    writable = no
    valid users = liujun
    #hosts allow = 192.168.0.0/24 127.0.0.1
    

    [iso]
    comment = Kinds of iso(linux,windows)
    path = /mnt/ISO
    browseable = yes
    public = no
    writable = no
    valid users = liujun
    #hosts allow = 192.168.0.0/24 127.0.0.1

    [main]
    comment = main source
    path = /mnt/main
    browseable = yes
    public = no
    writable = no
    valid users = liujun
    write list = liujun
    #hosts allow = 192.168.0.0/24 127.0.0.1

    [tmp]
    comment = tmp
    path = /mnt/tmp
    browseable = yes
    public = no
    writable = no
    valid users = liujun
    write list = liujun
    #hosts allow = 192.168.0.0/24 127.0.0.1

    [usb]
    comment = usb
    path = /mnt/usb
    browseable = yes
    public = no
    writable = no
    valid users = liujun
    write list = liujun
    #hosts allow = 192.168.0.0/24 127.0.0.1
#######################################################
    [win7_x86]
    comment = win7_x86 pxe install
    path = /smb/win7_x86
    writable = no
    public = yes

    [win7_x64]
    comment = win7_x64 pxe install
    path = /smb/win7_x64
    writable = no
    public = yes

    [win2008]
    comment = win2008 pxe install
    path = /smb/win2008
    writable = no
    public = yes


#################################################

    [win8e_x64]
    comment = Win8 Enterprise 64 bit pxe install
    path = /smb/win8e_x64
    writable = no
    public = yes

    [win8e_x86]
    comment = Win8 Enterprise 32 bit pxe install
    path = /smb/win8e_x86
    writable = no
    public = yes

    [win2012]
    comment = win2012 pxe install
    path = /smb/win2012
    writable = no
    public = yes

#################################################

    [winxp]
    comment = winXP pxe install
    path = /smb/winxp
    writable = no
    public = yes

#################################################



可以加上windows/unix用户映射
cat /etc/samba/smbusers

# Unix_name = SMB_name1 SMB_name2 ...
root = administrator admin
#nobody = guest pcguest smbguest
liujun = guest pcguest smbguest


#############################################
4.nginx安装与配置(用来共享linux镜像及安装源)
#############################################
这里建议采用源码来安装,我安装的时候nginx的版本是1.4.1,具体的情况依个人环境而定,详情请访问nginx官方网站nginx.org
下面是我写的一个自动安装部署脚本,有兴趣的朋友可以参考参考,不足之处还请不吝指教噢!

##############################################
#!/bin/bash
##############################################
#:<<TEST_SYNTAX
#varnish(memcache)

####################################################
#Check user & group
####################################################

USER=$(cat /etc/passwd|cut -d: -f1 |grep nginx)
GROUP=$(cat /etc/group|cut -d: -f1 |grep nginx)

echo "--------------------------------------------"
echo -e "Check \e[31;1muser & group\e[0m"
echo ""
if [ "$GROUP" = "" ];then
    groupadd -r nginx -g 600
    echo -e "\e[32;1mGroup nginx\e[0m is added"
else
    echo -e "\e[32;1mGroup\e[0m nginx is exist"
fi

if [ "$USER" = "" ];then
    useradd -r nginx  -u 600 -g nginx -s /sbin/nologin
    echo -e "\e[32;1mUser nginx\e[0m is added"
else
    echo -e "\e[32;1mUser\e[0m nginx is exist"
fi
echo ""
echo ""
echo ""


#########################################################
#Install libs developed
#########################################################
echo "--------------------------------------------"
echo -e "Check \e[31;1mlibs developed\e[0m"
echo ""
PACKAGE="daemon gcc g++ autoconf automake make zlib-dev libssl-dev libpcre3-dev   libxml2-dev libxslt1-dev libextutils-depends-perl"
for i in $PACKAGE
do
    FLAG=$(dpkg -L $i 2>/dev/null 1>&2|wc -l)
    if [ "$FLAG" == "3" ];then
        apt-get -y install $i
    else
        echo -e "\e[32;1m$i\e[0m is installed"
    fi
done


#########################################################
#Building & Install
#########################################################
echo ""
echo "--------------------------------------------"
echo -e "\e[31;1mWether nginx is installed or not\e[0m"
echo ""
which nginx >/dev/null 2>&1
if [ "$?" != "0" ];then
echo -e "\e[31;1mInstalling nginx\e[0m \e[34;1m... ...\e[0m"
sleep 1
echo ""

NGINX_SOURCE_FILE=
NGINX_SOURCE_FILE_VERSION="1.4.1"

tar -zxvf ${NGINX_SOURCE_FILE:-nginx-${NGINX_SOURCE_FILE_VERSION}.tar.gz} -C /usr/local/src/
cd /usr/local/src/nginx-${NGINX_SOURCE_FILE_VERSION}
./configure    \
  --prefix=/usr/local/nginx                      \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error_log    \
  --pid-path=/var/run/nginx.pid         \
  --lock-path=/var/lock/subsys/nginx \
  --user=nginx                       \
  --group=nginx                      \
  --with-http_ssl_module             \
  --with-http_realip_module          \
  --with-http_addition_module        \
  --with-http_xslt_module            \
  --with-http_sub_module             \
  --with-http_dav_module             \
  --with-http_flv_module             \
  --with-http_mp4_module             \
  --with-http_gzip_static_module     \
  --with-http_random_index_module    \
  --with-http_secure_link_module     \
  --with-http_degradation_module     \
  --with-http_stub_status_module     \
  --http-log-path=/var/log/nginx/access_log          \
  --http-client-body-temp-path=/var/tmp/nginx/client \
  --http-proxy-temp-path=/var/tmp/nginx/proxy        \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi      \
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi      \
  --http-scgi-temp-path=/var/tmp/nginx/scgi       

make && make install

else
    echo -e "\e[32;1mNginx\e[0m is installed"
    echo ""
fi

echo -e "\e[31;1mInstall\e[0m \e[32;1mOK!\e[0m"

#########################################################
#Check init.d shell script
#########################################################
mkdir -p /var/tmp/nginx/client #Because of a little bug, this directory needs created by yourself
mkdir -p /var/lock/subsys/ #Because of a little bug, this directory needs created by yourself


NGINX_INIT=/etc/init.d/nginx
cat > $NGINX_INIT <<'HELLO'
#! /bin/sh
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: nginx init.d dash script for Ubuntu <=9.10.
# Description:       nginx init.d dash script for Ubuntu <=9.10.
### END INIT INFO
#------------------------------------------------------------------------------
# nginx - this Debian Almquist shell (dash) script, starts and stops the nginx
        daemon for ubuntu 9.10 and lesser version numbered releases.
#
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
              proxy and IMAP/POP3 proxy server.  This \
       script will manage the initiation of the \
       server and it's process state.
#
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /acronymlabs/server/nginx.pid
# Provides:    nginx
#
# Author:  Jason Giedymin
         .
#
# Version: 2.0 02-NOV-2009 jason.giedymin AT gmail.com
# Notes: nginx init.d dash script for Ubuntu <=9.10.
#
# This script's project home is:
#     http://code.google.com/p/nginx-init-ubuntu/
#
#------------------------------------------------------------------------------
                              MIT X11 License
#------------------------------------------------------------------------------
#
# Copyright (c) 2009 Jason Giedymin, http://Amuxbit.com formerly
                    http://AcronymLabs.com
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
                              Functions
#------------------------------------------------------------------------------
. /lib/lsb/init-functions

#------------------------------------------------------------------------------
                              Consts
#------------------------------------------------------------------------------
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx

PS="nginx"
PIDNAME="nginx"                #lets you do $PS-slave
PIDFILE=$PIDNAME.pid                    #pid file
PIDSPATH=/var/run

DESCRIPTION="Nginx Server..."

RUNAS=root                              #user to run as

SCRIPT_OK=0                             #ala error codes
SCRIPT_ERROR=1                          #ala error codes
TRUE=1                                  #boolean
FALSE=0                                 #boolean

lockfile=/var/lock/subsys/nginx
NGINX_CONF_FILE="/etc/nginx/nginx.conf"

#------------------------------------------------------------------------------
                              Simple Tests
#------------------------------------------------------------------------------

#test if nginx is a file and executable
test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

#set exit condition
#set -e

#------------------------------------------------------------------------------
                              Functions
#------------------------------------------------------------------------------

setFilePerms(){

        if [ -f $PIDSPATH/$PIDFILE ]; then
                chmod 400 $PIDSPATH/$PIDFILE
        fi
}

configtest() {
    $DAEMON -t -c $NGINX_CONF_FILE
}

getPSCount() {
    return `pgrep -f $PS | wc -l`
}

isRunning() {
        if [ $1 ]; then
                pidof_daemon $1
                PID=$?

                if [ $PID -gt 0 ]; then
                        return 1
                else
                        return 0
                fi
        else
                pidof_daemon
                PID=$?

                if [ $PID -gt 0 ]; then
                        return 1
                else
                        return 0
                fi
        fi
}

#courtesy of php-fpm
wait_for_pid () {
        try=0

        while test $try -lt 35 ; do

                case "$1" in
                        'created')
                        if [ -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;

                        'removed')
                        if [ ! -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                esac

                #echo -n .
                try=`expr $try + 1`
                sleep 1
        done
}

status(){
    isRunning
    isAlive=$?

    if [ "${isAlive}" -eq $TRUE ]; then
                echo "$PIDNAME found running with processes:  `pidof $PS`"
        else
                echo "$PIDNAME is NOT running."
        fi


}

removePIDFile(){
    if [ $1 ]; then
                if [ -f $1 ]; then
                    rm -f $1
            fi
        else
        #Do default removal
        if [ -f $PIDSPATH/$PIDFILE ]; then
                    rm -f $PIDSPATH/$PIDFILE
            fi
        fi
}

start() {
        log_daemon_msg "Starting $DESCRIPTION"
    
    isRunning
    isAlive=$?
    
        if [ "${isAlive}" -eq $TRUE ]; then
                log_end_msg $SCRIPT_ERROR
        else
                start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \
                -- -c $NGINX_CONF_FILE
                setFilePerms
                log_end_msg $SCRIPT_OK
        fi
}

stop() {
    log_daemon_msg "Stopping $DESCRIPTION"
    
    isRunning
    isAlive=$?
        if [ "${isAlive}" -eq $TRUE ]; then
                start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE

        wait_for_pid 'removed' $PIDSPATH/$PIDFILE

                if [ -n "$try" ] ; then
                        log_end_msg $SCRIPT_ERROR
                else
                        removePIDFile
                    log_end_msg $SCRIPT_OK
                fi

        else
                log_end_msg $SCRIPT_ERROR
        fi
}

reload() {
    configtest || return $?

    log_daemon_msg "Reloading (via HUP) $DESCRIPTION"

        isRunning
        if [ $? -eq $TRUE ]; then
        `killall -HUP $PS` #to be safe

                log_end_msg $SCRIPT_OK
        else
                log_end_msg $SCRIPT_ERROR
        fi
}

quietupgrade() {
    log_daemon_msg "Peforming Quiet Upgrade $DESCRIPTION"

        isRunning
        isAlive=$?
        if [ "${isAlive}" -eq $TRUE ]; then
        kill -USR2 `cat $PIDSPATH/$PIDFILE`
        kill -WINCH `cat $PIDSPATH/$PIDFILE.oldbin`
        
        isRunning
        isAlive=$?
        if [ "${isAlive}" -eq $TRUE ]; then
            kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`
            wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin
                        removePIDFile $PIDSPATH/$PIDFILE.oldbin

            log_end_msg $SCRIPT_OK
        else
            log_end_msg $SCRIPT_ERROR
            
            log_daemon_msg "ERROR! Reverting back to original $DESCRIPTION"

            kill -HUP `cat $PIDSPATH/$PIDFILE`
            kill -TERM `cat $PIDSPATH/$PIDFILE.oldbin`
            kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`

            wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin
                        removePIDFile $PIDSPATH/$PIDFILE.oldbin

            log_end_msg $SCRIPT_ok
        fi
        else
                log_end_msg $SCRIPT_ERROR
        fi
}

terminate() {
        log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"
        
    PIDS=`pidof $PS` || true

    [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`

    for i in $PIDS; do
        if [ "$i" = "$PIDS2" ]; then
                kill $i
                        wait_for_pid 'removed' $PIDSPATH/$PIDFILE
            removePIDFile
        fi
    done

    log_end_msg $SCRIPT_OK
}

destroy() {
    log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION"
    killall $PS -q >> /dev/null 2>&1
    log_end_msg $SCRIPT_OK
}

pidof_daemon() {
    PIDS=`pidof $PS` || true

    [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`

    for i in $PIDS; do
        if [ "$i" = "$PIDS2" ]; then
            return 1
        fi
    done
    return 0
}

case "$1" in
  start)
    start
        ;;
  stop)
    stop
        ;;
  restart|force-reload)
    stop
    sleep 1
    start
        ;;
  reload)
    $1
    ;;
  status)
    status
    ;;
  configtest)
        $1
        ;;
  quietupgrade)
    $1
    ;;
  terminate)
    $1
    ;;
  destroy)
    $1
    ;;
  *)
    FULLPATH=/etc/init.d/$PS
    echo "Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|quietupgrade|terminate|destroy}"
    echo "       The 'destroy' command should only be used as a last resort."
    exit 1
    ;;
esac

exit 0
HELLO

chmod 755 $NGINX_INIT


#TEST_SYNTAX

#########################################################
#Config file
#########################################################
NGINX_CONFIG=/etc/nginx/nginx.conf

WORKER_PROCESSES=
WORKER_CONNECTIONS=
SERVER_NAME1=server101.jlive.com
SERVER_ROOT1=

SERVER_NAME2=
SERVER_ROOT2=

HTTPS_SERVER=web101.jlive.com
HTTPS_ROOT=/var/www/server
SSL_CRT=/etc/pki/tls/certs/nginx.crt
SSL_KEY=/etc/pki/tls/private/nginx.key
cat >${NGINX_CONFIG:-/etc/nginx/nginx.conf} <<HERE

#user  nobody;
worker_processes  ${WORKER_PROCESSES:-8}; #工作进程数

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  ${WORKER_CONNECTION:-30000}; #最大并发连接数
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    
    open_log_file_cache max=1000 inactive=20s min_uses=2 valid=1m; #meta数据缓存
    log_format  main  '\$remote_addr - \$remote_user [\$time_local] "\$request" '
                      '\$status \$body_bytes_sent "\$http_referer" '
                      '"\$http_user_agent" "\$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;


#压缩功能
    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types *;
    gzip_vary on;
    

#反向代理
    client_max_body_size 300m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 60s;
    proxy_read_timeout 60s;
    proxy_send_timeout 60s;
    proxy_buffer_size 16k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    proxy_temp_path /var/tmp/nginx/proxy_temp 1 2;
    proxy_cache_path /var/tmp/nginx/proxy_cache levels=1:2 keys_zone=one:500m inactive=1d max_size=1g;


#负载均衡
   upstream my_server_pool {
   server server103.jlive.com:8080 weight=1 max_fails=2 fail_timeout=30s;
   server www.jlive.com weight=1 max_fails=2 fail_timeout=30s;
   }
   upstream my_server_pool {
   server 192.168.0.1:8080 weight=1 max_fails=2 fail_timeout=30s;
   server 192.168.0.2:8080 weight=2 max_fails=2 fail_timeout=30s;
   }



    server {
        listen       80;
        server_name  ${SERVER_NAME1:-www.example.com};

        #charset koi8-r;

        access_log  /var/log/nginx/${SERVER_NAME1:-www.example.com}_access main buffer=32k;
        error_log  /var/log/nginx/${SERVER_NAME1:-www.example.com}_error warn;

    root ${SERVER_ROOT1:-/usr/local/nginx};
        location / {
        root html;
            index  index.html index.htm;
        }


#启用反向代理缓存
       location /sms {
       proxy_pass http://server103.jlive.com:8080;
       proxy_cache one;
       proxy_set_header Host \$host;
       proxy_set_header X-Forwarded-For \$remote_addr;
       proxy_cache_valid 200 10m;
       proxy_cache_valid 304 1m;
       proxy_cache_valid 301 302 1h;
       proxy_cache_valid any 1m;
       }
       location /ftp {
       proxy_pass http://www.jlive.com;
       proxy_cache one;
       proxy_set_header Host \$host;
       proxy_set_header X-Forwarded-For \$remote_addr;
       proxy_cache_valid 200 10m;
       proxy_cache_valid 304 1m;
       proxy_cache_valid 301 302 1h;
       proxy_cache_valid any 1m;
       }
       location ~* .*\.(gif|jpg|jpeg|png|bmp|swf|flv|js|css|html) {
       proxy_cache one;
       proxy_set_header Host \$host;
       proxy_set_header X-Forwarded-For \$remote_addr;
       proxy_cache_key \$host\$uri\$is_args\$args;
       proxy_cache_valid 200 10m;
       proxy_cache_valid 304 1m;
       proxy_cache_valid 301 302 1h;
       proxy_cache_valid any 1m;
       }



#密码认证,下载限速,简单的访问控制
   location /data {
       autoindex on;
       auth_basic "请输入用户名&密码"; #基本密码认证(htpasswd -cm ...)
       auth_basic_user_file /etc/nginx/.htpasswd;
       limit_rate_after 20m; #前20m不限速
       limit_rate 300k;
       allow 192.168.0.1
       deny 192.168.0.2
   }


#别名
      location /iso {
           alias /var/www/pub/iso;
       }


#nginx状态
      location /nginx_status {
       stub_status on;
       access_log off;
       auth_basic "请输入用户名&密码"; #基本密码认证(htpasswd -cm ...)
       auth_basic_user_file /etc/nginx/.htpasswd;
       }


#地址重写
   if (\$http_user_agent ~ MSIE) {
       rewrite ^(.*)\$ /msie/\$1 last;
   }
   if (! -f \$request_filename) {
       rewrite ^/file/(.*)\$ /site/\$host/img/\$1 last;
   }
   if (\$host="www.abc.com") {
       rewrite ^/(.*)\$ https://web.example.com permanent;
   }
   rewrite ^/data/\$ /bbs/ permanent;


#防盗链
   location ~* .*\.(gif|jpg|jpeg|png|bmp|swf|flv)\$ {
   valid_referers none blocked www.example.com *.example.com;
   if (\$invalid_referer) {
       rewrite ^/(.*)\$ http://www.example.net/block.html;
   }


#return指令
   location ~* .*\.(sh|bash)\$ {
       return 403;
   }


#浏览器缓存
    location ~* .*\.(gif|jpg|jpeg|png|bmp|swf|flv)\$ {
    expires 30d;
    }
    location ~ .*\.(js|css)\$ {
    expires 1h;
    }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        error_page   403  /403.html;
        location = /403.html {
            root   html;
        }
        error_page   404  /404.html;
        location = /404.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php\$ {
          proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php\$ {
          root           html;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /scripts\$fastcgi_script_name;
          include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
          deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
      listen       8000;
      listen       somename:8080;
      server_name  somename  alias  another.alias;

      location / {
          root   html;
          index  index.html index.htm;
      }
    #}


    # HTTPS server
    #
   server {
       listen       443;
       server_name  ${HTTPS_SERVER:-web.example.com};
#
       ssl                  on;
       ssl_certificate      ${SSL_CRT:-/etc/pki/tls/certs/localhost.crt};
       ssl_certificate_key  ${SSL_KEY:-/etc/pki/tls/private/localhost.key};
#
       ssl_session_timeout  5m;
#
       ssl_protocols  SSLv2 SSLv3 TLSv1;
       ssl_ciphers  HIGH:!aNULL:!MD5;
       ssl_prefer_server_ciphers   on;
#
       location / {
       root ${HTTPS_ROOT:-/var/www/https}/html;
           index  index.html index.htm;
       }
   }

}
HERE


#########################################################
#https test index.html
#########################################################
if [ -d ${HTTPS_ROOT:-/var/www/https} ];then
    rm -rf ${HTTPS_ROOT:-/var/www/https}
fi
if [ ! -d ${HTTPS_ROOT:-/var/www/https} ];then
    mkdir -p ${HTTPS_ROOT:-/var/www/https}/html
fi
cat >${HTTPS_ROOT:-/var/www/https}/html/index.html <<HERE







Welcome to nginx------HTTPS!


If you see this page, the nginx HTTPS web server is successfully installed and
working. Further configuration is required.



For online documentation and support please refer to
nginx.org .

Commercial support is available at
nginx.com .



Thank you for using nginx.





HERE

#########################################################
#Error page
#########################################################

#403
cat >${SERVER_ROOT1:-/usr/local/nginx}/html/403.html <<HERE







Sorry, invalid privilege


If you see this page, that's to say you don't have privilege to request this page



For online documentation and support please refer to
nginx.org .

Commercial support is available at
nginx.com .



Thank you for using nginx.





HERE

#404
cat >${SERVER_ROOT1:-/usr/local/nginx}/html/404.html <<HERE







Sorry, request not found


If you see this page, that's to say your requests is not found!



For online documentation and support please refer to
nginx.org .

Commercial support is available at
nginx.com .



Thank you for using nginx.





HERE

echo ""
/etc/init.d/nginx restart
/etc/init.d/nginx status


##############################
在/etc/nginx/nginx.conf中只需加上一个别名和一个autoindex on的选项就可以完成介质共享噢!

#别名
      location /iso {
           alias /var/www/pub/iso;
       }
       location /pub {
            alias /var/www/pub/;
        autoindex on;
        }
#nginx状态
       location /nginx_status {
        stub_status on;
        access_log off;
        auth_basic "请输入用户名&密码"; #基本密码认证(htpasswd -cm ...)
        auth_basic_user_file /etc/nginx/.htpasswd;
        }



最后,将iso镜像开机自动挂载

#
# /etc/fstab
# Created by anaconda on Sun Dec 16 05:53:28 2012
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=332ad6a5-4105-4e02-af82-e24a55c655c8    /boot    ext4    defaults 1 1
/dev/mapper/vg0-centos         ext4    defaults  1 1
/dev/mapper/vg1-swap     none  swap    defaults    0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/sda5 /mnt/ISO    ntfs    defaults 0 0
/dev/sda6 /mnt/software    ntfs    defaults 0 0
/dev/sda7 /mnt/main    ntfs    defaults 0 0
/dev/sda8 /mnt/work    ntfs    defaults 0 0
/dev/sda9 /mnt/backup    ntfs    defaults 0 0
/dev/sda14 /mnt/tmp    ntfs    defaults 0 0

###############################################################
#win7
/mnt/ISO/win7/cn_windows_7_ultimate_x64_dvd_x15-66043.iso /smb/win7_x64 udf defaults,loop    0 0
/mnt/ISO/win7/cn_windows_7_ultimate_x86_dvd_x15-65907.iso /smb/win7_x86 udf defaults,loop    0 0
/mnt/ISO/win7/cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_vl_build_x64_dvd_617396.iso /smb/win2008 udf defaults,loop    0 0

#win8
/mnt/ISO/win8/cn_windows_8_enterprise_x64_dvd_917570.iso /smb/win8e_x64 udf defaults,loop     0 0
/mnt/ISO/win8/cn_windows_8_enterprise_x86_dvd_917682.iso /smb/win8e_x86 udf defaults,loop     0 0
/mnt/main/iso/windows_server2012_x64.iso /smb/win2012 udf defaults,loop     0 0

#winXP
#/mnt/ISO/XP/GHOSTXP_SP2_purge.iso /smb/winxp iso9660 defaults,loop     0 0
/mnt/ISO/XP/XP_PRO_SP3_purge.iso   /smb/winxp iso9660 defaults,loop     0 0
##############################################################


############################################################
#Centos6.3
/mnt/ISO/linux/centos/CentOS-6.3-x86_64-bin-DVD1.iso /var/www/pub/ftp/centos6.3_1 iso9660 defaults,loop    0 0
/mnt/ISO/linux/centos/CentOS-6.3-x86_64-bin-DVD2.iso /var/www/pub/ftp/centos6.3_2 iso9660 defaults,loop    0 0

#Ubuntu12.04
/mnt/ISO/linux/ubuntu/ubuntu-12.04-server-amd64.iso  /var/www/pub/ftp/ubuntu12.04 iso9660 defaults,loop    0 0

#Kubuntu12.04
/mnt/ISO/linux/ubuntu/kubuntu-12.04-dvd-amd64.iso    /var/www/pub/ftp/kubuntu12.04 iso9660 defaults,loop    0 0

#Debian6.0
/mnt/ISO/linux/debian/debian-6.0.6-amd64-DVD-1.iso   /var/www/pub/ftp/debian6.0 iso9660 defaults,loop    0 0

#Red Hat Enterprise Server 6
/mnt/ISO/linux/redhat/rhel-server-6.2-x86_64-dvd.iso   /var/www/pub/ftp/rhel6.2 iso9660 defaults,loop    0 0

#Red Hat Enterprise Server 5
/mnt/ISO/linux/redhat/rhel-server-5.8-x86_64-dvd.iso    /var/www/pub/ftp/rhel5_x64 iso9660 defaults,loop    0 0

/mnt/main/iso/rhel-server-5.8-i386-dvd.iso /var/www/pub/ftp/rhel5_x86 iso9660 defaults,loop    0 0
/mnt/main/iso/rhds_x86.iso /var/www/pub/ftp/rhds iso9660 defaults,loop    0 0

#linuxMINT 13
/mnt/ISO/linux/mint13_mate_cinnamon_x64.iso    /var/www/pub/ftp/mint iso9660 defaults,loop    0 0

#BT5
/mnt/ISO/linux/bt5_r3_x64.iso    /var/www/pub/ftp/bt5 iso9660 defaults,loop    0 0

#Arch linux
/mnt/ISO/linux/archlinux-2012.12.01-dual.iso     /var/www/pub/ftp/arch iso9660 defaults,loop    0 0

#Free BSD 9.0
/mnt/ISO/linux/freebsd/FreeBSD-9.0-RELEASE-amd64-dvd1.iso /var/www/pub/ftp/freebsd iso9660 defaults,loop    0 0

可以看到,上面iso太多,而系统默认只开了loop0,loop1...loop7这8个loop设备,所以必需增加loop设备,可以在/etc/rc.local中加入
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local


mknod /dev/loop8 b 7 8
mknod /dev/loop9 b 7 9
mknod /dev/loop10 b 7 10
mknod /dev/loop11 b 7 11
mknod /dev/loop12 b 7 12
mknod /dev/loop13 b 7 13
mknod /dev/loop14 b 7 14
mknod /dev/loop15 b 7 15
mknod /dev/loop16 b 7 16
mknod /dev/loop17 b 7 17
mknod /dev/loop18 b 7 18
mknod /dev/loop19 b 7 19
mknod /dev/loop20 b 7 20
mknod /dev/loop21 b 7 21
mknod /dev/loop22 b 7 22
mknod /dev/loop23 b 7 23
mknod /dev/loop24 b 7 24
mknod /dev/loop25 b 7 25

mount -a

5.配置dhcp服务器
touch /var/run/dhcp-server/dhcpd.pid
chown dhcpd: /var/run/dhcp-server/dhcpd.pid

vim /etc/dhcp/dhcpd.conf
#
# Sample configuration file for ISC dhcpd for Debian
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#
#
allow bootp;
allow booting;
next-server 192.168.0.1;
filename "gpxelinux.0";


pid-file-name "/var/run/dhcp-server/dhcpd.pid";

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 {
range 10.254.239.10 10.254.239.20;
option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 {
range dynamic-bootp 10.254.239.40 10.254.239.60;
option broadcast-address 10.254.239.31;
option routers rtr-239-32-1.example.org;
#}

# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200;
#}

# A slightly different configuration for an internal subnet.
subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.100 192.168.0.200;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  option routers 192.168.0.1;
  option broadcast-address 192.168.0.255;
  default-lease-time 600;
  max-lease-time 7200;
}


# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

#host passacaglia {
hardware ethernet 0:0:c0:5d:bd:95;
filename "vmunix.passacaglia";
server-name "toccata.fugue.com";
#}

# Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address fantasia.fugue.com;
#}

# You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" {
match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}

#shared-network 224-29 {
subnet 10.17.224.0 netmask 255.255.255.0 {
   option routers rtr-224.example.org;
}
subnet 10.0.29.0 netmask 255.255.255.0 {
   option routers rtr-29.example.org;
}
pool {
   allow members of "foo";
   range 10.17.224.10 10.17.224.250;
}
pool {
   deny members of "foo";
   range 10.0.29.10 10.0.29.230;
}
#}

netstat -tunlp|grep :67 看是否有监听

6.pxe配置
cat >/etc/xinet.d/tftp <<HERE
# default: off
# description: The tftp server serves files using the trivial file transfer \
   protocol.  The tftp protocol is often used to boot diskless \
   workstations, download configuration files to network-aware printers, \
   and to start the installation process for some operating systems.
service tftp
{
    disable    = no
    socket_type        = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server            = /usr/sbin/in.tftpd
    server_args        = -s /var/lib/tftpboot
    per_source        = 11
    cps            = 100 2
    flags            = IPv4
}

HERE

/etc/init.d/xinetd restart

netstat -tunlp|grep :69 看是否有监听

mkdir /var/lib/tftpboot

ls /var/lib/tftpboot将会看到类似文件,当然这些依各自情况而定,
beauty.png
boot.msg
gpxelinux.0
pxelinux.0
pxelinux.cfg
syslinux.jpg
syslinux_splash.jpg
vesamenu.c32

arch
bt5
centos6.3
debian
debian6.0
debian-installer
freebsd
kubuntu12.04
mint
rhel5.8_x64
rhel5.8_x86
rhel6.2
ubuntu12.04
win2008
win2012
win7
win8
winxp

最主要的配置文件
cat /var/lib/tftpboot/pxelinux.cfg/default

###################################################################
default vesamenu.c32
#prompt 1
timeout 600

display boot.msg

menu clear

menu background syslinux.jpg
menu title Welcome to Jlive's install server!

    menu color screen    37;40      #80ffffff #00000000 std
    menu color border    30;44      #400060 #00000000 std
    menu color title    1;36;44    #20ff00 #00000000 std
    menu color unsel    37;44      #ffff00 #00000000 std
    menu color hotkey    1;37;44    #ffffffff #00000000 std
    menu color sel        7;37;40    #ff0000 #20ff8000 all
    menu color hotsel    1;7;37;40  #e0400000 #20ff8000 all
    menu color disabled    1;30;44    #60cccccc #00000000 std
    menu color scrollbar    30;44      #20ff00 #00000000 std
    menu color tabmsg    31;40      #2000ff #00000000 std
    menu color cmdmark    1;36;40    #c000ffff #00000000 std
    menu color cmdline    37;40      #c0ffffff #00000000 std
    menu color pwdborder    30;47      #80ffffff #20ffffff std
    menu color pwdheader    31;47      #80ff8080 #20ffffff std
    menu color pwdentry    30;47      #80ffffff #20ffffff std
    menu color timeout_msg    37;40      #600000 #00000000 std
    menu color timeout    1;37;40    #40ffff #00000000 std
    menu color help        37;40      #c0ffffff #00000000 std
    menu color msg07    37;40      #90ffffff #00000000 std

############################################################
#Default
############################################################
   menu color screen    37;40      #80ffffff #00000000 std
   menu color border    30;44      #40000000 #00000000 std
   menu color title    1;36;44    #c00090f0 #00000000 std
   menu color unsel    37;44      #90ffffff #00000000 std
   menu color hotkey    1;37;44    #ffffffff #00000000 std
   menu color sel        7;37;40    #e0000000 #20ff8000 all
   menu color hotsel    1;7;37;40  #e0400000 #20ff8000 all
   menu color disabled    1;30;44    #60cccccc #00000000 std
   menu color scrollbar    30;44      #40000000 #00000000 std
   menu color tabmsg    31;40      #90ffff00 #00000000 std
   menu color cmdmark    1;36;40    #c000ffff #00000000 std
   menu color cmdline    37;40      #c0ffffff #00000000 std
   menu color pwdborder    30;47      #80ffffff #20ffffff std
   menu color pwdheader    31;47      #80ff8080 #20ffffff std
   menu color pwdentry    30;47      #80ffffff #20ffffff std
   menu color timeout_msg    37;40      #80ffffff #00000000 std
   menu color timeout    1;37;40    #c0ffffff #00000000 std
   menu color help        37;40      #c0ffffff #00000000 std
   menu color msg07    37;40      #90ffffff #00000000 std
###############################################################


###############################################################
menu include /rhel5.8_x64/default linux    #rhel5.8_x64
menu include /rhel5.8_x86/default linux    #rhel5.8_x86
menu include /rhel6.2/default linux    #rhel6.2
menu include /centos6.3/default linux    #Centos6.3
menu include /ubuntu12.04/default linux #Ubuntu12.04
menu include /kubuntu12.04/default linux #Kubuntu12.04
menu include /debian6.0/default linux    #Debian6.0
menu include /mint/default linux    #Mint13
menu include /bt5/default linux        #Bt5
menu include /arch/default
menu include /freebsd/default linux    #FreeBSD 9.0

menu separator

menu include /win7/default win7_x64    #Win7_x64
menu include /win8/default win8_x64    #Win7_x64
menu include /winxp/default winxp    #WinXP
menu include /win2008/default win2008_x64    #Win7_x64
menu include /win2012/default win2012_x64    #Win7_x64
###############################################################


########
windows
########
cat /var/lib/tftpboot/win7/default

default /win7/vesamenu.c32
#prompt 1
timeout 600

display /win7/boot.msg

menu background /win7/win7.png
menu title Windows 7 Ultimite
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

label win7_x64
  menu label Win7 (^64 bit)
  menu default
  kernel /win7/memdisk
  append iso raw initrd=/win7/winpe_x64.iso

label win7_x86
  menu label Win7 (^32 bit)
  kernel /win7/memdisk
  append iso raw initrd=/win7/winpe_x86.iso
label local
  menu label Boot from ^local drive
  localboot 0xffff

注意:这里只是把winpe_x64.iso通过pxe发布给客户端,linux下批量装windows我这里选用最简单的办法,就是通过samba共享windows安装镜像,把预先封装好的windows pe通过网络发布,pe再驱动客户端的网卡通过samba来访问安装源。
不过这里就又出现一个问题,我们的电脑各式各样,网卡也是纷繁复杂,很难做到一个pe驱动所有网卡,所以企业里面一般都是大批采购相同型号的电脑,这样网卡的问题就得到了解决,因为只需要针对该类型的网卡进行pe封装,具体的封装方法请参考windows AIK.
    还有,32位和64位的镜像要分别对应32位和64位的pe镜像,要不然windows镜像中setup.exe运行不了。
##############
ubuntu
##############
cat /var/lib/tftpboot/ubuntu12.04/default

# D-I config version 2.0
include /ubuntu12.04/boot-screens/menu.cfg
default /ubuntu12.04/boot-screens/vesamenu.c32
prompt 0
timeout 0

cat /var/lib/tftpboot/ubuntu12.04/boot-screens/menu.cfg

menu hshift 13
menu width 49
menu margin 8

menu title Ubuntu 12.04 server LTS
include /ubuntu12.04/boot-screens/stdmenu.cfg
include /ubuntu12.04/boot-screens/txt.cfg
include /ubuntu12.04/boot-screens/gtk.cfg
menu begin advanced
    menu title Advanced options
    include /ubuntu12.04/boot-screens/stdmenu.cfg
    label mainmenu
        menu label ^Back..
        menu exit
    include /ubuntu12.04/boot-screens/adtxt.cfg
    include /ubuntu12.04/boot-screens/adgtk.cfg
menu end
label help
    menu label ^Help
    text help
   Display help screens; type 'menu' at boot prompt to return to this menu
    endtext
    config /ubuntu12.04/boot-screens/prompt.cfg

    
cat /var/lib/tftpboot/ubuntu12.04/boot-screens/stdmenu.cfg

menu background /ubuntu12.04/boot-screens/splash.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
# The command line must be at least one line from the bottom.
menu cmdlinerow 16
menu timeoutrow 16
menu tabmsgrow 18
menu tabmsg Press ENTER to boot or TAB to edit a menu entry


cat /var/lib/tftpboot/ubuntu12.04/boot-screens/txt.cfg

default install
label install
    menu label ^Install
    menu default
    kernel /ubuntu12.04/linux
    append vga=788 initrd=/ubuntu12.04/initrd.gz -- quiet
label preseed autoinstall
    menu label ^Autoinstall
    kernel /ubuntu12.04/linux
    append video=vesa:ywrap,mtrr vga=788 debian-installer/allow_unauthenticated=true  auto=true url=http://www.jlive.com/preseed/ubuntu12.04.seed initrd=/ubuntu12.04/initrd.gz --
label cli

    menu label ^Command-line install
    kernel /ubuntu12.04/linux
    append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false vga=788 initrd=/ubuntu12.04/initrd.gz -- quiet



###############
rhel6
###############

default /rhel6.2/vesamenu.c32
#prompt 1
timeout 600

display /rhel6.2/boot.msg

menu background /rhel6.2/splash.jpg
menu title Red Hat Enterprise Linux 6.2
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

label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel /rhel6.2/vmlinuz
  append initrd=/rhel6.2/initrd.img
label vesa
  menu label Install system with ^basic video driver
  kernel /rhel6.2/vmlinuz
  append initrd=/rhel6.2/initrd.img xdriver=vesa nomodeset
label text
  menu label ^Text mode
  kernel /rhel6.2/vmlinuz
  append initrd=/rhel6.2/initrd.img text
label ks
  menu label ^KS desktop
  kernel /rhel6.2/vmlinuz
  append ks=http://192.168.0.1/ks/rhel6-desktop.cfg initrd=/rhel6.2/initrd.img

label rescue
  menu label ^Rescue installed system
  kernel /rhel6.2/vmlinuz
  append initrd=/rhel6.2/initrd.img rescue
label local
  menu label Boot from ^local drive
  localboot 0xffff
label memtest86
  menu label ^Memory test
  kernel /rhel6.2/memtest
  append -

rhel5

default linux
prompt 1
timeout 600
display /rhel5.8_x64/boot.msg

menu background /beauty.png
menu title Red Hat Enterprise Linux 5.8 64bit
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

label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel /rhel5.8_x64/vmlinuz
  append initrd=/rhel5.8_x64/initrd.img
label boot
  menu label ^Boot.iso
  kernel /rhel5.8_x64/memdisk
  append iso raw initrd=/rhel5.8_x64/boot.iso

label vesa
  menu label Install system with ^basic video driver
  kernel /rhel5.8_x64/vmlinuz
  append initrd=/rhel5.8_x64/initrd.img xdriver=vesa nomodeset
label text
  menu label ^Text mode
  kernel /rhel5.8_x64/vmlinuz
  append initrd=/rhel5.8_x64/initrd.img text
label ks
  menu label ^KS desktop
  kernel /rhel5.8_x64/vmlinuz
  append ks=http://192.168.0.1/ks/rhel5-desktop.cfg initrd=/rhel5.8_x64/initrd.img
label rescue
  menu label ^Rescue installed system
  kernel /rhel5.8_x64/vmlinuz
  append initrd=/rhel5.8_x64/initrd.img rescue
label local
  menu label Boot from ^local drive
  localboot 0xffff
label memtest86
  menu label ^Memory test
  kernel /rhel5.8_x64/memtest
  append -

#############
backtrack5
#############

default /bt5/vesamenu.c32
prompt 0
timeout 300

menu title BackTrack 5
menu background /bt5/splash.png
menu color title 1;37;44 #c0ffffff #00000000 std

label linux
  menu label BackTrack ^Text - Default Boot Text Mode
  kernel /bt5/vmlinuz
  append  boot=casper initrd=/bt5/initrd.gz root=/dev/nfs  netboot=nfs nfsroot=192.168.0.1:/var/www/pub/ftp/bt5

label STEALTH
  menu label BackTrack Stealth - No ^Networking enabled
  kernel /bt5/vmlinuz
  append  boot=casper initrd=/bt5/initrd.gz root=/dev/nfs  netboot=nfs nfsroot=192.168.0.1:/var/www/pub/ftp/bt5 text splash staticip vga=791--


label FORENSICS
  menu label BackTrack ^Forensics - No Drive or Swap Mount
  kernel /bt5/vmlinuz
  append  boot=casper initrd=/bt5/initrd.gz root=/dev/nfs  netboot=nfs nfsroot=192.168.0.1:/var/www/pub/ftp/bt5 text splash vga=791--

label BackTrack noDRM - No NVIDIA drm driver
  menu label BackTrack Text - No ^NVIDIA drm driver
  kernel /bt5/vmlinuz
  append  boot=casper initrd=/bt5/initrd.gz root=/dev/nfs  netboot=nfs nfsroot=192.168.0.1:/var/www/pub/ftp/bt5 text splash nomodeset vga=791--

label debug
  menu label BackTrack ^Debug - Safe Mode
  kernel /bt5/vmlinuz
  append  boot=casper initrd=/bt5/initrd.gz root=/dev/nfs  netboot=nfs nfsroot=192.168.0.1:/var/www/pub/ftp/bt5 text--

label memtest
  menu label BackTrack ^Memtest - Run memtest
  kernel /bt5/memtest
  append -

label hd
  menu label ^Hard Drive Boot - boot the first hard disk
  localboot 0x80
  append -

####################
linux mint
####################

default /mint/vesamenu.c32
#prompt 1
timeout 600


menu background /mint/splash.jpg
menu title linux MINT 13
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


label linux
  menu label ^Start Linux Mint
  kernel /mint/linux
  append boot=casper initrd=/mint/initrd.gz root=/dev/nfs netboot=nfs nfsroot=192.168.0.1:/var/www/pub/ftp/mint
menu default

label memtest
  menu label ^Memory Test
  kernel memtest
label local
  menu label Boot from ^Local drive
  localboot 0x80
label rescue
    menu label ^Rescue mode
    kernel /mint/linux
    append boot=casper initrd=/mint/initrd.gz root=/dev/nfs netboot=nfs nfsroot=192.168.0.1:/var/www/pub/ftp/mint rescue/enable=true vga=788


#################
freebsd
#################

default /freebsd/vesamenu.c32
#prompt 1
timeout 600

display /freebsd/boot.msg

menu background /beauty.png
menu title Free BSD 9.0
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

label freebsd
  menu label FreeBSD 9.0
  kernel /freebsd/memdisk
  append iso raw initrd=/freebsd/bootonly.iso harddisk

label local
  menu label Boot from ^local drive
  localboot 0xffff

注意:
    live CD类型的linux发行版,需要nfs来共享,所以要开启nfs,下面是我个人的nfs配置,仅供参考!

cat /etc/exports

# /etc/exports: the access control list for filesystems which may be exported
       to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/var/www/pub/ftp/mint  192.168.0.0/24(ro,no_root_squash,sync)
/var/www/pub/ftp/bt5  192.168.0.0/24(ro,no_root_squash,sync)
/var/www/pub/ftp/freebsd  192.168.0.0/24(ro,no_root_squash,sync)
/var/lib/tftpboot/freebsd  192.168.0.0/24(ro,no_root_squash,sync)
/var/www/pub/ftp/arch  192.168.0.0/24(ro,no_root_squash,sync)


7.测试
可以从物理机的pxe引导,我这里用kvm来测试

sudo apt-get install virt-manager

NOTE: KVM默认不支持桥接模式,需要手动配置,这就是为什么前面要配置桥接的缘故.若还是不能选桥接则自己指定桥接网卡,我试过,没问题。



Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd
Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

Ubuntu12.04 <wbr>nginx+pxe+tftpd+samba/nfs+dhcpd

posted @ 2013-05-26 21:03  李庆喜  阅读(344)  评论(0编辑  收藏  举报