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. JavaScript | 值传递、引用传递的区别

    值传递 JavaScript值传递的数据类型:字符串(String).数字(Number).布尔(Boolean).空(Null).未定义(Undefined), 这五种数据类型是按值访问的,因为可以 ...

  2. 【阿里云IoT+YF3300】10.快速开发188协议设备驱动

    188协议的全称为CJ-T188-2004 <户用计量仪表数据传输技术条件>,是针对水表.燃气表.热量表和其他集中采集的一个国家行业标准协议. YFIOs就是YFSoft I/O Serv ...

  3. linux(raspbian)下mysql的安装,权限设置和用户管理

    一 MySQL安装:(1) 使用apt-get安装, 由于raspbian是基于Debian的自由操作系统,debian默认自带apt-get指令安装应用因此可以使用来安装 sudo apt-get ...

  4. [Oracle]Oracle的闪回归档

    Oracle的闪回归档 场景需求,由于管理数据库的一些核心表,在实施初期会有人为误删除的问题.Oracle 11gR2提供了闪回归档的特性,可以保证不用RMAN来恢复误删除的数据.实践如下: 1.创建 ...

  5. 「CH2101」可达性统计 解题报告

    CH2101 可达性统计 描述 给定一张N个点M条边的有向无环图,分别统计从每个点出发能够到达的点的数量.N,M≤30000. 输入格式 第一行两个整数N,M,接下来M行每行两个整数x,y,表示从x到 ...

  6. 「Vijos 1283」「OIBH杯NOIP2006第二次模拟赛」佳佳的魔杖

    佳佳的魔杖 背景 配制成功了珍贵的0号药水,MM的病治好了.轻松下来的佳佳意外的得到了一个好东西--那就是--一种非常珍贵的树枝.这些树枝可以用来做优质的魔杖!当然了,不能只做自己的,至少还要考虑到M ...

  7. 1062 最简分数 (20分)C语言

    一个分数一般写成两个整数相除的形式:N/M,其中 M 不为0.最简分数是指分子和分母没有公约数的分数表示形式. 现给定两个不相等的正分数 N1/M1和 N2/M​2,要求你按从小到大的顺序列出它们之间 ...

  8. 1053 住房空置率 (20 分)C语言

    在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行判断.判断方法如下: 在观察期内,若存在超过一半的日子用电量低于某给定的阈值 e,则该住房为"可能空置&quo ...

  9. Python for Data Analysis 学习心得(三) - 文件读写和数据预处理

    一.Pandas文件读写 pandas很核心的一个功能就是数据读取.导入,pandas支援大部分主流的数据储存格式,并在导入的时候可以做筛选.预处理.在读取数据时的选项有超过50个参数,可见panda ...

  10. iOS-UITableView HeaderView随Cell一起移动

    我们在使用TableView的时候,有时会设置HeaderView,当我们滑动的时候,HeaderView不会随Cell滑出屏幕,而是会固定到导航栏下面.今天我们要实现HeaderView随滑动一起滑 ...