自动安装Linux系统之"SystemImager”

 

通常人们在安装Linux操作系统中,常使用是“光盘安装”的传统方式。目前,U盘安装的方法也逐渐盛行。但是,上述的两种方法只适用于单机部署,对于大规模化的安装操作系统,推荐使用网络引导无人值守的自动化安装操作系统的方式。

我曾经在Linux KickStart无人值守安装》一文中介绍了Red Hat公司基于脚本方式安装的KickStart如何自动化部署Red Hat Linux操作系统。使用该方法的优点就是操作系统的软件包只需要一份拷贝;根据不同的组配置,不同的配置文件,当待安装节点通过PXE网络引导后,就可以安装配置文件指定的软件包,从而完成安装工作。

在实际的部署过程中,我们经常会遇到不仅仅需要成功的安装系统,关键是系统上的应用。(例如:高性能集群、计算机实验室、公司桌面环境。)如何快速、简单、高效地完成整个部署值得大家思考。本文将介绍基于镜像方式安装的SystemImager部署Linux操作系统。

一、 SystemImager 简介

SystemImagerSystem Installation Suite的一部份,创始人Brian Elliott Finley。目前的维护者和项目小组的领导者是Andrea Righi。该软件支持所有的GUN/Linux版本,发布软件及快速部署生产环境。其主要特点如下:

SystemImager的一个主要特征是与发行版本无关,并且能支持不同种类的硬件。这一特征可以让我们将任何种类的GNU/Linux(标准的发行版本或者自定义的版本)部署到目标机器。此项目的主要目标是实现轻松,快捷的部署大量的节点。典型的应用环境包括计算机实验室,render farms(注:视觉农场,很多大片在后期制作所使用的图形渲染的工作站,类似于超级计算机),Internet服务器中心,数据库服务器中心,公司桌面环境等。SystemImager已经被证实了在集群计算环境中很流行,如:网格计算和高性能计算。

另一个设计上便于GNU/Linux发行以及不依赖于硬件的特点是SystemImager处理的是基于系统镜像的文件。镜像以文件形式储存目录体系节构,即为样本节点的一个全面的快照,包含节点根文件系统中所有文件及目录。镜像以多种方法获得,包括从目标系统(golden client)中获得,或应用第三方工具直接在镜像服务器中生成。

二、SystemImager工作原理

SystemImager 软件包需要从一台安装好操作系统的节点抓取映像,利用这个映像就可以为多个相同硬件配置的计算机节点安装操作系统。

   三、部署systemp_w_picpathr服务
要部署systemp_w_picpathr服务,一共需要一下几个步骤:
(1)  安装镜像服务器
(2)   安装黄金客户端

(3)  制作黄金客户端镜像

(4)配置systemp_w_picpathr服务

(5)克隆操作系统

1、安装镜像服务器:

首先,到SystemImager官方网站下载安装镜像服务器所需的软件包,官方提供了sis-install脚本,可以快速的下载所需的软件包。当然,也可以到网站上单个的下载。镜像服务器所需的软件包列表如下所示:

 
  
server  
| -- perl-AppConfig-1.52-4.noarch.rpm  
| -- systemconfigurator-2.2.11-1.noarch.rpm  
| -- systemp_w_picpathr-common-4.1.6-1.noarch.rpm  
| -- systemp_w_picpathr-i386boot-standard-4.1.6-1.noarch.rpm  
` -- systemp_w_picpathr-server-4.1.6-1.noarch.rpm  
在安装的过程中,注意软件包的依赖关系,确保以安装perl-XML-Simpleperl-XML-Parser等软件包。执行如下命令开始安装:
 
  
[root@localhost server]# rpm -ivh *.rpm  
error: failed  to  stat /media/RHEL_5.4 i386 DVD:  No  such file  or  directory  
Preparing...                ########################################### [100%]  
   1:perl-AppConfig         ########################################### [ 20%]  
   2:systemconfigurator     ########################################### [ 40%]  
   3:systemp_w_picpathr-common    ########################################### [ 60%]  
   4:systemp_w_picpathr-server    ########################################### [ 80%]  
Stopping xinetd: [  OK  ]  
Starting xinetd: [  OK  ]  
   5:systemp_w_picpathr-i386boot-s########################################### [100%]  
[root@localhost server]# 
2、安装黄金(Golden)客户端:

要创建golden client,你必须安装systemp_w_picpathr-client包。黄金客户端所需的软件包列表如下所示:
 
  
client/  
| -- perl-AppConfig-1.52-4.noarch.rpm  
| -- systemconfigurator-2.2.11-1.noarch.rpm  
| -- systemp_w_picpathr-client-4.1.6-1.noarch.rpm  
| -- systemp_w_picpathr-common-4.1.6-1.noarch.rpm  
` -- systemp_w_picpathr-i386initrd_template-4.1.6-1.noarch.rpm  
    执行rpm –ivh *.rpm完成黄金客户端的安装:
 
  
[root@qiuri client]# rpm -ivh *.rpm  
Preparing...                ########################################### [100%]  
   1:perl-AppConfig         ########################################### [ 20%]  
   2:systemconfigurator     ########################################### [ 40%]  
   3:systemp_w_picpathr-common    ########################################### [ 60%]  
   4:systemp_w_picpathr-client    ########################################### [ 80%]  
   5:systemp_w_picpathr-i386initrd########################################### [100%]  
[root@qiuri client]# 
3、制作黄金客户端镜像

当你安装完毕后,就可以以root身份执行si_prepareclient命令,执行后会在/etc/systemp_w_picpathr目录下生成许多文件,其中包含分区方案,文件系统类型等。同时si_prepareclient也会在黄金客户端上启动一个rsync进程,以便SystemImager服务器可以获取访问它的文件的权限,并通过网络复制文件到镜像服务器中。 
 
   
[root@qiuri ~]# si_prepareclient --server 172.16.0.10  
Welcome  to  the SystemImager si_prepareclient command.  This command may  modify  
the following files  to   prepare  your golden client  for   having  it's p_w_picpath   
retrieved  by  the p_w_picpathserver.  It will also  create  the /etc/systemp_w_picpathr   
directory  and  fill it  with  information about your golden client.   All  modified  
files will be backed up  with  the .before_systemp_w_picpathr-4.1.6 extension.  
   
 /etc/services:  
   This file defines the port numbers used  by  certain software  on  your system.  
   Entries  for  rsync will be added if necessary.  
   
 /tmp/fileO0rkKZ:  
   This  is  a  temporary  configuration file that rsync needs  on  your golden client  
    in   order   to  make your filesystem available  to  your SystemImager server.  
   
 inetd configuration:  
   SystemImager needs  to  run rsync  as  a standalone daemon  on  your golden client  
   until it's p_w_picpath  is  retrieved  by  your SystemImager server.  If rsyncd  is    
   configured  to  run  as  a service started  by  inetd, it will be temporarily  
   disabled,  and   any  running rsync daemons  or  commands will be stopped.   Then ,  
   an rsync daemon will be started using the  temporary  configuration file  
   mentioned above.  
     
See  "si_prepareclient --help"   for  command line options.  
   
Continue ? (y/[n]): y  #输入“y”,继续。  
*********************************** WARNING ***********************************   
This utility starts an rsync daemon that makes  all   of  your files accessible  
by  anyone who can  connect   to  the rsync port  of  this machine.  This  is  the   
case  until you reboot,  or  kill the  'rsync --daemon'  process  by  hand.   By    
default , once you use si_getp_w_picpath  to  retrieve this p_w_picpath  on  your p_w_picpathserver,   
these contents will become accessible  to  anyone who can  connect   to  the rsync   
port  on  your p_w_picpathserver.  See rsyncd.conf(5)  for  details  on  restricting   
access  to  these files  on  the p_w_picpathserver.  See the systemp_w_picpathr-ssh package  
for  a more secure method  of  making p_w_picpaths available  to  clients.  
*********************************** WARNING ***********************************   
   
Continue ? (y/[n]): y  #再次输入"y"。
   
 
-rw-r --r-- 1 root root 1855956 Apr 10 21:31 /etc/systemp_w_picpathr/boot/kernel  
   
Starting  or  re-starting rsync  as  a daemon.....  
done!  
   
This client  is  ready  to  have its p_w_picpath retrieved.  You must now run   
the  "si_getp_w_picpath"  command  on  your p_w_picpathserver.  
   
Your client has been successfully prepared.  Boot kernel (copied  from  
this Linux distribution)  and  an initrd.img (generated  by  the  
initrd_template package) can be found  in  /etc/systemp_w_picpathr/boot.  
   
Automatically  create  configuration file  for  systemconfigurator:  
  >> /etc/systemconfig/systemconfig.conf  
[root@qiuri ~]# 
    我们可以使用ps –ef命令来检查si_prepareclient脚本工作是否正常,可以看到一个正在运行的rsync守护进程(使用/tmp/rsyncd.conf文件作为配置文件)在等待发送文件到网络的请求。
 
    
[root@qiuri ~]# ps -ef |grep rsync   
root      3812     1  0 15:46 ?        00:00:00 rsync  --daemon --port=873 --config=/tmp/filerqgMEG  
root      3846  3539  0 15:47 pts/2    00:00:00 grep rsync 
现在可以在镜像服务器上执行si_getp_w_picpath,将镜像(即:黄金客户端上的内容)从黄金客户端复制到镜像服务器。默认情况下,镜像被存储在SystemImager服务器上的/var/lib/SystemImager/p_w_picpaths目录。

注意:镜像服务器上有足够的磁盘空间用于存储黄金客户端镜像。

基本的语法是:“si_getp_w_picpath -golden-client [client_hostname] -p_w_picpath [p_w_picpath_name]

其中[client_hostname]golden client的主机名或IP地址,[p_w_picpath_name]是你想要给存储镜像的名称。--post-install reboot选项指定克隆一台机器后客户端重新启动计算机,-directory选项可以指定镜像存储的路径。可以用“man si_getp_w_picpath”查看更多其它的选项。
 
   
[root@localhost ~]# si_getp_w_picpath --golden-client 172.16.0.2 -p_w_picpath vfast_backup   
--post-install reboot -directory /systemp_w_picpathr/  
   
This program will get the  "vfast_backup"  system p_w_picpath  from   "172.16.0.2"  
making the assumption that  all  filesystems considered part  
of  the system p_w_picpath are using ext2, ext3, jfs, FAT, reiserfs,  or  xfs.  
   
This program will  not  get /proc, NFS,  or  other filesystems  
not  mentioned above.  
   
*********************************** WARNING ***********************************   
All  files retrieved  from  a golden client are,  by   default , made accessible  to    
anyone who can  connect   to  the rsync port  of  this machine.  See rsyncd.conf(5)  
for  details  on  restricting access  to  these files  on  the p_w_picpathserver.  See the  
systemp_w_picpathr-ssh package  for  a more secure (but less effecient) method  of    
making p_w_picpaths available  to  clients.  
*********************************** WARNING ***********************************   
   
See  "si_getp_w_picpath --help"   for  command line options.  
   
Continue ? ([y]/n):y  #输入"y"继续
黄金客户端开始复制文件到镜像服务器,如下所示:
 
  
usr/share/zoneinfo/right/Navajo => usr/share/zoneinfo/right/US/Mountain  
usr/share/zoneinfo/ right /America/Denver => usr/share/zoneinfo/ right /US/Mountain  
usr/share/zoneinfo/ right /America/Shiprock => usr/share/zoneinfo/ right /US/Mountain  
usr/share/zoneinfo/ right /America/Los_Angeles => usr/share/zoneinfo/ right /US/Pacific  
usr/share/zoneinfo/ right /Pacific/Pago_Pago => usr/share/zoneinfo/ right /US/Samoa  
usr/share/zoneinfo/ right /Pacific/Samoa => usr/share/zoneinfo/ right /US/Samoa  
   
sent 3524467 bytes  received 3232535951 bytes  1941830.43 bytes/sec  
total  size   is  3411616325  speedup  is  1.05  
------------- vfast_backup IMAGE RETRIEVAL FINISHED -------------  
   
Press <Enter>  to   continue ... 

复制完成后,提示按“Enter”键继续,键入“Enter”后,需要让我们选择为克隆客户端选择获取IP地址的方式。有以下三种方式供大家选择:

l  DHCP:服务器安装完成后会使用DHCP获得IP,非静态

l  STATIC:安装过程中使用的IP会成为安装客户端的静态IP

l  REPLICANT:安装后不会配置网络,作为备份或者快速恢复单机的机制

 根据实际情况选择,这里我选择使用DHCP,直接回车即可。

 
   
There are three ways to assign IP addresses to the client systems on an  
ongoing basis:  
   
1) DHCP  
    ----------------------------------------------------------------  
   A DHCP server will assign IP addresses  to  clients installed  with  
   this p_w_picpath.  They may be assigned a different address each  time .  
   If you want  to  use DHCP, but must ensure that your clients  
   receive the same IP address each  time , see  "man si_mkdhcpstatic" .  
   
2)  STATIC  
    ----------------------------------------------------------------  
   The IP address the client uses during autoinstall will be  
   permanently assigned  to  that client.  
   
3) REPLICANT  
    ----------------------------------------------------------------  
   Don 't mess with the network settings in this p_w_picpath.  I' m using  
   it  as  a backup  and  quick restore mechanism  for  a single machine.  
   
Which method do you prefer? [1]:    #直接回车
You have chosen method 1  for  assigning IP addresses. 
接下来,让我们确认配置以及马上配置si_clusterconfig命令,直接回车即可。到此,整个黄金客户端镜像制作完成。可以到存储镜像的目录查看创建好的镜像。
 
   
Are you satisfied? ([y]/n):   
Would you  like   to  run the  "si_clusterconfig"  utility now? (y/[n]): 
文章上半部分完成,查看整篇文章请看<<自动化安装Linux系统之“SystemImager”(下)>>