PXE安装linux系统

          PXE称为网络批量部署安装,且可支持多版本选择安装,方便快捷
          以下以centos5.7_x64安装为例子
挂载光盘
mount /dev/cdrom /mnt
一、安装dhcp为其它计算机需要安装操作系统分配IP要求可以正常分配ip并且指定TFTP服务器
    安装tftp为了通过网络传输启动文件,存放系统安装所需要的引导文件pxelinux.0文件、启动菜单、内核vmlinuz及initrd.img、ks无人值守配置文件
    安装system-config-kickstart配置无人职守安装,安装nginx作为镜像传输文件服务。
    安装nginx作为网络传输服务
yum -y install dhcp tftp* system-config-kickstart
ifconfig eth1:1 10.0.51.1 netmask 255.255.0.0
二、修改配置DHCP配置文件
vim /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;

subnet 10.0.0.0 netmask 255.255.0.0 {

# --- default gateway
             option routers                                    10.0.0.1;
             option subnet-mask                            255.255.0.0;
filename "/pxelinux.0";
#pxelinux.0启动引导文件存放路径
next-server 10.0.51.1;
#TFTP服务器ip地址,所以dhcpd与TFTP服务器不一定在一个机器上
#             option nis-domain                             "domain.org";
#             option domain-name                            "domain.org";
             option domain-name-servers            202.101.172.35,202.101.172.47;

             option time-offset                            -18000; # Eastern Standard Time
             option ntp-servers                            10.0.1.91;
#             option netbios-name-servers         192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#             option netbios-node-type 2;

                range dynamic-bootp 10.0.51.100 10.0.51.254;
                default-lease-time 21600;
                max-lease-time 43200;

                # we want the nameserver to appear at a fixed address
#             host ns {
#                             next-server marvin.redhat.com;
#                             hardware ethernet 12:34:56:78:AB:CD;
#                             fixed-address 207.175.42.254;
#             }
}
启动DHCP:
service dhcpd start
设置开机启动:
chkconfig --level 35 dhcpd on
三、配置TFTP:    vim /etc/xinet.d/tftp将disable = yes 改为no 需要启动tftp服务
vim /etc/xinetd.d/tftp    
# 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
{
                socket_type                         = dgram
                protocol                                = udp
                wait                                        = yes
                user                                        = root
                server                                    = /usr/sbin/in.tftpd
                server_args                         = -s /tftpboot
                disable                                 = no
                per_source                            = 11
                cps                                         = 100 2
                flags                                     = IPv4
}
启动tftp
service xinetd restart
四、安装nginx服务
mkdir /data
yum -y install gcc gcc + gcc - c ++ openssl openssl - devel
cd /usr/local/src
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-7.9.tar.gz
tar zxvf pcre-7.9.tar.gz
cd pcre-7.9/
./configure
make && make install
cd ../
wget http://sysoev.ru/nginx/nginx-0.8.15.tar.gz
tar zxvf nginx-0.8.15.tar.gz
cd nginx-0.8.15/
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../
修改nginx配置文件
vim /usr/local/nginx/conf/nginx 添加以下内容
        server {
                listen             8020;
                server_name    localhost;
                location / {
                        root     /data0;        
                        autoindex on;     #开启目录浏览    
                }
        }
/usr/local/nginx/sbin/nginx -t 验证配置文件问题
/usr/local/nginx/sbin/nginx 启动Nignx
五、为tftp准备PXE所需文件
将光盘数据拷贝到nginx访问的路径下
mkdir -p /data0/iso57
cp -rp /mnt/* /data0/iso57
拷贝启动引导文件:
cp    /usr/lib/syslinux/pxelinux.0    /tftpboot
复制linux的启动文件内核文件:
cp /mnt/isolinux/vmlinuz /tftpboot/vmlinuz_centos57_x64
cp /mnt/isolinux/initrd.img /tftpboot/initrd_centos57_x64.img
复制启动菜单选项
cp /usr/lib/syslinux/menu.c32 /tftpboot/
启动菜单配置文件:
mkdir /tftpboot/pxelinux.cfg
vim /tftpboot/pxelinux.cfg/default
default menu.c32
prompt 0
timeout 0
ONTIMEOUT local

MENU TITLE Linux System Install Menu

label local
                MENU LABEL ^1.Boot local hard drive
                LOCALBOOT 0
label centos
                MENU LABEL ^3.Linux CentOS 5.7_x64
                kernel vmlinuz_centos57_x64
                append ks=http://10.0.51.1:8020/iso57/ks.cfg initrd=initrd_centos57_x64.img text ksdevice=eth0
cd /data0/iso57
创建ks.cfg文件也就是自动应答脚本
vim ks.cfg
# Kickstart file automatically generated by anaconda.

install
url --url http://10.0.51.1:8020/iso57
lang en_US.UTF-8
keyboard us
#network --device eth0 --bootproto dhcp
network --device eth0 --bootproto static --ip 10.0.5.7 --netmask 255.255.0.0 --gateway 10.0.0.1 --nameserver 202.101.172.35 --hostna
me PXEheihei
rootpw --iscrypted $1$MtnXjRkF$TcE9rokYMeCvtk/2YOlq70
firewall --disable
authconfig --enableshadow --enablemd5
selinux --disable
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda
# 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 --all --initlabel
part /boot --fstype ext3 --size=100
part swap --size=8192
part / --fstype ext3 --size=100 --grow --asprimary
reboot
%packages
@base
@core
@development-libs
@development-tools
@dialup
@editors
@text-internet
keyutils
iscsi-initiator-utils
trousers
fipscheck
device-mapper-multipath
imake
完成安装
service dhcpd restart
service xinetd restart
准备客户端引导就可以自动安装系统了- -

你可能感兴趣的:(linux,安装)