PXE自动化部署安装centos7.6

运维

2019-05-29

169

0

PrebootExcution Environment 预启动执行环境Intel公司研发基于Client/Server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,PXE可以引导和安装Windows,linux等多种操作系统

环境介绍及初绍化

1、环境介绍

操作系统:CentOS Linux release 7.6.1810 (Core)

网卡地址:192.168.87.11/24

光盘镜像:CentOS-7.6-x86_64-DVD-1810.iso

安装工具:ServerPXE + dhcp + tftp-server + tftp + httpd

Workstaion网络:VMNet

2、准备工作

2.1、服务器禁用SElinux,然后进行重启操作

[root@ServerPXE ~]# cat /etc/redhat-release

CentOS Linux release 7.6.1810 (Core)

[root@ServerPXE ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g'

/etc/selinux/config

[root@ServerPXE ~]# setenforce 0

[root@ServerPXE ~]# systemctl reboot

[root@ServerPXE ~]# getenforce

Permissive

 

systemctl stop firewalld.service  关闭防火墙

systemctl disable  firewalld.service 禁止防火墙开机自启动

yum install -y dhcp httpd tftp-server syslinux     一次性安装四个软件包

rpm -q httpd dhcp tftp-server tftp syslinux

mount /dev/cdrom  /var/www/html/centos/7

mkdir  /var/www/html/ksdir

2.2   配置http做文件仓库和修改ks.cfg文件

yum -y install system-config-kickst*

system-config-ServerPXE  生成ks.cfg文件

 

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

systemctl  set-default multi-user.target  默认进入多用户模式

systemctl  disable initial-setup.service 自动化centos7

 

[root@ServerPXE ksdir]# cat /etc/dhcp/dhcpd.conf

option domain-name "ServerPXE";

option domain-name-servers ns1.ServerPXE, ServerPXE;

default-lease-time 600;

max-lease-time 7200;

log-facility local7;

subnet 192.168.87.0 netmask 255.255.255.0 {

  range dynamic-bootp 192.168.87.200 192.168.87.230;

  option domain-name-servers 192.168.87.11;

  option routers 192.168.87.1;

  default-lease-time 21600;

  max-lease-time 43200;

  next-server 192.168.87.11;

  filename "pxelinux.0";

}

[root@ServerPXE ksdir]#

 

systemctl enable  dhcpd  设置dhcp服务开机自启动

systemctl start dhcpd 启动dhcp服务

systemctl enable  httpd 设置http服务开机自启动

systemctl start httpd  启动http服务 

ss -ntlu 查看用到的服务端口是否都已开启 dhcp:67

 

拷贝文件到tftp服务器下

[root@ServerPXE ksdir]# tree /var/lib/tftpboot/

/var/lib/tftpboot/

├── boot.msg

├── chain.c32

├── initrd.img

├── mboot.c32

├── memdisk

├── menu.c32

├── pxelinux.0

├── pxelinux.cfg

│   └── default

├── splash.png

├── vesamenu.c32

└── vmlinuz

 

 

 

1 directory, 11 files

[root@ServerPXE ksdir]# ls /var/lib/tftpboot/

boot.msg   initrd.img  memdisk   pxelinux.0    splash.png    vmlinuz

chain.c32  mboot.c32   menu.c32  pxelinux.cfg  vesamenu.c32

[root@ServerPXE ksdir]#

 

[root@ServerPXE ksdir]# cat /var/lib/tftpboot/pxelinux.cfg/default

default vesamenu.c32

timeout 30

menu title  Auto Install CentOS

label centos7

  menu label ^Install  Desktop CentOS  7

  kernel vmlinuz

  append initrd=initrd.img ks=http://192.168.87.11/ksdir/ks.cfg

 

label local

  menu label Boot from ^local drive

  localboot 0xffff

menu end

tree /var/lib/tftpboot/

[root@ServerPXE ksdir]#

 

  1. 配置TFTP服务

安装tftp的server和client包

# yum install -y tftp*

安装xinetd守护进程,因为tftp依赖于xinetd

# yum install -y xinetd

 

修改tftp配置文件/etc/xinetd.d/tftp,将disable= yes改为disable=no

[root@ServerPXE ksdir]# cat /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

       disable                 = no

       per_source           = 11

       cps                = 100 2

       flags                     = IPv4

}

[root@ServerPXE ksdir]# ^C

[root@ServerPXE ksdir]#

关闭并配置开机自动关闭系统防火墙(重要!否则会导致PXE Client无法访问TFPT服务)

# systemctl stop firewalld

# systemctl disable firewalld

 

2、确保tftp.socket正常

[root@ServerPXE ~]# systemctl start tftp.socket

[root@ServerPXE ~]# systemctl enable tftp.socket

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

[root@ServerPXE ~]# systemctl status tftp.socket

  • tftp.socket - Tftp Server Activation Socket

Loaded: loaded (/usr/lib/systemd/system/tftp.socket; enabled; vendor preset: disabled)

Active: active (listening) since Thu 2017-12-28 01:56:55 CST; 2min 29s ago

Listen: [::]:69 (Datagram)

Dec 28 01:56:55 ServerPXE.contoso.com systemd[1]: Listening on Tftp Server Activation Socket.

Dec 28 01:56:55 ServerPXE.contoso.com systemd[1]: Starting Tftp Server Activation Socket

 

3、然后启动tftp.service

[root@ServerPXE ~]# systemctl start tftp.service

[root@ServerPXE ~]# systemctl enable tftp.service

[root@ServerPXE ~]# systemctl status tftp.service

  • tftp.service - Tftp Server

Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabled)

Active: active (running) since Thu 2017-12-28 02:04:32 CST; 20s ago

Docs: man:in.tftpd

Main PID: 1777 (in.tftpd)

CGroup: /system.slice/tftp.service

└─1777 /usr/sbin/in.tftpd -s /var/lib/tftpboot

 

[root@ServerPXE ~]# ss -unlp | grep 69 //端口为UDP:69

UNCONN 0 0 :::69 :::* users:(("systemd",pid=1,fd=42))

 

 

 

 

 

本地yum配置

cd /etc/yum.repos.d/vi CentOS-Media.repo

[c7-media]

name=CentOS-$releasever - Media

baseurl=http://localhost/centos/7

gpgcheck=0

enabled=1

制作cache

yum clean allyum makecache

 

 

 

 

 

PXE虚拟机自动安装配置:(支持PXE,启动顺序网络优先)

pxe1

部分安装过程,安装成功之后,会进行重启,进入到文本模式,即成功。

 

       

发表评论

全部评论:0条

lmy233

努力工作学习生活的人呐~~

联系方式

神圣之子仅供学习交流
E-mail:limengyu233@163.com
github:https://github.com/lmy01