Pxe+Kickstart

实现无人值守批量网络安装操作系统

wKiom1NVMWfByM_yAAG9MWMg1-k967.png

说明:

当批量给主机安装操作系统时,我们不可能用传统的方式——用光盘、U盘等,一台一台逐个安装,这样一来,费时又力,对于批量部署主机时,效率是极低的。所以,我们通过

Pxe+Kickstart技术来实现企业中集群服务的批量安装,近而将网络技术人员从繁忙中解脱出来,之后你就可以去悠闲地去饮一杯coffee了,过半个多小时回来,这批服务器都乘乘地

拥有了自己的操作系统。下面是详细配置过程:

实验环境准备

VmwareworkStation虚拟机

一台装有Linux操作系统的虚拟机,这里命名它为PXE-Server(静态IP192.168.1.254

新建2台虚拟裸机(待安装的所有裸机网卡都配置成vmnet1

实验过程概述

PXE-Server上安装dhcpd tftp nfshttpd三个服务

将相关内核和启动引导文件initrd.img  pxelinux.0  pxelinux.cfg  vmlinuz放到tftp根目录/tftpboot

步骤:

1.配置yum

[root@localhost ~]# cd /etc/yum.repos.d

[root@localhost yum.repos.d]# cp rhel-debuginfo.repo yang.repo

            [root@localhost yum.repos.d]#vim  yang.repo

            [rhel-server]    //[ ]里要以rhel- 开头,制作kickstart文件选择安装包时要用到

name=Red Hat Enterprise Linux Server

baseurl=file:///misc/cd/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

测试yum库安装情况

[root@localhost ~]#yum  list

Loaded plugins: product-id, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Installed Packages

Deployment_Guide-en-US.noarch              5.8-1.el5                 installed  

Deployment_Guide-zh-CN.noarch              5.8-1.el5                 installed  

Deployment_Guide-zh-TW.noarch              5.8-1.el5                 installed  

GConf2.i386                                2.14.0-9.el5              installed  

.

.

出现上边的界面表示yum库安装成功!

2.安装并配置DHCP服务

[root@localhost ~]# yum -y install dhcp*     //安装

            [root@localhost ~]# vim /etc/dhcpd.conf     //配置

ddns-update-style interim;

next-server 192.168.1.254;     //

filename "pxelinux.0";

subnet 192.168.1.0 netmask 255.255.255.0 {

option subnet-mask              255.255.255.0;

option domain-name              "tarena.com";

option domain-name-servers      192.168.1.254;

range dynamic-bootp 192.168.1.1 192.168.1.10;

default-lease-time 21600;

max-lease-time 43200;

}

3.安装NFS共享服务

[root@localhost ~]# yum -y install nfs-utils portmap  //安装软件包nfs-utils-        1.0.9-66.el5   portmap-4.0-65.2.2.1
      [root@localhost ~]# vim /etc/exports  // 修改主配置文件
        /data/iso/rhel5.9     *(ro)     

[root@localhost ~]# mkdir -p  /data/iso/rhel5.9  //创建系统镜像存放目录

[root@localhost ~]# cp -rf  /misc/cd/*   /data/iso/rhel5.9   //拷贝光盘所有

也可以用挂载的方法,同样实现访问镜像文件的作用

[root@localhost ~]# umount -a

[root@localhost ~]# mount  /misc/cd     /data/iso/rhel5.9  

3.安装并配置TFTP服务

[root@localhost ~]# yum -yinstall  tftp

[root@localhost ~]#service  xinetd  restart  //开启tftp临时服务

[root@localhost ~]# cd /misc/cd/p_w_picpaths/pxeboot   //进入光盘目录

[root@localhost pxeboot]# ls

initrd.img  README  TRANS.TBL  vmlinuz

[root@localhost pxeboot]# cp initrd.img vmlinuz /tftpboot

            [root@localhost ~]#vim  /etc/xinetd.d/tftp  //配置tftp临时服务文件

 

wKiom1NVL-vSkVRFAACxzoabQzU394.jpg

[root@localhost ~]# find / -name pxelinux.0  //查找pxelinux.0文件存位置

/tftpboot/linux-install/pxelinux.0

/usr/share/syslinux/pxelinux.0

[root@localhost ~]# cp /tftpboot/linux-install/pxelinux.0 /tftpboot   //将这个文件拷贝到/tftpboot

若没找到/pxelinux.0这个文件,则安装一个包:

[root@localhost ~]# yum –y install syslinux-tftpboot.x86_64

安装完后到这个位置去找/usr/share/syslinux/pxelinux.0

[root@localhost ~]# cp -rf /tftpboot/linux-install/pxelinux.cfg/  /tftpboot  //pxelinux.cfg拷贝到/tftpboot

若找不到则创建这目录

[root@localhost pxeboot]# mkdir /tftpboot/pxelinux.cfg 

然后

[root@localhost pxeboot]# cp /misc/cd/isolinux/isolinux.cfg  \

> /tftpboot/pxelinux.cfg/default    //拷贝模板到default

[root@localhost ~]# cd /tftpboot/

[root@localhost tftpboot]# ls

initrd.img  linux-install  pxelinux.0  pxelinux.cfg  vmlinuz

至此/tftpboot下的initrd.img  pxelinux.0 pxelinux.cfg  vmliuz全部准备好了

4.生成Kickstart无人值守配置文件

[root@localhost ~]# yum -y install system-config-kickstart //安装生成Kickstart的工具

wKioL1NVOinz9vKcAAKh58ZENrg757.jpg

wKiom1NVPO7TyiTHAAGUr_0Jlg0005.png

wKioL1NVOiniF27MAAHNwtSLV1w839.jpg

wKiom1NVOlLBhQiMAAIhEPK7P34691.jpg

wKioL1NVOinjvFXoAAFh39Cl9sQ785.jpg

wKiom1NVOlPx4AchAAGv6NQESSk114.jpg

wKioL1NVOinzDN4tAAG1ZVB1TO4797.jpg

wKiom1NVOlPyN6yoAAHK4YXuAVk887.jpg

wKioL1NVOirzLqJFAAHxVLec17g380.jpg

wKiom1NVOlOCXuCPAAIVL-mrs2M325.jpg

之后,点击文件保存到一个目录下就OK了

5.安装httpd服务

[root@localhost ~]# yum -y install httpd

[root@localhost ~]# cp /root/ks.cfg /var/www/html/   //ks.cfg是步骤4生成的配置文件 ,/var/www/html/ —— httpd默认站点

[root@localhost ~]# service httpd restart

[root@localhost ~]# chkconfig httpd on

[root@localhost ~]# vim /var/www/html/ks.cfg

在文件中添加key  --skip  //任意位置

最后vim  /tftpboot/pxelinux.cfg/default

 

wKiom1NVMCqDVYGfAADvZ_QTChk649.jpg

6.测试

将两台虚拟裸机开机(此后不应有交互的操作,静等安装)

未完待续……