您的位置:首页 > 运维架构 > Linux

PXE自动安装Linux系统

2017-02-18 14:23 525 查看
PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端(客户端)基本软件设置,从而引导预先安装在服务器中的终端操作系统。PXE可以引导多种操作系统,如:Windows95/98/2000/windows2003/windows2008/winXP/win7/win8,linux系列系统等。

######系统自动安装脚本######

一.配置系统软件(虚拟机:脚本提供机)

1.vim /etc/sysconfig/network-scrips/ifcfg-??              
##调整IP

2.vim /etc/yum.repo.d/??.repo                                     ##调整yum源

3.yum install system-config-kickstart.noarch -y        ##安装脚本生成软件

4.yum install httpd -y                                                
##安装http服务

5.systemctl start httpd                                          ##开启http服务

6.systemctl stop firewalld.service                
##关闭火墙

二.生成脚本文件(虚拟机:脚本提供机)
1.system-config-kickstart             ##启动脚本生成软件



















2.vim /var/www/html/ks.cfg             ##生成脚本后添加以下内容与脚本

%packages

@base                         ##安装系统必须组件

lftp                        ##测试软件

%end

三.测试脚本(在真机中安装虚拟机,这里需要会对KVM有一定的了解)

1.vim test.sh                     ##编写安装脚本

virt-install \    

--name $1 \                     ##虚拟机名字

--ram 1024 \                     ##内存的大小

--file /var/lib/libvirt/images/$1.qcow2 \  
##磁盘位置

--file-size 10 \                 ##磁盘大小

--location http://172.25.254.13/rht7.2 \ ##设定安装源

--extra-args "ks=http://172.25.254.113/ks.cfg"  ##设定脚本源(这里写刚才的脚本)



######网络装机(实战开始)######

一.服务器操作

->dhcp服务

1.yum install dhcp -y                 ##安装dhcp服务

2.vim /etc/dhcp/dhcpd.conf             ##修改配置文件

subnet 172.25.254.0 netmask 255.255.255.0 {

  range 172.25.254.160 172.25.254.245;

  option routers 172.25.254.254;

  next-server 172.25.254.113;             ##服务器ip

  filename "pxelinux.0";

}

3.systemctl start dhcp                  ##开启dhcp服务

4.systemctl enable dhcp              ##开机自启动dhcp服务

->tftp服务(对应目录在/var/lib/tftpbot/)


5.yum install tftp xinetd -y             ##安装tftp及其管理服务

6.vim /etc/xinetd.d/tftp              ##修改配置文件

> 14         disable               = no        
##设为开启xinetd时开启tftp

7.yum install syslinux -y             ##安装该软件获取pxelinux.0

8.cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/    ##复制该文件

9.cp 镜像/isolinux/* /var/lib/tftpboot/   ##复制这些文件

11.mkdir /var/lib/tftpboot/pxelinux.cfg ##创建目录

12.cd /var/lib/tftpboot/

13.cp isolinux.cfg pxelinux.cfg/default ##创建新系统读取文件

14.vim pxelinux.cfg/default            

  2 timeout 50

  63   menu default                 ##设定第一个(安装)为默认启动

  65   append initrd=initrd.img repo=http://172.25.254.13/rht7.2 ks=http://172.25.254.113/ks.cfg

                         ##设定安装源与ks源

二.待安装客户端

与服务器连接并设为网卡启动即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: