Chinaunix首页 | 论坛 | 博客
  • 博客访问: 350697
  • 博文数量: 34
  • 博客积分: 251
  • 博客等级: 二等列兵
  • 技术积分: 419
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-21 15:50
文章分类

全部博文(34)

文章存档

2017年(5)

2016年(19)

2012年(10)

我的朋友

分类: 系统运维

2012-07-21 17:05:11

原文发表于:2010-09-05

就我来说,linux玩得并不好,只是会一些基础的东西,由于工作中经常要安装多种操作系统,时间长了人也给逼疯了。最终不胜其烦,前段时间做了一套pxe+kickstart,写了个简易的文档。人都是给逼出来的。

一.原理简介

PXE(preboot execute environment)工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载镜像,并由此支持来自网络的操作系统的启动。启动过程中,终端由DHCP服务器分配IP地址,再用TFTP(trivial file transfer protocol)等协议下载存在于服务器(NFS,FTP,HTTP等)的Liunx内核和根文件系统等到本机内存中并执行,由此完成终端基本软件设置,从而引导预先安装在服务器中的终端操作系统。

Kickstart 是一种无人职守安装方式。它通过记录典型的安装过程中所需人工干预填写的各种参数,并生成一个ks.cfg文件;在其后的安装过程中单出现要求填写参数的时候,安装程序会查找kickstart文件,在能找到合适的参数情况下就不需要人工干预。

二.环境说明

os:

CentOS 5.4 i386

soft:

dhcp, nfs, tftp, kickstart(gnome 或者x-window)

可以使用yum安装:

yum –y install dhcp*

yum –y install nfs*

yum –y install tftp*

yum –y install system-config-kickstart*

ip:

eth0: 192.168.1.254

三.安装配置过程简介

1. 配置DHCP

more /etc/dhcpd.conf

# DHCP Server Configuration file.

#    see /usr/share/doc/dhcp*/dhcpd.conf.sample

#

# Location: Zhangjiang IDC

# Date: 2010-08-01

ddns-update-style interim;

ignore client-updates;

allow booting;

allow bootp;

subnet 192.168.1.0 netmask 255.255.255.0 {

option routers                  192.168.1.254;

option subnet-mask              255.255.255.0;

option domain-name-servers      192.168.1.254;

option time-offset              -18000; # Eastern Standard Time

range dynamic-bootp 192.168.1.10 192.168.1.250;

default-lease-time 21600;

max-lease-time 43200;

# Group the PXE bootable hosts

# PXE-server configuration direction

next-server 192.168.1.254;    #指向nfs服务器

filename "/pxelinux.0";       #/tftp根目录下的启动引导文件

}

重启dhcp服务:/etc/init.d/dhcpd restart

2. 配置TFTP

more /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              = -u nobody -s /tftpboot  #-s指定tftp根目录

disable                 = no        #默认yes,关闭

per_source              = 11

cps                     = 100 2

flags                   = IPv4

}


重启tftp服务:/etc/init.d/xinetd.restart

查看tftp服务是否启动:chkconfig –list | grep tftp

3. 配置NFS

NFS需要向RPC注册才能被客户端调用,一般做端口映射的portmap是默认安装的,没有的话可以使用yum安装:yum –y install portmap*

mount /dev/cdrom /mnt

mkdir /ios/CentOS_5.4

cp –a /mnt/* /ios/CentOS_5.4

可以直接使用挂载的镜像,这里是拷到服务器上为了建立一个专门存放常用的镜像文件建的目录。

echo “/tftpboot 192.168.1.0/24(ro,sync)” > /etc/exports

#共享tftp的根目录,192.168.1.0/24网段的用户有只读权限

echo “/ios/CentOS_5.4 *(ro,sync)” >> /etc/exports

#共享存放镜像文件的目录,所有用户有只读权限

exportfs –arv  #不重启nfs服务器情况下配置生效

/etc/init.d/portmap restart

/etc/init.d/nfs resart             #重启服务

查看共享目录是否生效:showmount –e localhost

4. 配置PXE启动需要的文件

cp /usr/lib/syslinux/pxelinux.0 /tftpboot

# pxelinux.0依赖于syslinux,没有安装使用yum:yum –y install syslinux*

# pxelinux.0是PXE启动引导文件

cp /ios/CentOS_5.4/ioslinux/vmlinuz /tftpboot

cp /ios/CentOS_5.4/ioslinux/initrd.img /tftpboot

# vmlinuz和initrd.img是不同版本的系统内核和系统引导文件,安装不同版本系统时

# 请使用各版本的vmlinuz和initrd.img

mkdir /tftpboot/pxelinux.cfg

cp /ios/CentOS_5.4/ioslinux.cfg /tftpboot/pxelinux.cfg/default

到目前已经可以从网络安装系统了。

测试:

启动服务器,一般F12进入PXE网络启动,向DHCP请求IP,DHCP响应包含IP地址和pxelinux启动程序位置;PXE客户端收到响应后,向服务器请求传送文件(pxelinux.0、pxelinux.cfg/default、vmlinuz、initrd.img); 客户端通过pxelinux.cfg/default文件成功的引导Linux安装内核后,安装程序首先必须确定你通过什么安装介质来安装linux,如果是通过网络安装(NFS, FTP, HTTP),则会在这个时候初始化网络,并定位安装源位置。(由于PXE获取的是安装用的内核以及安装程序等,而安装程序要获取的是安装系统所需的二进制包以及配置文件,它们需要的内容不同造成PXE模块和安装程序是相对独立的,PXE的网络配置并不能传递给安装程序,从而进行两次获取IP地址过程)。


5. 配置ks.cfg文件

ks.cfg文件可以由以下方法生成:

1)    每次装好一台CentOS(RedHat),安装程序都会自动创建一个kickstart文件,文件记录了真实的安装配置,位置在/root/anaconda-ks.cfg。可以根据此配置来生成自己需要的ks.cfg文件。

2)    使用图形化的kickstart配置工具,命令:system-config-kickstart

3)    使用文本编辑器编辑。


以下是已经写好的ks.cfg文件,仅供参考:

more /ios/ks.cfg

# Kickstart file automatically generated by anaconda.

install

nfs --server=192.168.1.254 --dir=/ios/CentOS_5.4

#指出NFS的路径和安装文件的位置

lang en_US.UTF-8

keyboard us

network --device eth0 --onboot yes --bootproto dhcp --hostname test

#network --device eth0 --onboot yes –bootproto static --ip 192.168.1.10 --netmask 255.255.255.0 --gateway 192.168.1.1 --nameserver 8.8.8.8 --hostname test

#一个网卡获得地址的方式

network --device eth1 --onboot no --bootproto dhcp --hostname test

rootpw --iscrypted $1$V26J9f5V$A7k9alSJs1GzG.qNBef6f/

#加密root密码

firewall --disabled #--port=22:tcp

authconfig --enableshadow --enablemd5

#使用md5认证

selinux --disabled

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 --linux

part /boot --fstype ext3 --size=100 --ondisk=sda

part swap --size=2048 --ondisk=sda

part / --fstype ext3 --size=100 –grow --ondisk=sda

#分区和选包, 在这里可以修改

reboot          #安装完毕后重启

%packages

@development-libs

@development-tools

@admin-tools

@editors

#选包


将配置好的ks.cfg文件放在共享目录内,这里放到/ios下

echo “/ios 192.168.1.0/24(ro,sync)” >> /etc/exports

exportfs –arv

修改/tftpboot/pxelinux.cfg/default配置:

more /tftpboot/pxelinux.cfg/default

default ks          #默认从标签ks启动

prompt 1          #显示”boot:”提示符

timeout 30         #等待超时时间

display boot.msg   #/tftpboot/boot.msg默认显示boot.msg,可以根据实际情况编辑,

F1 boot.msg

F2 options.msg

F3 general.msg

F4 param.msg

F5 rescue.msg

label linux       #在boot:提示符后输入linux(只是一个标签),从下面指出的内核启动

kernel vmlinuz

append initrd=initrd.img

label text       #在boot:提示符后输入text,这里是文字界面安装

kernel vmlinuz

append initrd=initrd.img text

label ks        #default默认,从ks.cfg读取安装信息,无需人工干预

kernel vmlinuz

append ks=nfs:192.168.1.254:/ios/ks.cfg initrd=initrd.img ksdevice=link

#ksdevice=link,从连接的网卡读取安装文件

label local

localboot 1

label mem

kernel memtest

append -

6. 进阶

由于所在的环境常安装的系统是RHEL4.7, RHEL4.7 x86_64, CentOS5.4, CentOS5.4 x86_64。可以将四种镜像放在专门的目录内 。例如:

RHEL4.7:/ios/rhel4.7

RHEL4.7 x86_64: /ios/rhel4.7-x86_64

CentOS5.4: /ios/centos5.4

CentOS5.4 x86_64: /ios/centos5.4- x86_64

/tftp根目录(这里是/tftpboot下,各版本的内核和引导文件也需要改变位置:

RHEL4.7:/ios/rhel4.7/vmlinuz

/ios/rhel4.7/initrd.img

RHEL4.7 x86_64: /ios/ rhel4.7-x86_64/vmlinuz

/ios/ rhel4.7-x86_64/initrd.img

CentOS5.4: /ios/centos5.4/vmlinuz

/ios/centos5.4/initrd.img

CentOS5.4 x86_64: /ios/centos5.4- x86_64/vmlinuz

/ios/centos5.4- x86_64/ initrd.img

PXE引导文件(这里是/tftpboot/pxelinux.cfg/default)修改:

default 3

prompt 1

timeout 300

display boot.msg

F1 boot.msg

F2 options.msg

F3 general.msg

F4 param.msg

F5 rescue.msg

label 1

kernel rhel4.7/vmlinuz

append initrd=rhel4.7/initrd.img

label 2

kernel rhel4.7-x86_64/vmlinuz

append initrd=rhel4.7-x86_64/initrd.img

label 3

kernel centos5.4/vmlinuz

append initrd=centos5.4/initrd.img

label 4

kernel centos5.4-x86_64/vmlinuz

append initrd=centos5.4-x86_64/initrd.img

label 1-ks_**

kernel rhel4.7/vmlinuz

append ks=nfs:192.168.1.254:/ios/rhel4.7ks_**.cfg initrd=rhel4.7/initrd.img ksdevice=link

label 2-ks_**

kernel rhel4.7-x86_64/vmlinuz

append ks=nfs:192.168.1.254:/ios/rhel4.7-x86_64ks_**.cfg initrd=rhel4.7-x86_64/initrd.img ksdevice=link

label 3-ks_**

kernel centos5.4/vmlinuz

append ks=nfs:192.168.1.254:/ios/centos5.4ks_**.cfg initrd=centos5.4/initrd.img ksdevice=link

label 4-ks_**

kernel centos5.4-x86_64/vmlinuz

append ks=nfs:192.168.1.254:/ios/centos5.4-x86_64ks_**.cfg initrd=centos5.4-x86_64/initrd.img ksdevice=link

label local

localboot 0

label mem

kernel memtest

append –

这里由于选项太多,可以在tftp根目录下启用boot.msg与options.msg文件来说明安装什么样的操作系统和怎样安装操作系统。如:

boot.msg

Install RHEL4.7: 1

Install RHEL4.7 x86_64: 2

Install CentOS5.4: 3

Install CentOS5.4 x86_64: 4

Default: Graph mode.

If you want to use text mode, type: [number] text

F1: boot.msg   F2: options.msg

options.msg

Install RHEL4.7: 1

Install RHEL4.7 x86_64: 2

Install CentOS5.4: 3

Install CentOS5.4 x86_64: 4

Default: Graph mode.

If you want to use text mode, type: [number] text

If you want to use kickstart, the flowing list the different OS ks.cfg:

1-ks_**: RHEL4.7

2-ks_**: RHEL4.7 x86_64

3-ks_**: CentOS5.4

4-ks_**: CentOS5.4 x86_64

F1: boot.msg   F2: options.msg

听说又有一种叫cobbler的装机利器,没试过。这里有一篇介绍cobbler介绍安装的文章:


阅读(2039) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~