部署一台服务器需要很长时间,安装人工来安装的话,需要安装源,需要配置很多配置,这样的话是非常耗费时间的并且容易出错,因此需要比较智能化的解决方案:而这样方式已经非常成熟了,本文主要介绍PXE(引导)+kickstart(自动配置系统)+DHCP(客户端获取IP)+TFTP(传输Linux启动所需要的文件)+HTTP(提供安装源)这样方案来完成系统的部署。

一:相关概念

二:实例

*****************************************************************************************


一:相关概念和安装过程

   PXE是一种引导方式 preboot excution environment client网卡要支持网络引导

   DHCP是一种动态地址获取协议

   TFTP适合于传输小文件,简单文件传输协议,高效传输小文件

   HTTP文件传输,本例中用于完成提供安装源

   xinted超级守护进程


安装过程,主要有以下几步;

1、pxe启动,会去寻找dhcp服务器获取ip地址pxelinux.0文件

2、client通过tftp连接到服务器,下载pxelinux.0文件。

3、client下载成功pxelinux.0文件后,系统还会下载控制pxelinux.0的配置文件,叫default。然后client就会按照default的配置来执行pxelinux.0文件。

4、现在client端会在获取一次IP地址。并且根据DHCP服务器配置文件找到kickstart配置

文件并下载。

5、pxelinux.0文件定义的想服务器请求linux内核,根文件系统之类的参数。运行这个文件,client就会向服务器请求相关的文件并下载。

6、文件下载成功后,client就会启动linux内核,这就进入了我们安装时候看见的第一个图形界面,这个界面和自己安装看见的第一个画面一样,回车就是图形安装,输入text就是文本安装那里。如果使用了kickstart,这个界面消失很快,可能看不见。到这里PXE启动就完成了。

7、当按照default要求运行pxelinux.0文件,系统读取内核,挂在根文件系统以后的任务就都交给了kickstart了。包括安装介质来源、语言、时区、分区、安装哪些包等,都是在kickstart文件中定义。只要进入这一步,kickstart配置文件正确,我们的无人值守安装已经成功了




二:实例

配置步骤: 前提:

mkdir /mnt/cdrom

mount -r /dev/cdrom /mnt/cdrom


1、配置DHCP服务器

yum -y install dhcp

vim /etc/dhcp/dhcpd.conf

 service dhcpd restart

tail -f /var/log/boot.log

subnet 192.168.2.0 netmask 255.255.255.0 {
  range 192.168.2.20 192.168.2.30;
  default-lease-time 6000;
  max-lease-time 72000;
  next-server 192.168.2.21;
  filename "/pxelinux.0";
}


2、配置tftp-server

yum -y install xinetd tftp-server tftp

chkconfig xinetd on                        

chkconfig tftp on # service xinetd start                                              

ss -unl | grep ":69"      

[root@station133 ~]# ss -unl |grep ":69"
UNCONN     0      0                         *:695                      *:*
UNCONN     0      0                         *:69                       *:*
UNCONN     0      0                        :::695                     :::*



3、准备安装树

mkdir /var/www/html/centos6                                                

mount --bind /mnt/cdrom /var/www/html/centos6

service httpd start  


[root@station133 ~]# ll /var/www/html/
total 12
-rw------- 1 root root 2851 Mar  9 14:18 anaconda-ks.cfg
dr-xr-xr-x 7 root root 4096 Nov 29 20:09 centos6
-rw-r--r-- 1 root root 2822 Mar  9 14:19 ks.cfg


 4、准备tftpboot下的文件      

 yum -y install syslinux

 cp /mnt/cdrom/p_w_picpaths/pxeboot/{vmlinuz,initrd.img}  /var/lib/tftpboot/

 cp /mnt/cdrom/isolinux/{boot.msg,vesamenu.c32,splash.jpg}  /var/lib/tftpboot/

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

 mkdir /var/lib/tftpboot/pxelinux.cfg

 cp /mnt/cdrom/isolinux/isolinux.cfg  /var/lib/tftpboot/pxelinux.cfg/default


[root@station133 ~]# ll /var/lib/tftpboot/
total 348
-r--r--r-- 1 root root     84 Mar  9 14:16 boot.msg
dr-xr-xr-x 2 root root   4096 Mar  9 14:15 pxeboot
-rw-r--r-- 1 root root  26828 Mar  9 14:17 pxelinux.0
drwxr-xr-x 2 root root   4096 Mar  9 14:21 pxelinux.cfg
-r--r--r-- 1 root root 151230 Mar  9 14:16 splash.jpg
-r--r--r-- 1 root root 162860 Mar  9 14:16 vesamenu.c32




5、提供kickstart文件

注意:url及repo后的路径要修改为可用安装树的路径; 编辑好kickstart文件后保存至/var/www/html目录下;这里假设为ks.cfg


[root@station133 ~]# ll /var/www/html/
total 12
-rw------- 1 root root 2851 Mar  9 14:18 anaconda-ks.cfg
dr-xr-xr-x 7 root root 4096 Nov 29 20:09 centos6
-rw-r--r-- 1 root root 2822 Mar  9 14:19 ks.cfg

6、配置引导程序能自动加载此kickstart文件

编辑/var/lib/tftpboot/pxelinux.cfg/default 在label为linux项的append一行后附加:

ks=http://192.168.2.21/ks.cfg

label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.2.21/ks.cfg
label vesa
  menu label Install system with ^basic video driver


[root@station133 ~]# cd /mnt/cdrom/
[root@station133 cdrom]# ls
CentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6
EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6
EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6
GPL              repodata                  TRANS.TBL
p_w_picpaths           RPM-GPG-KEY-CentOS-6
[root@station133 cdrom]# service httpd start
Starting httpd:                                            [  OK  ]
[root@station133 cdrom]# yum install -y syslinux
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.btte.net
 * updates: mirrors.btte.net
Setting up Install Process
Package syslinux-4.02-8.el6.x86_64 already installed and latest version
Nothing to do
[root@station133 cdrom]# ls /mnt/cdrom/p_w_picpaths/pxeboot/
initrd.img  TRANS.TBL  vmlinuz
[root@station133 cdrom]# cp /mnt/cdrom/p_w_picpaths/pxeboot/ /var/lib/tftpboot/
cp: omitting directory `/mnt/cdrom/p_w_picpaths/pxeboot/'
[root@station133 cdrom]# cp -r /mnt/cdrom/p_w_picpaths/pxeboot/ /var/lib/tftpboot/
[root@station133 cdrom]# ls /mnt/cdrom/isolinux/
boot.cat  grub.conf   isolinux.bin  memtest     TRANS.TBL     vmlinuz
boot.msg  initrd.img  isolinux.cfg  splash.jpg  vesamenu.c32
[root@station133 cdrom]# ls /mnt/cdrom/isolinux/
boot.cat  grub.conf   isolinux.bin  memtest     TRANS.TBL     vmlinuz
boot.msg  initrd.img  isolinux.cfg  splash.jpg  vesamenu.c32
[root@station133 cdrom]# cp /mnt/cdrom/isolinux/{boot.msg,vesamenu.c32,splash.jpg} /var/lib/tftpboot/
[root@station133 cdrom]#
[root@station133 cdrom]#
[root@station133 cdrom]# cp /usr/share/syslinux/pxe
pxechain.com  pxelinux.0
[root@station133 cdrom]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@station133 cdrom]# mkdir /var/lib/tftpboot/pxelinux.0
CentOS_BuildTag                RELEASE-NOTES-en-US.html
.discinfo                      repodata/
EFI/                           RPM-GPG-KEY-CentOS-6
EULA                           RPM-GPG-KEY-CentOS-Debug-6
GPL                            RPM-GPG-KEY-CentOS-Security-6
p_w_picpaths/                        RPM-GPG-KEY-CentOS-Testing-6
isolinux/                      TRANS.TBL
Packages/                      .treeinfo
[root@station133 cdrom]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@station133 cdrom]# cp /mnt/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@station133 cdrom]# cp /root/anaconda-ks.cfg /var/www/html/
[root@station133 cdrom]# vi /var/www/html/ks.cfg
[root@station133 cdrom]# cp /root/anaconda-ks.cfg /var/www/html/
cp: overwrite `/var/www/html/anaconda-ks.cfg'? ^C
[root@station133 cdrom]# cp /root/anaconda-ks.cfg /var/www/html/ks.cfg
[root@station133 cdrom]# vi /var/www/html/ks.cfg
[root@station133 cdrom]# vi /var/lib/tftpboot/pxelinux.cfg/default
[root@station133 cdrom]# ss -unl |grep ":69"
UNCONN     0      0                         *:695                      *:*
UNCONN     0      0                        :::695                     :::*
[root@station133 cdrom]# service xinetd on
Usage: /etc/init.d/xinetd {start|stop|status|restart|condrestart|reload}
[root@station133 cdrom]# service tftp on
tftp: unrecognized service
[root@station133 cdrom]# yum install splash.jpg^C
[root@station133 cdrom]# yum -y install xinetd tftp-server tftp
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.btte.net
 * updates: mirrors.btte.net
Setting up Install Process
Package 2:xinetd-2.3.14-39.el6_4.x86_64 already installed and latest version
Package tftp-server-0.49-7.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package tftp.x86_64 0:0.49-7.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================
 Package            Arch                 Version                  Repository          Size
===========================================================================================
Installing:
 tftp               x86_64               0.49-7.el6               base                32 k
Transaction Summary
===========================================================================================
Install       1 Package(s)
Total download size: 32 k
Installed size: 45 k
Downloading Packages:
tftp-0.49-7.el6.x86_64.rpm                                          |  32 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : tftp-0.49-7.el6.x86_64                                                  1/1
  Verifying  : tftp-0.49-7.el6.x86_64                                                  1/1
Installed:
  tftp.x86_64 0:0.49-7.el6                                                         
Complete!
[root@station133 cdrom]# service tftp on
tftp: unrecognized service
[root@station133 cdrom]# service tftpd on
tftpd: unrecognized service
[root@station133 cdrom]# service tftpd on^C
[root@station133 cdrom]# service tftp on
tftp: unrecognized service
[root@station133 cdrom]# service xinetd on
Usage: /etc/init.d/xinetd {start|stop|status|restart|condrestart|reload}
[root@station133 cdrom]# service xinetd start
Starting xinetd:
[root@station133 cdrom]# ss -unl |grep ":69"
UNCONN     0      0                         *:695                      *:*
UNCONN     0      0                        :::695                     :::*
[root@station133 cdrom]# service dhcpd start
[root@station133 cdrom]# ss -unl |grep ":69"
UNCONN     0      0                         *:695                      *:*
UNCONN     0      0                        :::695                     :::*
[root@station133 cdrom]# service dhcpd restart
Shutting down dhcpd:                                       [  OK  ]
Starting dhcpd:                                            [  OK  ]
[root@station133 cdrom]# ss -unl |grep ":69"
UNCONN     0      0                         *:695                      *:*
UNCONN     0      0                        :::695                     :::*
[root@station133 cdrom]# service tftpd start
tftpd: unrecognized service
[root@station133 cdrom]# yum -y install xinetd tftp-server tftp
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.btte.net
 * updates: mirrors.btte.net
Setting up Install Process
Package 2:xinetd-2.3.14-39.el6_4.x86_64 already installed and latest version
Package tftp-server-0.49-7.el6.x86_64 already installed and latest version
Package tftp-0.49-7.el6.x86_64 already installed and latest version
Nothing to do
[root@station133 cdrom]# chkconfig xinetd on
[root@station133 cdrom]# chkconfig tftp on
[root@station133 cdrom]# service xinetd start
Starting xinetd:
[root@station133 cdrom]# ss -unl |grep ":69"
UNCONN     0      0                         *:695                      *:*
UNCONN     0      0                         *:69                       *:*
UNCONN     0      0                        :::695                     :::*

wKioL1McSHOSmtJqAANf6VtkYjA273.jpg