pxe+kickstart无人值守装机

pxe+kickstart无人值守装机

DHCP概述及原理 Dynamic Host Configuration Protocol 动态主机配置协议,由IETF(Internet 网络工程师任务小组)组织制定,用来简化主机地址分配管理

主要分配以下入网参数

— IP地址/子网掩码/广播地址

— 默认网关地址、DNS服务器地址

— PXE引导设置(TFTP服务器地址、引导文件名)

DHCP地址分配的四次会话 DISCOVERY - OFFER - REQUEST - ACK

服务端基本概念 租期:允许客户机组用IP地址的时间期限,单位为秒

                          作用域:分配给客户机的IP地址所在网段

                          地址池:用来动态分配的IP地址范围

网络装机的优势

规模化:同时装配多台主机 ;自动化:装系统,配置各种服务 ;远程实现:不需要光盘、U盘等物理介质

什么是PXE网络 PXE     Pre-boot eXecution Environment 预启动执行环境,在操作系统之前运行 可用于远程安装 工作模式 PXE client 集成在网卡的启动芯片中 当计算机引导时,从网卡芯片中把PXE client调入内存执行,获取PXE server配置,实现菜单PXE server配置、显示菜单,根据用户选择远程引导程序下载到本机运行。

PXE需要用到的服务及组件

DHCP 服务,用于分配IP地址,定位引导程序

TFTP (简单文件传出协议)服务,提供引导程序下载

HTTP 服务(或FTP/NFS),提供yum安装源

客户端应具备的条件

— 网卡芯片必须支持PXE协议

— 主板支持从网卡启动

关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

关闭内核
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config

# 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
# 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 


挂载   配置yum源
[root@localhost ~]# mkdir /mnt/centos
[root@localhost ~]# mount /dev/cdrom /mnt/centos
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@localhost yum.repos.d]# rm -rf *.repo
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/local.repo
[local]
name=local_centos
baseurl=file:///mnt/centos
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]# echo '/dev/cdrom /mnt/centos iso9660 defaults 0 0' >> /etc/fstab
[root@localhost yum.repos.d]# mount -a
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache 
[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                            源名称                                   状态
local                             local_centos                             3,971
repolist: 3,971

安装dhcp
[root@localhost yum.repos.d]# yum -y install dhcp
[root@localhost yum.repos.d]# vim /etc/dhcp/dhcpd.conf

esc:r /usr/share/doc/dhcp*/dhcpd.conf.example   #  复制出配置文件

    subnet 192.168.70.0 netmask 255.255.255.0 {     #设置网段   及子网掩码
    range 192.168.70.60 192.168.70.120;                #设置IP地址区间  
    option domain-name-servers 192.168.70.50;      #本机IP地址
    option routers 192.168.70.254;                                 #路由IP地址
    default-lease-time 600;                                        
    max-lease-time 7200;
 }

激活dhcp
[root@localhost yum.repos.d]# systemctl start dhcpd


安装tftp

TFTP 简单的文件传输协议,端口号 69

软件包:tftp-server 服务名:tftp

默认共享路径:/var/lib/tftpboot
[root@localhost yum.repos.d]#  yum -y install tftp-server.x86_64 
                                              
[root@localhost yum.repos.d]# vim /etc/dhcp/dhcpd.conf 

    next-server 192.168.70.50;   #添加 tftp IP地址
    filename "pxelinux.0";           #制定引导文件名

启动dhcp   tftp
[root@localhost yum.repos.d]# systemctl restart dhcpd
[root@localhost yum.repos.d]# systemctl restart tftp
[root@localhost yum.repos.d]# systemctl status tftp
查找共享文件 路径
[root@localhost yum.repos.d]# rpm -ql tftp-server 
/var/lib/tftpboot

安装syslinux
[root@localhost yum.repos.d]# yum -y install syslinux

查找pxelinux.0 引导文件  路径
[root@localhost yum.repos.d]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0

将pxelinux.0 复制粘贴到共享文件夹
[root@localhost yum.repos.d]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost yum.repos.d]#  ls /var/lib/tftpboot/
pxelinux.0

查看关在系统文件  并且复制到共享文件

vesamenu.c32   图形模块
vmlinuz   启动内核文件
splash.png   菜单背景图片
isolinux.cfg  菜单文件(拷贝菜单文件并重新命名)
initrd.img     驱动程序文件

[root@localhost yum.repos.d]# cd /mnt/centos/
[root@localhost centos]# ls  
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL
[root@localhost centos]# cd isolinux/                         cd /images  内也有vmlinuz  initrd.img
[root@localhost isolinux]# ls
boot.cat  grub.conf   isolinux.bin  memtest     TRANS.TBL     vmlinuz
boot.msg  initrd.img  isolinux.cfg  splash.png  vesamenu.c32
[root@localhost isolinux]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost isolinux]# cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@localhost isolinux]# cp {vmlinuz,splash.png,vesamenu.c32,initrd.img} /var/lib/tftpboot
[root@localhost isolinux]# ls /var/lib/tftpboot/
initrd.img  pxelinux.0  pxelinux.cfg  splash.png  vesamenu.c32  vmlinuz


修改菜单文件
[root@localhost isolinux]# vim /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 60    #开机时间倒计时

label linux
  menu label ^Install CentOS 7
  kernel vmlinuz
  append initrd=initrd.img # 后面删除
  
#以下全部删除


重启tftp  dhcp
[root@localhost isolinux]# systemctl restart tftp
[root@localhost isolinux]# systemctl restart dhcpd


安装httpd

 创建共享目录  mkdir /var/www/html/centos
[root@localhost isolinux]# yum -y install httpd
启动httpd   设置开机自启
[root@localhost isolinux]# systemctl restart httpd
[root@localhost isolinux]# systemctl enable httpd

新建共享目录
[root@localhost isolinux]# mkdir /var/www/html/centos

挂载镜像内容
[root@localhost isolinux]# mount /dev/cdrom/ /var/www/html/centos
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost isolinux]# ls /var/www/html/centos
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL

安装部署应答文件   无人值守安装
[root@localhost isolinux]# yum -y install system-centos-kickstart


[root@localhost isolinux]# vim /etc/yum.repos.d/local.repo 
[development]    修改仓库标识
name=local_centos
baseurl=file:///mnt/centos
enabled=1
gpgcheck=0
 
图形生成应答文件工具
[root@localhost isolinux]# system-config-kickstart

 http目录   /var/www/html/centos

制定http服务

 

添加4个基本分区

/boot 分 500M

/swap 分 4096M

/home 分 4096M

剩余的全给 / ,选择下面 使用磁盘上全部未用空间 这一项

 

centos7 网卡名称

 

 系统安装基本功能   其余可在装机后安装

 

文件保存到  /var/www/html/

[root@localhost isolinux]# vim /var/lib/tftpboot/pxelinux.cfg/default 
label linux
  menu label ^Install CentOS 7
  menu default  读秒结束默认选择安装
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.70.50/ks.cfg  #指定应答文件位置


重启文件 
[root@localhost isolinux]# systemctl restart tftp
[root@localhost isolinux]#  systemctl restart dhcpd

安装系统

新建虚拟机

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值