无人值守安装服务器

1、 什么是PXE?
  严格来说,PXE并不是一种安装方式,而是一种引导的方式。其核心功能是让客户通过网络从远端服务器下载启动镜像,从而实现网络启动。整个过程中,客户机要求服务器分配IP地址,在使用TFTP协议下载位于服务器上的启动镜像到本机内存中并执行,由这个启动文件完成客户端基本软件的设置。进行PXE安装的必要条件是要安装的计算机中包含一个PXE支持的网卡( NIC),即网卡中必须要有PXE Client。PXE( Pre-boot Execution Environment )协议使计算机可以通过网络启动。

  协议分为client 和server 端,PXE client在网卡的ROM中,当计算机引导时,BIOS把PXE client调入内存执行,由PXE client将放置在远端的文件通过网络下载到本地运行。

  运行PXE协议需要设置DHCP服务器和TFTP服务器。DHCP 服务器用来给PXE client (将要安装系统的主机)分配一个IP地址,由于是给PXE client分配IP地址,所以在配置DHCP服务器时需要增加相应的PXE设置。

  此外,在PXE client的ROM中,已经存在了TFTP Client。PXE Client通过TFTP协议到TFTP server上下载所需的文件。

2、什么是KickStart
  KickStart是一种无人职守安装方式。KickStart的工作原理是通过记录典型的安装过程中所需人工干预填写的各种参数,并生成一个名为ks.cfg 的文件;在其后的安装过程中(不只局限于生成KickStart安装文件的机器)当出现要求填写参数的情况时,安装程序会首先去查找KickStart生成的文件,当找到合适的参数时,就采用找到的参数,当没有找到合适的参数时,才需要安装者手工干预。
  这样,如果KickStart文件涵盖了安装过程中出现的所有需要填写的参数时,安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后去忙自己的事情。等安装完毕,安装程序会根据ks.cfg 中设置的重启选项来重启系统,并结束安装。

  kickstart文件可以通过以下三种方式生成:
    1>手动书写
    2>通过system-config-kickstart图形工具(该实验环境应用)
    3>通过红帽的安装程序Anaconda自动生成

3、安装部署流程
  客户端首先需要在BIOS中设置通过网络启动,当客户端启动后,就会通过发送广播包的方式寻找DHCP服务器,如果找到了DHCP服务器,即可向该服务器申请获得包括IP地址在内的网络参数,并通过DHCP获得TFTP的位置,当客户端获得TFTP服务器的地址后,即可从TFTP服务器上将启动文件下载到本机内存并且运行,最终实现无盘启动的功能。我们可以在启动文件中设置Kickstart文件共享的位置,这样客户端启动后,即可自动寻找kickstart文件实现无人值守安装操作系统。注意,kickstart文件需要实现通过网络共享。在kickstart文件中描述了如何安装设置操作系统。运行部署脚本等。

 

4、pxe+kickstart自动装机部署
  1>环境:
    192.168.100.101    关闭防火墙,禁用selinux

  2>配置安装服务器
  安装服务器需要DHCP、TFTP、NFS服务
  (1)DHCP服务
    DHCP服务器主要实现在企业内部网络为客户端分配IP地址等网络参数。在我们的无人值守环境中,当客户端选择从网络启动后,就会通过发送广播数据包的形式寻找DHCP服务器,从DNCP获得IP地址等参数后才可以通过TFTP共享读取启动文件。首先,进行安装DHCP。

[root@pxe-server ~]# yum install dhcp -y

    安装后,DHCP服务的主配置文件为/etc/dhcp/dhcp.conf.我们可以修改配置文件以实现为客户端分配网络参数。

[root@pxe-server ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@pxe-server ~]# cp /etc/dhcp/dhcpd.conf{,.bak}
[root@pxe-server ~]# > /etc/dhcp/dhcpd.conf
[root@pxe-server ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.100.0 netmask 255.255.255.0 {             #指定为那个网段分配网络参数
    range 192.168.100.3 192.168.100.100;                 #地址池
    option domain-name-servers centos7.expample.com;  #设置分配给客户端的DNS服务器地址
    option routers 192.168.100.2;                       #设置分配给客户端的网关地址
    option broadcast-address 192.168.100.255;            #广播地址
    default-lease-time 600;                           #默认租赁期限
    max-lease-time 7200;                  #最大租赁期限
    next-server 192.168.100.101;                       #下一跳,TFTP服务器地址
    filename "pxelinux.0";                         #在TFTP服务器上共享的启动文件名
}
[root@pxe-server ~]# systemctl start dhcpd
[root@pxe-server ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.

  (2)tftp服务安装配置

tftp服务安装配置:
[root@pxe-server ~]# yum install tftp-server tftp xinetd -y [root@pxe
-server ~]# vim /etc/xinetd.d/tftp # default: off # description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /varlib/tftpboot disable = no #将disbale改为no per_source = 11 cps = 100 2 flags = IPv4 }
[root@pxe-server ~]# systemctl start xinetd
[root@pxe-server ~]# systemctl enable xinetd
[root@pxe-server ~]# netstat -tlunp|grep 69
udp        0      0 0.0.0.0:69              0.0.0.0:*                           48143/xinetd

  (3)vsftpd服务安装配置

[root@pxe-server ~]# yum install vsftpd -y
[root@pxe-server ~]# systemctl start vsftpd
[root@pxe-server ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

   (4)kickstart服务:

[root@pxe-server ~]# yum install system-config-kickstart syslinux -y
[root@pxe-server ~]# mount /dev/cdrom /var/ftp/pub
mount: /dev/sr0 写保护,将以只读方式挂载
[root@pxe-server ~]# vim /etc/yum.repos.d/base.repo
[root@pxe-server ~]# cat /etc/yum.repos.d/base.repo
[base]
name=cdrom base
baseurl=file:///var/ftp/pub
gpgcheck=0
[root@pxe-server ~]# yum clean all
[root@pxe-server ~]# yum makecache
[root@pxe-server ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@pxe-server ~]# cp /misc/cd/images/pxeboot/vmlinuz /var/lib/tftpboot/
[root@pxe-server ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@pxe-server ~]# cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@pxe-server ~]# chmod 644 /var/lib/tftpboot/pxelinux.cfg/default
[root@pxe-server ~]# vim /var/lib/tftpboot/pxelinux.cfg/default //修改内容如下图
 
创建自动应答文件:
[root@pxe-server ~]# system-config-kickstart Could not open display because no X server is running. Try running 'system-config-kickstart --help' for a list of options. [root@pxe-server ~]# yum install gdm -y [root@pxe-server ~]# system-config-kickstart Could not open display because no X server is running. Try running 'system-config-kickstart --help' for a list of options.

  解决:安装Xmanager,打开插件Xstart,连接该主机

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



 

posted @ 2020-05-05 16:39  我听过  阅读(447)  评论(0编辑  收藏  举报