Heim  >  Artikel  >  Betrieb und Instandhaltung  >  Netzwerkinstallationsmethode für Linux-Systeme basierend auf pxe+dhcp+nfs+tftp+kickstart

Netzwerkinstallationsmethode für Linux-Systeme basierend auf pxe+dhcp+nfs+tftp+kickstart

巴扎黑
巴扎黑Original
2017-06-23 14:35:161916Durchsuche

Originaltext veröffentlicht am: 05.09.2010

Nachdruck zum Datum: 21.07.2012

1. Einführung in das Prinzip

PXE (Preboot-Ausführungsumgebung) funktioniert im Netzwerkmodus von Client/Server, Unterstützung von Workstations durch Das Netzwerk lädt das Image vom Remote-Server herunter und unterstützt so das Booten des Betriebssystems aus dem Netzwerk. Während des Startvorgangs wird dem Terminal vom DHCP-Server eine IP-Adresse zugewiesen und verwendet dann TFTP (triviales Dateiübertragungsprotokoll) und andere Protokolle werden vom Server heruntergeladen (NFS, FTP, HTTP usw. )s Liunx-Kernel und Root-Dateisystem warten, bis sie im lokalen Speicher sind und ausgeführt werden, wodurch sie abgeschlossen werden die grundlegenden Softwareeinstellungen des Terminals, wodurch das im Server vorinstallierte Terminal-Betriebssystem gebootet wird.

Kickstart ist eine unbeaufsichtigte Installationsmethode. Es zeichnet verschiedene Parameter auf, die durch manuelle Eingriffe während eines typischen Installationsprozesses eingegeben werden, und generiert eine ks.cfg-Datei, die während des anschließenden Installationsprozesses ausgefüllt werden muss Wenn Sie die Parameter eingeben, sucht das Installationsprogramm nach der Datei kickstart und es ist kein manueller Eingriff erforderlich, wenn die entsprechenden Parameter gefunden werden können.

2. Umgebungsbeschreibung

Betriebssystem:

CentOS 5.4 i386

weich:

DHCP, NFS, TFTP, Kickstart (Gnome oder x-window)

kann mit yum installiert werden:

yum –y install dhcp*
yum –y install nfs*
yum –y install tftp*
yum –y install system-config-kickstart*

ip:

eth0: 192.168.1.254

3. Einführung in den Installations- und Konfigurationsprozess

1. KonfigurationDHCP

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根目录下的启动引导文件
 
        # we want the nameserver to appear at a fixed address
        host ns {
                hardware ethernet 00:1C:25:80:F4:58; #张江机房的笔记本网卡mac
                fixed-address 192.168.1.2;
        }
}

NeustartdhcpService:

/etc/init.d/dhcpd restart

2. KonfigurationTFTP

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
}

NeustarttftpDienst:

/etc/init.d/xinetd.restart

Überprüfen Sie, ob der tftp-Dienst gestartet ist:

chkconfig –list | grep tftp

3. KonfigurationNFS

NFS muss sich bei RPC registrieren, um vom Client aufgerufen zu werden. Im Allgemeinen ist die Portmap für Die Portzuordnung ist standardmäßig nicht installiert. Wenn ja, können Sie yum zur Installation verwenden:

yum –y install portmap*

 

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

 

mount /dev/cdrom /mnt
mkdir /ios/CentOS_5.4
cp –a /mnt/* /ios/CentOS_5.4

 

#共享tftp的根目录,192.168.1.0/24网段的用户有只读权限
echo "/tftpboot 192.168.1.0/24(ro,sync)" > /etc/exports

#共享存放镜像文件的目录,所有用户有只读权限
echo "/ios/CentOS_5.4 *(ro,sync)" >> /etc/exports

 

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

#重启服务
/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,没有安装使用yumyum –y install syslinux*

# pxelinux.0PXE启动引导文件

 

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

# vmlinuzinitrd.img是不同版本的系统内核和系统引导文件,安装不同版本系统时请使用各版本的vmlinuzinitrd.img

 

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

 

到目前已经可以从网络安装系统了。测试如下:

启动服务器,一般F12进入PXE网络启动,向DHCP请求IPDHCP响应包含IP地址和pxelinux启动程序位置;PXE客户端收到响应后,向服务器请求传送文件(pxelinux.0pxelinux.cfg/defaultvmlinuzinitrd.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

#分区和选包是机房最头疼的事,在这里可以修改
#clearpart --linux --drives=sda
#part /boot --fstype ext3 --size=200
#part pv.2 --size=0 --grow --ondisk=sda
#volgroup VolGroup00 --pesize=32768 pv.2
#logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
#logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=1000 --grow --maxsize=6144
#以上是一个LVM分区的示范

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.msgoptions.msg文件来说明安装什么样的操作系统和怎样安装操作系统。如:

boot.msgInstall 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.msgInstall 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

 

7. 小结

只要注意各操作系统的内核和引导文件的对应关系,就能扩展到多套系统。

kickstart文件能在原来的基础上修改的就在原来的基础上修改,稍加时日,就可以形成针对各业务不同的kickstart文件,这样就方便IDC人员实现Linux操作系统的自动化安装。

Das obige ist der detaillierte Inhalt vonNetzwerkinstallationsmethode für Linux-Systeme basierend auf pxe+dhcp+nfs+tftp+kickstart. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:LAMP=Linux+Apache+Mysql+PhpNächster Artikel:LAMP=Linux+Apache+Mysql+Php