通过网络去装系统,如何部署配置
大安网站建设公司创新互联建站,大安网站设计制作,有大型网站制作公司丰富经验。已为大安上千提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的大安做网站的公司定做!
前言
部署PXE远程安装服务
- 搭建PXE远程安装服务器
- 验证PXE网络安装
实现Kickstart无人值守安装
- 准备安装应带文件
- 实现批量自动装机
一 :服务器的批量部署
- 规模化:同时装配多台服务器
- 自动化:安装系统、配置各种服务
- 远程实现:不需要光盘、U盘等安装介质
- 缺点:同时安装的服务器裸机若是过多,则需要考虑带宽是否够用 即传输介质

二 : 关于PXE网络
2.1 PXE,Pre-boot eXcution Environment
- 预启动执行环境,在操作系统之前运行
- 可用于远程安装、构建无盘工作站
2.2 服务端 配置
- 运行DHCP服务,用来分配地址、定位引导程序
- 运行TFTP服务,提供引导程序下载
2.3 客户端 硬件要求
- 网卡支持PXE协议
- 主板支持网络启动
裸机插网卡,没有IP地址,所以服务器要先运行DHCP服务,给客户机分配地址,即服务端第一步先安装引导程序
引导程序,指导客户机去服务端下载相关安装文件
引导程序放在TFTP服务器上,UDP协议69端口,传输速度快,文本小 第二步
映像文件放在VSFTPD上,tcp21和20端口 第三步
openstack
daiwops
三 : 配置PXE装机服务器
3.1 基本部署过程
- 准备Centos 7 安装源
- 配置DHCP服务,用来分配地址、指出引导程序位置
- 配置TFTP服务,用来提供内核、引导程序
- 配置启动菜单
3.1.1 TFTP服务及引导文件
- 安装tftp-server软件包,启用tftp服务
- 准备内核文件vmlinuz
- 准备初始化镜像initrd.img
- 准备引导程序文件pxelinux.0 (引导程序文件pxelinux.0依赖于syslinux程序,需要先安装syslinux程序)
- 还有一个是tftp的默认配置文件需要修改 /etc/xinetd.d/tftp
[root@localhost pxelinux.cfg]# yum install tftp-sever -y    '安装tftp服务软件'
[root@localhost pxelinux.cfg]# vim /etc/xinetd.d/tftp   '修改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
3.1.2 DHCP服务的PXE设置
[root@localhost pxelinux.cfg]# yum install dhcp     '安装dhcp服务'
subnet 192.168.100.0 netmask 255.255.255.0 {
  range 192.168.100.1 192.168.100.200;
  option routers 192.168.100.100;
  option domain-name-servers 8.8.8.8;
  next-server 192.168.100.100;  '指定TFTP服务器地址'
  filename "pxelinux.0";        '指定要下载的引导程序文件'
}
[root@localhost pxelinux.cfg]# systemctl start dhcpd    '开启'
[root@localhost pxelinux.cfg]# systemctl enable dhcpd   '自启动'
3.1.3 默认的启动菜单文件
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default  '编辑default'
default auto    '默认共享'
prompt 1    '启动时间'
label auto
        kernel vmlinuz  '内核'
        append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
        追加      进程 初始化文件    方法   定位                         kickstart  位置
label linux text    '文本模式安装'
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux rescue  '进入救援模式'
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
四 : 关于kickstart
4.1 kickstart无人值守技术
- 创建应答文件,预先定义好各种安装设置
- 免去交互设置过程,从而实现全自动化安装
- 通过添加%post脚本,完成安装后的各种配置操作
4.2 准备应答文件
- 应答文件的内容
root@localhost ~]# vim /var/ftp/ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL6,
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$6qKSDsgs$eaNnQ18jrgccQjSX95B9Z.
# Use network installation
url --url="ftp://192.168.100.100/centos7"   '网络安装源'
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=none
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs" --size=512
part /home --fstype="xfs" --size=4096
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1
%packages   '定制的软件包组'
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
%end
4.2 PXE与kickstart结合使用
- 将应答文件部署在客户机可访问的位置
- 修改启动菜单文件,添加调用应答文件
root@localhost ~]# cp /root/ks.cfg /var/ftp/ks.cfg      
root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default   '编辑default'
default auto    '默认共享'
prompt 0    '取消用户时间'
label auto
        kernel vmlinuz  '内核'
        append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
        追加      进程 初始化文件    方法   定位                 应答文件kickstart  位置
4.3 PXE+kickstart自动安装
4.3.1 PXE与kickstart结合使用
- 将应答文件部署在客户机可访问的位置
- 修改启动菜单文件,调用应答文件
实验:运用PXE+kickstart搭建自动安装linux系统的服务器
思路:pxe自动部署
DHCP
为客户机自动获取IP地址,引导定位TFTP文件位置
命令:
next-server TFTP的IP
fliename “pxelinux.0”
TFTP 安装tftp-server包,第一个安装syslinux(包含pxelinux.0)' 引导程序
 第二个压缩内核 vmlinxuz (iso镜像文件中获取)
 第三个初始化文件 initrd.img (iso镜像文件中获取)
 第四个默认配置文件 default (自建文件:三个模式,默认是auto,指引FTP镜像系统文件位置)
vsftpd 系统镜像 无人值守安装配置模板 (ks.cfg)
五 :实验步骤
新加一块网卡,设置仅主机模式,主机网卡用来安装服务端去连接裸机,NAT网卡用来下载软件包

[root@localhost named]# ifconfig    查看网卡
ens33: flags=4163  mtu 1500
        inet 192.168.139.131  netmask 255.255.255.0  broadcast 192.168.139.255  '可以上网的网卡'
        inet6 fe80::413b:c9ad:e0e:1afc  prefixlen 64  scopeid 0x20
        ether 00:0c:29:d6:c0:8a  txqueuelen 1000  (Ethernet)
        RX packets 638059  bytes 939850586 (896.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 157948  bytes 9731567 (9.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
ens36: flags=4163  mtu 1500 '新增加的网卡,需要重新配置'
        inet6 fe80::351b:fad2:2b7c:7ac2  prefixlen 64  scopeid 0x20
        ether 00:0c:29:d6:c0:94  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13  bytes 2334 (2.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  [root@localhost named]# cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens36    
'把ens33的网卡作为模板复制修改为ens36'
[root@localhost named]# vim /etc/sysconfig/network-scripts/ifcfg-ens36  
                        '修改配置'
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"  '网卡设置为静态'
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens36"    '名称改为36'
DEVICE="ens36"
ONBOOT="yes"
IPADDR=192.168.100.100  '配置IP地址'
NETMASK=255.255.255.0   '配置子网掩码'
GATEWAY=192.168.100.1   '配置网关'
[root@localhost named]# systemctl restart network   '重启网卡'
[root@localhost named]# ifconfig    '再次查看'
ens33: flags=4163  mtu 1500
        inet 192.168.139.131  netmask 255.255.255.0  broadcast 192.168.139.255
ens36: flags=4163  mtu 1500
        inet 192.168.100.100  netmask 255.255.255.0 
    '成功'  1.
[root@localhost named]# systemctl stop firewalld.service    关闭防火墙
[root@localhost named]# setenforce 0    '关闭增强'
[root@localhost named]# rpm -q dhcp '查看dhcp是否安装'
dhcp-4.2.5-77.el7.centos.x86_64
[root@localhost named]# yum install dhcp -y     '没有安装的使用这个命令'
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.zju.edu.cn
软件包 12:dhcp-4.2.5-77.el7.centos.x86_64 已安装并且是最新版本
无须任何处理
[root@localhost named]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example  /etc/dhcp/dhcpd.conf
                        '复制模板到/etc/dhcp.dhcpd下'
[root@localhost named]# vim /etc/dhcp/dhcpd.conf    '编辑'
subnet 192.168.100.0 netmask 255.255.255.0 {
  range 192.168.100.1 192.168.100.200;
  option routers 192.168.100.100;
  option domain-name-servers 8.8.8.8;
  next-server 192.168.100.100;  '指定TFTP服务器'
  filename "pxelinux.0";    '指定要下载的引导程序文件目录'
} 
2.安装tftp服务
[root@localhost named]# yum install tftp-server -y  '安装TFTPd服务'
[root@localhost named]# rpm -ql tftp-server '查看tftp服务的所有文件'
/etc/xinetd.d/tftp  '需要配置'
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot
[root@localhost named]# vim /etc/xinetd.d/tftp  '编辑/etc/xinetd.d/tftp'
14         disable                 = no     '双重否定为启用'
[root@localhost named]# vim /var/lib/tftpboot   'tftpboot站点'
[root@localhost named]# cd /var/lib/tftpboot
[root@localhost tftpboot]# ls
[root@localhost tftpboot]# 
[root@localhost tftpboot]# yum install syslinux -y  '安装syslinux'
[root@localhost tftpboot]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0      '把pxelinux.0复制到tftpboot内'
[root@localhost tftpboot]# 
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost tftpboot]# ls /var/lib/tftpboot
pxelinux.0
[root@localhost tftpboot]# yum install vsftpd -y    '安装vsftpd服务'
[root@localhost tftpboot]# rpm -ql vsftpd |grep pub
/var/ftp/pub
[root@localhost tftpboot]# mkdir /var/ftp/centos7   '创建/var/ftp/centos7目录'
[root@localhost tftpboot]# cd /var/ftp
[root@localhost ftp]# ls
centos7  pub
[root@localhost ftp]# ls centos7/
[root@localhost ftp]# 
开启光驱,使用对应系统的镜像文件
[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7   '把镜像文件挂载到centos7上'
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ftp]# ls centos7
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@localhost ftp]# cd centos7/images '切换到镜像文件下的images目录'
[root@localhost images]# ls
efiboot.img  pxeboot  TRANS.TBL
[root@localhost images]# cd pxeboot '切换到pxeboot目录'
[root@localhost pxeboot]# ls
initrd.img  TRANS.TBL  vmlinuz
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot   '把里面的两个文件复制到var/lib/tftpboot'
[root@localhost pxeboot]# ls /var/lib/tftpboot
  initrd.img  pxelinux.0  vmlinuz[root@localhost pxeboot]# cd /var/lib/tftpboot  '切换到tfpboot目录'
[root@localhost tftpboot]# mkdir pxelinux.cfg   '创建pxelinux.cfg目录'
[root@localhost tftpboot]# cd pxelinux.cfg
[root@localhost pxelinux.cfg]# vim default  '在pxelinux.cfg目录下创建default文件'
[root@localhost pxelinux.cfg]# ls
default
[root@localhost pxelinux.cfg]# 
defalut auto    '默认为自适应'
prompt 1    '等待时间'
label auto  '标签自适应'
        kernel vmlinuz  '内核'
        append initrd=initrd.img method=ftp://192.168.100.100/centos7
        '追加初始化进程'           '路径方法'
label linux text
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux rescue
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
[root@localhost pxelinux.cfg]# systemctl start dhcpd    '开启dhcpd'
[root@localhost pxelinux.cfg]# systemctl start vsftpd   '开启vsftpd'
[root@localhost pxelinux.cfg]# systemctl start tftp     '开启tftp'
测试
此时测试的虚拟机的网卡需要是仅主机模式

进入4
boot 敲回车

自动引导结束

3.无人值守安装
[root@localhost ~]# yum install system-config-kickstart -y      '安装系统配置工具kickstart'













[root@localhost ~]# cd /var/ftp '切换到/var/ftp目录'
[root@localhost ftp]# ls
centos7  ks.cfg  pub
[root@localhost ftp]# vim ks.cfg    '修改ks.cfg配置文件'
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$6qKSDsgs$eaNnQ18jrgccQjSX95B9Z.
# Use network installation
url --url="ftp://192.168.100.100/centos7"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=none
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs" --size=512
part /home --fstype="xfs" --size=4096
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1
[root@localhost ftp]# cd ~  '切换到root的家目录'
[root@localhost ~]# ls
anaconda-ks.cfg       公共  视频  文档  音乐
initial-setup-ks.cfg  模板  图片  下载  桌面
[root@localhost ~]# vim anaconda-ks.cfg     '把里面的anaconda.ks.cfg文件内的'
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network  --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network  --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$lZy/ZqchdBxv/dZ0$RUyTDADN9e2H0hJlb9J757GyZ0nxWhPKY1sDdyCtvBR2/Asw/CPCAFFIfJB.kO7qbicMQx1LeoP53Xq/YXJeC0
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --name=gsy --password=$6$4r65p5GBvUZhGlnz$Cs.RsqZdbDij5eQeIxWRi3f4VERzZFsp1TSkgaURI3d0Beafr8TT//iBETmpgEsW//yoHoqfvL9k2BwmGQlx51 --iscrypted --gecos="gsy"
# X Window System configuration information
xconfig  --startxonboot
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
~     
[root@localhost ~]# vim /var/ftp/ks.cfg
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
%end
[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  pxelinux.cfg  vmlinuz
[root@localhost tftpboot]# cd pxelinux.cfg
[root@localhost pxelinux.cfg]# ls
default
[root@localhost pxelinux.cfg]# vim default
label auto
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
[root@localhost pxelinux.cfg]# systemctl restart dhcpd
[root@localhost pxelinux.cfg]# systemctl restart tftp
[root@localhost pxelinux.cfg]# systemctl restart vsftpd
再次验证
选择第四个,然后回车

六 : 总结:PXE+kickstart 批量网络装机的搭建服务器
1.首先先关掉防火墙
systemctl stop firewalld.service
setenforce 02.配置双网卡
3.运行DHCP服务(端口号:给客户机分配地址,引导安装文件)
subnet 192.168.100.0 netmask 255.255.255.0 {
  range 192.168.100.1 192.168.100.200;
  option routers 192.168.100.100;   '在局域网络配置装机服务时,把网关指向自己'
  option domain-name-servers 8.8.8.8;
  next-server 192.168.100.100;  '指定FTP服务器'
  filename "pxelinux.0";    '指定要下载的引导程序文件目录'
} 
4.运行vsftpd服务(tcp21和20端口,存放映像文件)
5.运行tftpd服务(udp端口号69,引导程序在TFTPd上)
配置tftpd服务的配置文件/etc/xinetd.d/tftp
disable 改为no    '开启'initrd.img和vmlinuz文件来源于镜像文件:把镜像文件下的images/pxeboot/目录下的两个initrd.img、vmlinuz文件拷贝到/var/lib/tftpboot目录下
pxelinux.0文件:需要先安装syslinux软件,在其/usr/share/syslinux目录下,把pxelinux.0文件直接复制到var/lib/tftpboot/目录下
pxelinux.cfg目录为新创建的目录,然后再var/lib/tftpboot/pxelinux.cfg/目录下新建default文件
 pxelinux.cfg/default文件配置
default auto    '默认共享'
prompt 1    '启动时间'
label auto
        kernel vmlinuz  '内核'
        append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
        追加      进程 初始化文件    方法   定位                         kickstart  位置
label linux text    '文本模式安装'
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux rescue  '进入救援模式'
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7然后开启所有服务
systemctl start dhcpd   '开启dhcpd'
systemctl start vsftpd  '开启vsftpd'
systemctl start tftp        '开启tftp'6.配置KICKstart
先安装system-config-kickstart 系统配置kickstart软件
然后再图形化界面配置
- 安装方法FTP 服务器ftp://192.168.100.100/ - 目录centos7 
- 引导装载程序选开启 
- 分区设置,/boot512M /home 4096M swap 4096M / 剩余的所有都给他 
- 添加网卡ens33 
- 禁用防火墙 
- 安装后脚本使用解释程序/bin/bash
然后保存在vsftpd服务的/var/ftp/目录下
脚本可以把~/anaconda.cfg中的数据%pac
kages到%end 复制到/var/ftp/ks.cfg中
此时再次重启即可
文章标题:理论+实操:PXE高效批量网络装机——理论讲解
转载来源:http://www.scyingshan.cn/article/jojiji.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 