centos系统搭建PXE网络安装centos+ubuntu+Windows

Centos搭建PXE,安装部署操作系统

一 . 原理:

1.什么是PXE:

PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端基本软件设置,从而引导预先安装在服务器中的终端操作系统。

严格来说,PXE 并不是一种安装方式,而是一种引导方式。进行 PXE 安装的必要条件是在要安装的计算机中必须包含一个 PXE 支持的网卡(NIC),即网卡中必须要有 PXE Client。PXE 协议可以使计算机通过网络启动。此协议分为 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,那么它就可以通过 TFTP 协议到 TFTP Server 上下载所需的文件了。

2.PXE的工作过程:

1. PXE Client 从自己的PXE网卡启动,向本网络中的DHCP服务器索取IP;

2. DHCP 服务器返回分配给客户机的IP 以及PXE文件的放置位置(该文件一般是放在一台TFTP服务器上) ;

3. PXE Client 向本网络中的TFTP服务器索取pxelinux.0 文件;

4. PXE Client 取得pxelinux.0 文件后之执行该文件;

5. 根据pxelinux.0 的执行结果,通过TFTP服务器加载内核和文件系统 ;

6. 进入安装画面, 此时可以通过选择HTTP、FTP、NFS 方式之一进行安装;

详细工作流程,请参考下面这幅图:

二.配置步骤:

1.基本环境:

①PXE搭建系统:CentOS Linux release 7.2.1511 (Core)

②IP地址:192.168.1.1(静态)

更改项:

BOOTPROTO= static

ONBOOT= yes

添加项:

IPADDR=192.168.1.10

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

DNS1=192.168.1.1

DNS2=114.114.114.114                                                                                                                                

③关闭防火墙:systemctl stop firewalld.service

[root@localhost ~]# systemctl stop firewalld.service        ##关闭firewalld防火墙

[root@localhost ~]# systemctl disable firewalld                ##关闭firewalld防火墙自启

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

④关闭selinux:

编辑配置文件:/etc/sysconfig/selinux

[root@localhost ~]# vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX= disabled        ##关闭 SELinux,只能重启生效。

# SELINUXTYPE= can take one of three two values:

#     targeted - Targeted processes are protected,

#     minimum - Modification of targeted policy. Only selected processes are protected.

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

因为更改配置文件需要重启后才能生效,所以使用命令临时关闭selinux:这种修改立时生效,但重启后失效。

[root@localhost ~]# getenforce

Enforcing                ##强制模式。违反 SELinux 规则的行为将被阻止并记录到日志中。

[root@localhost ~]# setenforce 0        ##设置selinux放松, 这种修改立时生效,但重启后失效。

[root@localhost ~]# getenforce

Permissive                ##宽容模式。违反 SELinux 规则的行为只会记录到日志中。一般为调试用。

⑤因为我是使用的VM虚拟机所以我以光驱的形式挂在了光盘:

SR0对应:CentOS-7-x86_64-DVD-1511.iso

SR1对应:ubuntu-16.04.6-server-amd64.iso

2.安装所需服务: dhcp        xinetd        tftp-server        httpd        syslinux

yum install dhcp xinetd tftp-server  httpd syslinux -y

为了便于编辑配置文件,我提前安装了vim: yum install -y vim

3.配置TFTP所需环境:

vim /etc/xinetd.d/tftp  ##编辑xinetd配置文件管理tftp

[root@localhost ~]# 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 /var/lib/tftpboot -c         ##所指tftp根目录

disable                 = no                         ##更改为no

per_source              = 11

cps                     = 100 2

flags                   = IPv4

}

重启xinetd服务和TFTP服务并使其开机自启:

[root@localhost ~]# systemctl restart xinetd        ##重启xinetd服务

[root@localhost ~]# systemctl restart tftp        ##重启tftp服务

[root@localhost ~]# systemctl enable tftp         ##使tftp服务开机自启

Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.

[root@localhost ~]# systemctl enable xinetd        ##使xinetd服务开机自启

根据需求复制指定引导文件到指定位置(请跳转至第6):

[root@localhost ~]# cp /usr/share/syslinux/* /var/lib/tftpboot/

4.配置DHCP所需环境:

编辑DHCP配置文件:/etc/dhcp/dhcpd.conf

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

#

# DHCP Server Configuration file.

#   see /usr/share/doc/dhcp*/dhcpd.conf.example

#   see dhcpd.conf(5) man page

#

allow booting;      #定义能够PXE启动

allow bootp;

log-facility local4;

subnet 192.168.1.0 netmask 255.255.255.0 {

range 192.168.1.210 192.168.1.220;

option routers 192.168.1.10;

option subnet-mask 255.255.255.0;

filename "pxelinux.0";

default-lease-time 86400;

max-lease-time 172800;

host ns {

next-server 192.168.1.10;

#        hardware ethernet 88:51:fb:59:1c:9b;

}

}

重启DHCP服务并使其开机自启:

[root@localhost ~]# systemctl restart dhcpd         ##重启dhcp服务

[root@localhost ~]# systemctl enable dhcpd         ##使dhcp服务开机自启

Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service. :

5.配置FTP所需环境(本次实验把HTTP服务改成了FTP服务,给网起设备提供系统):

安装FTP服务:yum install -y vsftpd

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

编辑/etc/vsftpd/vsftpd.conf,确保以下设置(ftp根目录没有更改,依旧是/var/ftp/):

anonymous_enable=yes

anon_upload_enable=YES        ##默认注释掉了需要取消注释

anon_umask=022        ##默认local_umask=022也可以

[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf

# Example config file /etc/vsftpd/vsftpd.conf

#

# The default compiled in settings are fairly paranoid. This sample file

# loosens things up a bit, to make the ftp daemon more usable.

# Please see vsftpd.conf.5 for all compiled in defaults.

#

# READ THIS: This example file is NOT an exhaustive list of vsftpd options.

# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's

# capabilities.

#

# Allow anonymous FTP? (Beware - allowed by default if you comment this out).

anonymous_enable=YES

#

# Uncomment this to allow local users to log in.

# When SELinux is enforcing check for SE bool ftp_home_dir

local_enable=YES

#

# Uncomment this to enable any form of FTP write command.

write_enable=YES

#

# Default umask for local users is 077. You may wish to change this to 022,

# if your users expect that (022 is used by most other ftpd's)

local_umask=022

#

# Uncomment this to allow the anonymous FTP user to upload files. This only

# has an effect if the above global write enable is activated. Also, you will

# obviously need to create a directory writable by the FTP user.

# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access

anon_upload_enable=YES

#

# Uncomment this if you want the anonymous FTP user to be able to create

# new directories.

重启vsftpd服务并使其开机自启:

[root@localhost ~]# systemctl restart vsftpd        ##重启FTP服务

[root@localhost ~]# systemctl enable vsftpd        ##使FTP服务开机自启

Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

创建目录用于挂载centos7系统iso镜像文件:/var/ftp/c7-64

[root@localhost ~]# mkdir -p /var/ftp/c7-64

挂载centos7系统iso镜像:

[root@localhost ~]# mount /dev/sr0 /var/ftp/c7-64/

为了每次开机都不用再去挂载推荐设置为自动挂载:

[root@localhost ~]# vim /etc/fstab

#

# /etc/fstab

# Created by anaconda on Thu Jan 16 16:30:28 2020

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/centos-root /                       xfs     defaults        0 0

UUID=c6af63a6-4574-481c-aa4d-50cc710ed5bb /boot                   xfs     defaults        0 0

/dev/mapper/centos-swap swap                    swap    defaults        0 0

/dev/sr0        /var/ftp/c7-64  auto    auto    0 0        ##添加这一行

~

mount: /dev/sr0 is write-protected, mounting read-only

6.配置准备系统安装引导所需文件+环境:

[root@localhost ~]# cp /var/ftp/c7-64/images/pxeboot/vmlinuz /var/lib/tftpboot/vmlinuz.c7-64

[root@localhost ~]# cp /var/ftp/c7-64/images/pxeboot/initrd.img /var/lib/tftpboot/initrd.img.c7-64

[root@localhost ~]# mkdir  -p /var/lib/tftpboot/pxelinux.cfg

[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

[root@localhost pxelinux.cfg]# vim /var/lib/tftpboot/pxelinux.cfg/default

default c7

prompt 1

timeout 100

display boot.msg

label c7

kernel vmlinuz.c7-64

append initrd=initrd.img.c7-64 method=ftp://192.168.1.10/c7-64 devfs=nomount

创建/var/lib/tftpboot/boot.msg用于显示信息:

[root@localhost ~]# vim /var/lib/tftpboot/boot.msg

####################################################

# Input:                               #

#    c7 to install CentOS7-64              #

#                                    #

# Type Enter directly to install default OS      #

# Default is c7                          #

###################################################

ok!到此需要安装系统的机器就可以开机使用PXE启动安装centos系统了!

Centos搭建PXE,安装部署操作系统的更多相关文章

  1. CentOS 6.5安装部署Zabbix监控系统

    CentOS 6.5安装部署Zabbix监控系统 先说一点废话,我没有用centos7做实验,讲真,centos 7我也不常用,喜欢新版本的同学其实可以尝试下,注意一点的就是centos 6.5只支持 ...

  2. Centos 6 PXE安装

    author:JevonWei 版权声明:原创作品 192.168.198.134作为安装服务器,由httpd服务共享安装程序 192.168.198.134作为dhcp服务器,客户机获取IP 一.安 ...

  3. centos如何离线安装部署node&pm2?

    最近我们项目要上即时通讯,因为项目对安全要求比较高,所以选择了即时通讯云服务器yun2win,他们提供了数据服务器让我们自己安装部署.那么问题来了,我们服务器是放在内网,完全无法访问外网,而yun2w ...

  4. 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署

    少啰嗦,直接装 看过上一篇分布式文件系统 - FastDFS 简单了解一下的朋友应该知道,本次安装是使用目前余庆老师开源的最新 V5.05 版本,是余庆老师放在 Github 上的,和目前你能在网络上 ...

  5. CentOS下SparkR安装部署:hadoop2.7.3+spark2.0.0+scale2.11.8+hive2.1.0

    注:之前本人写了一篇SparkR的安装部署文章:SparkR安装部署及数据分析实例,当时SparkR项目还没正式入主Spark,需要自己下载SparkR安装包,但现在spark已经支持R接口,so更新 ...

  6. centos7 搭建pxe 安装centos windows(非全自动)(这个教程测试centos6和7.2可以用,Windows各版本也可以)

    yum install dhcp xinetd syslinux tftp-server httpd 编辑dhcpdb配置(192.168.0.1为本机IP) ; max-lease-time ; l ...

  7. CentOS 7.4 安装部署 iRedMail 邮件服务器

    在公司部署了一套开源的邮件网关Scrollout F1用来测试,由于Scrollout F1需要使用IMAP协议连接到邮件服务器上的隔离邮箱,抓取GOOD和BAD文件夹里的邮件进行贝叶斯学习,但公司的 ...

  8. CentOS 7 Docker安装部署Go Web

    Docker 是一种容器技术,它部署简单,能很好的进行服务隔离,生成镜像,Push到镜像仓库,其他机器一键拉取部署. Docker分为社区版CE和企业版EE,社区版是免费提供给个人和小型团队使用,企业 ...

  9. Centos虚拟机上安装部署Tenginx,以及部署过程中遇到的问题

    Tenginx下载网址: Tenginx 官网地址:http://tengine.taobao.org/ Tenginx的官方网址中可以阅读Nginx的文档,可以选择中文进行阅读.下载Tengine- ...

随机推荐

  1. 【Linux】grep笔记

    Linux grep命令用于查找文件里符合条件的字符串. 参数: -a 或 --text : 不要忽略二进制的数据. -A<显示行数> 或 --after-context=<显示行数 ...

  2. C++Review5_Swap交换

    面试中可能会问到交换两个变量的值有几种实现方式,对这方面有一定了解还是有必要的,简单罗列一下几种方式,具体介绍查看参考链接: 1.中间变量:->这个最常见了 2.加减法: 3.异或法: 4.sw ...

  3. filter 开发

    在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目 ...

  4. HMaster/HRegion Server 工作原理

      1.HBase系统架构       2. HRegion Sever架构图 0.94之前的版本 0.96+的版本 WAL: 即Write Ahead Log, 是HDFS上一个文件,早期版本中称为 ...

  5. CodeForces 1182D

    图论的思维题,太秀了,网上答案也不多,我就也来bb吧 总之47个样例姑且是过了,不知道还有没有反例: 会求树的重心和中心了,挺好 #include<cstdio> #include< ...

  6. Elasticsearch基本概念和使用

    Elasticsearch基本概念和使用 1.操作索引 1.1.基本概念 Elasticsearch也是基于Lucene的全文检索库,本质也是存储数据,很多概念与MySQL类似的. 对比关系: 索引( ...

  7. MementoPattern(备忘录模式)-----Java/.Net

    备忘录模式(Memento Pattern)保存一个对象的某个状态,以便在适当的时候恢复对象.备忘录模式属于行为型模式.

  8. Tomcat黑窗口中对于中文乱码问题的解决

    存在的问题: 如标题,下图所示,启动tomcat时黑窗口中中文乱码,影响查看程序打印信息 解决方案: tomcat安装/解压目录中,conf 文件夹下 logging.properties 文件中,代 ...

  9. PHP 对接 饿了么开放平台 接单

    <?php # 一开始使用的是API方式对接,所以我这里是API的方式+SDK的结合 (除了获取token之外都是使用SDK方式,所以看到的朋友还是直接使用纯SDK方式对接最好),因为我这里使用 ...

  10. 解决apt-get命令出现的安装源错误

    首先linux环境下打开网页,输入上网账号密码,确保已经联网 直接安装软件或库的时候,在管理员模式下,在终端输入:apt-get install A可以自动安装A 有时会出现下面的安装源错误 这是因为 ...