PXE mounting system unattended batch

First, generalization

  It may not necessarily be from the hard disk, floppy disk or CD-ROM drive, but solely to direct a computer through a network by network approach guidance system. This is very convenient for installation, because it means that you can sit at the table, the machine does not have to go there insert the CD-ROM or floppy disk, you can boot a machine located elsewhere on the network.

  PXE's role : as a small operating system in ROM on the network card, which is a standard API through their own network boot feature to the system's BIOS, you can start linux through the network;

  PXE network boot process: a host broadcasts a set DHCP PXE option "find" request, then a DHCP server with a PXE option DHCP packet contains responds to it (the name of the boot server IP address and the boot file) . The client download it via TFTP boot files and perform the boot files.

  Tools for automatic mounting is called kickstart, kickstart profile generated by the ks.cfg system-config-kickstart tool.

Second, the realization of ideas

  After the original (official) mirrored the installation is complete, the system will make system backup gho image file. Gho through the network system backup image using the Mac address of the NIC are assigned ip address, and then distributed.

Third, prepare the environment

  Two virtual machines: a test environment: (CentOS, 192.168.144.133 ), is additionally installed as a CentOS end installed network boot provided

Fourth, the installation ready

① build yum CD source

  Yum to install with the required installation package

(1) [root @ test1 ~  ] # mount / dev / cdrom / mnt # to check the root directory mnt directory

  

(2) Create a file ending in /etc/yum.repos.d directory .repo

   [Root @ test1 ~] # we /etc/yum.repos.d/server.repo 

   Configuration reads as follows:

    

[Base] 
the Name = Base 
baseurl = file: /// mnt / # (parts of the system may require the use of file: /// path mnt / server of) 
Enabled =. 1 
gpgcheck = 0   

(3) After the backup, delete other files under /etc/yum.repos.d/: rm -rf C *

  

(4) Installation ftp service and open service, is set to boot automatically.

  (Yum install vsftpd tftp-server dhcp tftp -y) This command can be a one-time installation services, recommendations, step by step!

     [root @ test1 ~] # yum install vsftpd -y ( appears complete installation instructions )

   If the " : failure: Packages Standard Package / vsftpd-2.2.2-11.el6_4.1.x86_64.rpm from Base: vsftpd-2.2.2-11.el6_4.1.x86_64 [Errno 256] No More Mirrors to the try. " case, check whether the disc is hanging on to the / mnt. If you have still hanging in the still prompt the error, execute the command "yum Clean All" command.  

  [root@test1 ~]# /etc/init.d/vsftpd start  service vsftpd start

  [root@test1 ~]# chkconfig vsftpd on 

(5)安装 TFTP,修改 tftp 配置文件及开启服务  

    [root@test1 ~]# yum install tftp  –y

    [root@test1 ~]# yum install tftp-server  –y     

    [root@test1 ~]vim /etc/xinetd.d/tftp,修改第13,14行配置

      

(6)重新启动 xinetd 服务,然后查看服务端口是否打开。  

    [root@test1 ~]# /etc/init.d/xinetd restart 或者service xinetd restart

    

    OK,TFTP 服务正常启动。Xinetd 服务本来就是开机启动的,所以这里我们不再需要设置。 

    (注:xinetd是新一代的网络守护进程服务程序,又叫超级Internet服务器,常用来管理多种轻量级Internet服务)

(7)安装 dhcp,修改配置文件及开启服务

    [root@test1 ~]# yum install dhcp  –y 

    [root@test1 ~]# vim /etc/dhcp/dhcpd.conf ( 9,10 行是网络引导需要的配置,必须要有的。

     

ddns-update-style interim;
ignore client-updates; 
# 注意网段需要相同。否则无法使用 
subnet 192.168.144.0 netmask 255.255.255.0 {     
  # 与服务器IP地址相同
   option routers 192.168.144.133; 
  # IP默认租约时间
default-lease-time 21600;  
  #IP最大租约时间
max-lease-time 43200;
#IP租约地址池,这里要注意网段一定相同,否则起不来DHCP服务
range 192.168.144.10  192.168.144.100;   
option subnet-mask 255.255.255.0;
next-server 192.168.144.133;  # 与服务器IP地址相同
filename "pxelinux.0"; 
} 

  [root@test1 ~]# /etc/init.d/dhcpd start 或者service dhcpd start    # 启动 DHCP

  [root@test1 ~]# chkconfig dhcpd on   #设置开机自启

  

  # 可能会存在启动失败的情况!! 

  如果是虚拟机,请查看配置信息是否与当前网段匹配。

  如果启动DHCP服务的时候提示“Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file”

   修改 /etc/rc.d/init.d/dhcpd 文件,将其中的

   user=dhcpd

   group=dhcpd

   改为:

   user=root

   group=root

  至此我们的准备工作完成,下面开始kickstart配置。

五、kickstart配置

   如果找不到 syslinux 目录,需要安装包 yum  install  system-config-kickstart.noarch  –y

  ①执行如下命令:

    [root@test1 ~]# mkdir /tftpboot

    [root@test1 ~]# mkdir /tftpboot/pxelinux.cfg

    [root@test1 ~]# cp /usr/share/syslinux/pxelinux.0 /tftpboot/

    [root@test1 ~]# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default

    [root@test1 ~]# cp /mnt/images/pxeboot/initrd.img /tftpboot/

    [root@test1 ~]# cp /mnt/images/pxeboot/vmlinuz /tftpboot/

    [root@test1 ~]# chmod 644 /tftpboot/pxelinux.cfg/default

    然后修改  /tftpboot/pxelinux.cfg/default 的配置文件。 

    vim /tftpboot/pxelinux.cfg/default   

    (文件里面需要修改两行,修改第 1 行,后面的 linux 意思是寻找下面 18 行的 label linux,然后修改下 22 行(即在后面添加 ks=ftp://”pxe-server-ip”/ks.cfg)。第 22 行的意思是使安装程序通过 FTP 服务器访问 kickstart 文件。)

    其中第 1 行:default linux 表示指定默认入口名称;第 2 行:prompt 1 prompt 用来设置是否等待用户选择,1 表示等待用户控制;第 18、23、27、31 label linux 表示定义的引导入口,表示系统的不同安装方式,如第 18 行定义的入口表示图形安装。 

       

    配置文件修改完了,要开始自动安装,安装程序必须能访问 kickstart 文件。有多种方法可访问 kickstart 文件,其中最常用的一种方法是通过网络服务器进行,例如:ftp 服务器、WEB 服务器或 NFS 服务器,这种方法非常易于部署,并且也使管理更改变得十分简单。也可以通过 USB 磁盘、CD-ROM 或本地硬盘。如果 USB CD-ROM 中的 kickstart 文件非常便于访问,只需将 kickstart 文件放置在用来开始安装的引导介质中。而使用 DHCP 服务器和 TFTP PXE 配置起来更为复杂。 

使安装程序指向 kickstart 文件的书写格式如下: 

ks=ftp://server/dir/file  如:ks=ftp://ftp 服务器 IP/ks.cfg ks=http://server/dir/file 如:ks=http://http 服务器 IP/ks.cfg ks=nfs:server:/dir/file   如:ks=nfs:nfs 服务器 IP:/var/ftp/pub/ks.cfg ks=hd:device:/dir/file   如:ks=hd:sdb1:/kickstar-files/ks.cfg ks=cdrom:/dir/file      如:ks=cdrom:/kickstart-files/ks.cfg

以上有关 default 配置文件的修改就是通过 ftp 服务器方式来访问 kickstart 文件。

六、制作kickstart无人值守软件

  ①打开终端输入 system-config-kickstart 弹出来界面。 (需要在服务器中打开。)

    我们设置下默认安装的语言,时区,根口令,然后勾选下面的安装后重新引导。然后选择安装方法。 (服务器ip)

     

    我们配置 ftp 服务器的安装方法。选择执行新安装。然后点击引导装载程序选项 

    

    GRUB 选项如果无特殊需求,可以不勾选。 

    

    

    到这一步,布局这里,我们自己设置下分区大小。 

    分区大小需要自己根据情况而定。 

    比如我的虚拟机配置较低就要用下面的分区: 

    /boot 分区  文件系统类型:ext4   使用硬盘空间大小:200MB

    /swap 分区                      使用硬盘空间大小::2048MG(内存小于 8G 的需设置成内存的两倍,16G以后的内存最好保持物理内存的8G或者相同物理内存的大小,这里实验虚拟机只有1G内存,所以swap分区2048) 

    /   根分区  文件系统类型:ext4   使用硬盘空间大小: 剩下所有硬盘空间 

    以上三个为基本分区,其他的分区需根据情况制定。

     

 

    网络这里,默认没有,点击添加网络,设备名称为 eth0,网络类型为 dhcp 

    

    验证部分

    

    

    防火墙和 selinux 根据自己需求选择开启或者禁用 

    

    显示设置

    

    软件包选择,默认没有勾选桌面。根据自己需求勾选。 (基本,语言支持)

     #附上Linux系统最小化安装包选择

       

后面剩余的两项不需要配置。 

    提示:安装脚本:在“预安装脚本”,“安装后脚本”对话框中,可以分别添加在安装前、安装后自动的可执行语句。此项设置使服务器自动化配置变得更加容易,例如可以在客户机在完成安装后自动设置 YUM 仓库,如下图所示,需要注意的是:应确保所编写的代码能够正确执行,以免安装失败。 

       

    提供一个参考的案例:

    

    然后点击左上角的文件选择保存,选择下保存的路径(/root),然后复制 ks.cfg 文件到/var/ftp/ 目录下: 

    [root@test1 ~]#cp ks.cfg  /var/ftp/

    :ks.cfg 就是无人值守安装时要用的 Kickstart 文件,该文件可以手动进行编辑,如果手动编辑 Kickstart 文件,则使用 ksvalidator 来验证该文件使用正确的关键字,但却无法验证 URL 路径、各个数据包或组等书写错误。Ksvalidator system-config-kickstart 数据包的一部分,

因此必须要安装该软件包 

---还记的/tftpboot/pxelinux.cfg/default 文件中设置过 ks=ftp://192.168.10.1/ks.cfg 因此必须

执行上面的一步重新挂载 安装光盘到/var/ftp/pub 目录下,开始执行另一台机器的无人值守安装:   

    [root@test1 ~]#umount /dev/cdrom      # 取消原来是挂载到/mnt 下的镜像文件。Umount /dev/cdrom(umount /mnt)

    [root@test1 ~]#mount /dev/cdrom  /var/ftp/pub 

    建议关闭防火墙和 selinux,如果没有关闭的话,tftp 服务会有问题。

    设置防火墙: 

    #chkconfig iptables off  (重启生效)

    #service iptables stop    (即刻生效)

    关闭 selinux 功能:有如下两种方法可以实现 

    1) 永久关闭 selinux 功能:修改/etc/sysconfig/selinux 文件,将 SELINUX=enforcing 改为 disabled,要重启系统才生效 

    2)临时关闭 selinux 功能:#setenforce  0  不需要重启系统若使用 vmware 虚拟机,如果还失败的话,就 vmware 虚拟机软件所提供的 DHCP 功能停掉(一般情况下不影响)

七、安装启动机器

接下来启动你要安装的机器了(设置为网络引导安装,你就可以休息下,等待自己安装完成) 

    新建一台虚拟机,操作系统稍后选择安装。将此虚拟机开机,默认会通过DHCP选择刚刚的192.168.144.133配置好的PXE进行安装系统。至此我们已经完成PXE无人值守系统安装。

  

  它会全程自己安装

  

 

可能出现的问题

     

  如果出现这个状态请查看 ks 的路径和 selinux 是否关闭。 

  查看 SELinux 状态:

  1、 /usr/sbin/sestatus -v      ##如果 SELinux status 参数为 enabled 即为开启状态

  SELinux status:                 enabled

  2、 getenforce                 ##也可以用这个命令检查

  如果遇到 Unable to retrieve ftp ,确认是否进行了镜像挂载, ls /var/ftp/pub/ 即可。

 

Guess you like

Origin www.cnblogs.com/rmxd/p/11320369.html