Centos5.5下建立无盘系统

 1.          简介

本文介绍通过VMware建立Centos无盘系统的测试过程

基本实现原理:在Image Server上建立dhcp,tftp,nfs服务,然后启动diskless client—>dhcp获得IP—>tftp获取内核文件vmlinuz(可引导的、压缩的内核), initrd.img(用来临时的引导硬件到实际内核vmlinuz能够接管并继续引导的状态)--->通过nfsroot(Mounting the root filesystem via NFS)来挂载根分区到Image Server上实现无盘系统

 

2.          通过Yum 安装dhcp,tftp,nfs ,busybox-anaconda(用于redhat的安装管理程序一个单一的binary,包含大量系统指令,包括shell), system-config-netboot-cmd(用于命令行下建立无盘环境)

l  yum –y install dhcp tftp nfs-utils nfs-utils-lib busybox-anaconda system-config-netboot-cmd

 

3.          修改dhcp配置文件并启动

l  vi /etc/dhcpd.conf

 

allow bootp;

allow booting;

 

ddns-update-style interim;

ignore client-updates;

 

subnet 192.168.159.0 netmask 255.255.255.0 {

range 192.168.159.200 192.168.159.220;

default-lease-time 21600;

max-lease-time 43200;

option routers 192.168.159.2;

option domain-name-servers 192.168.159.2;

option subnet-mask 255.255.255.0;

option domain-name "pwrd.com";

option time-offset -18000;

filename "linux-install/pxelinux.0";  #需要指定pxelinux.0(PXE启动引导文件)的位置,默认在/tftpboot

next-server 192.168.159.120;      #指定tftpIP地址

 

#可以指定diskless clientIP地址

host test4 {

    hardware ethernet 00:0c:29:a3:86:c3;

    fixed-address 192.168.159.130;

  }

}

 

#启动dhcp, 如有报错可以查看/var/log/messages 中的log

l  /etc/init.d/dhcpd start

 

4.          修改tftp配置文件并启动

l  vi /etc/xinetd.d/tftp

 

service tftp

{

        socket_type             = dgram

        protocol                = udp

        wait                    = yes

        user                    = root

        server                  = /usr/sbin/in.tftpd

        server_args             = -s /tftpboot  #指定tftp下载的主目录

        disable                 = no      #yes改为no

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

 

#启动tftp, 如有报错可以查看/var/log/messages 中的log

l  /etc/init.d/xinetd start

 

5.         建立diskless client所需要的root目录,并同步系统文件到diskless root目录中,在根目录下排除不需要的目录即可,比如/proc /sys

l  mkdir -p /diskless/centos/test4/root/

 

#192.168.159.120为本机,image server

l  rsync -v -a -e ssh --exclude='/proc/*' --exclude='/sys/*' --exclude='/mnt/*' 192.168.159.120:/ /diskless/centos/test4/root/

 

 

6.          修改NFS配置文件,指定挂载目录,并启动NFS服务

#snapshot 是为了那些每一个diskless client都需要读写的部分,例如/var/log/messages

l  vi /etc/exports

/diskless/centos/test4/root/             *(rw,sync,no_root_squash,no_all_squash)

/diskless/centos/test4/root/snapshot/     *(rw,sync,no_root_squash,no_all_squash)

 

#启动portmap NFS, 如有报错可以查看/var/log/messages 中的log

/etc/init.d/portmap start

/etc/init.d/nfs start

 

查看rpcinfoexport list

rpcinfo –p

showmount -e 192.168.159.120

 

 

 

7.          命令下设置diskless的引导环境

#The “pxeos” enables you to create a new operating system under /tftpboot and places the vmlinux and initrd images there.

Options for “pxeos”:
-a: Adds new O.S.
-i: Description of O.S.
-p: Protocol to use
-D: If set to 1, then it indicates it’s diskless
-s: NFS server
-L: Location of your O.S., this should contain the vmlinuz and initrd somewhere in it.

#生成NFS引导的内核文件

l  pxeos -a -i centoskernel -p NFS -D 1 -s 192.168.159.120 -L /diskless/centos/test4 centoskernel

 

#查看pxeos是否成功

l  pxeos -l

 

#查看NFS引导的内核文件是否生成

l  ll /tftpboot/linux-install/centoskernel/

 

#查看pxeos生成的配置文件

l  more /tftpboot/linux-install/pxelinux.cfg/pxeos.xml

 

The “pxeboot” command adds clients to the diskless environment and creates the HEX file for the host in the /tftpboot directory 

Options for “pxeboot”:
-a: Adds new host
-O: Name of O.S. (You should have already created this with the system-config-netboot or pxeos)
-r: Size of ram disk
-S: Snapshot name of the diskless client.
-e: The interface through which the pxe boot will take place.
-N: NIS domain
-s: Serial console settings to view remote consoles during boot up

#生成diskless client所需要的启动文件,指定IP192.168.159.130

l  pxeboot -a -O centoskernel -r 28753 -S test4 -e eth0 -s console=ttyS0,115200n8r 192.168.159.130

 

#也可以不用pxeboot命令,而用01+MAC地址作为文件名(注意小写,由于PXE的寻址规律)

l  cat /tftpboot/linux-install/pxelinux.cfg/01-00-0c-29-a3-86-c3

default centoskernel

label centoskernel

    kernel centoskernel/vmlinuz

    append console=ttyS0,9600n8 initrd=centoskernel/initrd.img root=/dev/ram0 init=disklessrc NFSROOT=192.168.159.120:/servers_drbd/centos/coreclient/test4 ramdisk_size=28753 ETHERNET=eth0 SNAPSHOT=test4

 

 

8.         新建一台Vmware,只需分配内存和CPU,作为diskless client

如何获取MAC地址:

diskless client启动时会广播DHCP request, Image Server tail -f /var/log/messages可以看到,根据step 7中的格式写入到/tftpboot/linux-install/pxelinux.cfg,或者写入到step 3中的dhcpd.conf,并分配固定IP地址,然后用step 7中的pxeboot生成启动文件

l  tail -f /var/log/messages

Dec 11 00:50:29 test3 dhcpd: DHCPDISCOVER from 00:0c:29:a3:86:c3 via eth0

Dec 11 00:50:29 test3 dhcpd: DHCPOFFER on 192.168.159.130 to 00:0c:29:a3:86:c3 via eth0

Dec 11 00:50:31 test3 dhcpd: DHCPREQUEST for 192.168.159.130 (192.168.159.120) from 00:0c:29:a3:86:c3 via eth0

Dec 11 00:50:31 test3 dhcpd: DHCPACK on 192.168.159.130 to 00:0c:29:a3:86:c3 via eth0

 

l  ls /tftpboot/linux-install/pxelinux.cfg/01-00-0c-29-a3-86-c3

 

 

9.          启动成功后可以检查diskless clientimage server的同步情况

由于NFS设置成了sync模式,则在diskless client上的任何增删改操作都会实时同步到image servernfs 挂载目录

 

 

 

参考资料:

http://www.linuxquestions.org/questions/red-hat-31/building-a-diskless-redhat-enterprise-linux-cluster-765393/

http://wiki.centos.org/zh/HowTos/DisklessClients

你可能感兴趣的:(linux,nfs,diskless,nfsroot)