Centos搭建PXE,安装部署操作系统
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,安装部署操作系统的更多相关文章
- CentOS 6.5安装部署Zabbix监控系统
CentOS 6.5安装部署Zabbix监控系统 先说一点废话,我没有用centos7做实验,讲真,centos 7我也不常用,喜欢新版本的同学其实可以尝试下,注意一点的就是centos 6.5只支持 ...
- Centos 6 PXE安装
author:JevonWei 版权声明:原创作品 192.168.198.134作为安装服务器,由httpd服务共享安装程序 192.168.198.134作为dhcp服务器,客户机获取IP 一.安 ...
- centos如何离线安装部署node&pm2?
最近我们项目要上即时通讯,因为项目对安全要求比较高,所以选择了即时通讯云服务器yun2win,他们提供了数据服务器让我们自己安装部署.那么问题来了,我们服务器是放在内网,完全无法访问外网,而yun2w ...
- 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署
少啰嗦,直接装 看过上一篇分布式文件系统 - FastDFS 简单了解一下的朋友应该知道,本次安装是使用目前余庆老师开源的最新 V5.05 版本,是余庆老师放在 Github 上的,和目前你能在网络上 ...
- CentOS下SparkR安装部署:hadoop2.7.3+spark2.0.0+scale2.11.8+hive2.1.0
注:之前本人写了一篇SparkR的安装部署文章:SparkR安装部署及数据分析实例,当时SparkR项目还没正式入主Spark,需要自己下载SparkR安装包,但现在spark已经支持R接口,so更新 ...
- 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 ...
- CentOS 7.4 安装部署 iRedMail 邮件服务器
在公司部署了一套开源的邮件网关Scrollout F1用来测试,由于Scrollout F1需要使用IMAP协议连接到邮件服务器上的隔离邮箱,抓取GOOD和BAD文件夹里的邮件进行贝叶斯学习,但公司的 ...
- CentOS 7 Docker安装部署Go Web
Docker 是一种容器技术,它部署简单,能很好的进行服务隔离,生成镜像,Push到镜像仓库,其他机器一键拉取部署. Docker分为社区版CE和企业版EE,社区版是免费提供给个人和小型团队使用,企业 ...
- Centos虚拟机上安装部署Tenginx,以及部署过程中遇到的问题
Tenginx下载网址: Tenginx 官网地址:http://tengine.taobao.org/ Tenginx的官方网址中可以阅读Nginx的文档,可以选择中文进行阅读.下载Tengine- ...
随机推荐
- buerdepepeqi 的模版
buerdepepeqi的模板 头文件 #include <set> #include <map> #include <deque> #include <qu ...
- apache WEB服务器安装(包括虚拟主机)
一.apache下载编译安装 yum install apr apr-devel apr-util apr-util-devel gcc-c++ wget tar -y cd /usr/src wge ...
- Django框架之中间件MiddleWare
Django中的中间件是一个轻量级.底层的插件系统,可以介入Django的请求和响应处理过程,修改Django的输入或输出.中间件的设计为开发者提供了一种无侵入式的开发方式,增强了Django框架的健 ...
- Web的大趋势:Java+大前端
前后端分离,是目前Web开发的主流模式.而Java无疑是后端开发的王者,PHP和.NET目前仍处于水深火热之中,更像是在夹缝中求生存.而大前端,强势崛起!Java+大前端这一强强组合,面对其他Web领 ...
- 【重学Node.js 第4篇】实现一个简易爬虫&启动定时任务
实现一个简易爬虫&启动定时任务 课程介绍看这里:https://www.cnblogs.com/zhangran/p/11963616.html 项目github地址:https://gith ...
- Volatile是用于解决什么问题,谈谈实现原理
一.volatile的作用 通常情况下我们可以通过Synchronized关键字来解决这些个问题,不过如果对Synchronized原理有了解的话,应该知道Synchronized是一个比较重量级的操 ...
- DOCKER学习_007:Docker的套接字介绍
根据https://www.cnblogs.com/zyxnhr/p/11825331.html这个文章,已经可以正常安装一个docker服务 查看Docker状态 [root@docker-serv ...
- kotlin + springboot启用elasticsearch搜索
参考自: http://how2j.cn/k/search-engine/search-engine-springboot/1791.html?p=78908 工具版本: elasticsearch ...
- cocos2dx 仿射变换
AffineTransform __CCAffineTransformMake(float a, float b, float c, float d, float tx, float ty) { Af ...
- Django之表高级操作
目录 一.如何开启自己的测试脚本? 二.对表数据的添加.更新.删除 1.create() 2.update() 3.delete() 4.查看执行的sql语句 三. 单表查询13个操作 返回Query ...