您的位置:首页 > 运维架构 > Linux

企业必备———Linux Centos7 无人值守自动化装机(PXE部署)

2019-09-11 01:05 1586 查看

本章目的:无人值守自动化装Llinux Centos7系统

本章环境:VM虚拟机,一台linux服务器,一台客户端,都在局域网环境下

本章流程:

服务端:
1、DHCP服务 指定分配ip地址 定位引导文件

next-server //指向TFTP路径
filename //引导程序文件位置
—————————————————————————

2、TFTP服务(简单文件传输协议) UDP69端口

高效率             容量小

(引导程序pxelinnx.0(syslinux包),压缩内核vmlinuz,
系统初始化文件initrd.img,启动菜单default)

—————————————————————————

3.FTP (vsftp) 文件传输协议 系统镜像(centos7)
安全 容量大 TCP 20(数据传输), 21(连接)

—————————————————————————

安装包:dhcp, tftp-server, vsftp, syslinux

4.安装并配置kickstart无人值守

1.先设置我们的环境,给我们的服务端添加一块网卡

1.1装一个裸机的客户端(作为无人值守部署的验证,详细教程请看我之前的教程,下面的图片是要注意的地方)




记得重启我们的网卡才能生效

1.查看我们的网卡信息

[root@localhost ~]# ifconfig    //查看网卡详细信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 192.168.17.128  netmask 255.255.255.0  broadcast 192.168.17.255
inet6 fe80::e3c7:14af:6e4d:7216  prefixlen 64  scopeid 0x20<link>
ether 00:0c:29:c9:dd:05  txqueuelen 1000  (Ethernet)
RX packets 622  bytes 385786 (376.7 KiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 217  bytes 18826 (18.3 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet6 fe80::658e:4c2d:2273:9cf5  prefixlen 64  scopeid 0x20<link>
ether 00:0c:29:c9:dd:0f  txqueuelen 1000  (Ethernet)
RX packets 7  bytes 795 (795.0 B)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 82  bytes 13820 (13.4 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
//我们的两块网卡有了

2.配置这两块网卡

[root@localhost ~]# cd /etc/sysconfig/network-scripts/   //到我们的网卡配置文件夹中
[root@localhost network-scripts]# ls
ifcfg-ens33  ifdown-isdn      ifup          ifup-plip      ifup-tunnel
ifcfg-lo     ifdown-post      ifup-aliases  ifu-plusb     ifup-wireless
ifdown       ifdown-ppp       ifup-bnep     ifup-post      init.ipv6-global
ifdown-bnep  ifdown-routes    ifup-eth      ifup-ppp       network-functions
ifdown-eth   ifdown-sit       ifup-ib       ifup-routes    network-functions-ipv6
ifdown-ib    ifdown-Team      ifup-ippp     ifup-sit
ifdown-ippp  ifdown-TeamPort  ifup-ipv6     ifup-Team
ifdown-ipv6  ifdown-tunnel    ifup-isdn     ifup-TeamPort
[root@localhost network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36  //复制ens33网卡的信息到ens36中
[root@localhost network-scripts]# vim ifcfg-ens36  //进入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
DEVICE=ens36
ONBOOT=yes
IPADDR=192.168.100.100   //IP地址
NETMASK=255.255.255.0  //子网掩码
GATWAY=192.168.100.100 //默认网关
~
~
~
~
~
~
~
~
~
:wq                 //保存退出

3.重启网络服务查看地址有没有生效

[root@localhost network-scripts]# systemctl restart network   //重启网络服务,查看我们的网址有没有配上去
[root@localhost network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 192.168.17.128  netmask 255.255.255.0  broadcast 192.168.17.255
inet6 fe80::e3c7:14af:6e4d:7216  prefixlen 64  scopeid 0x20<link>
ether 00:0c:29:c9:dd:05  txqueuelen 1000  (Ethernet)
RX packets 2302  bytes 679197 (663.2 KiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 951  bytes 111027 (108.4 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 192.168.100.100  netmask 255.255.255.0  broadcast 192.168.100.255
inet6 fe80::658e:4c2d:2273:9cf5  prefixlen 64  scopeid 0x20<link>
ether 00:0c:29:c9:dd:0f  txqueuelen 1000  (Ethernet)
RX packets 9  bytes 1281 (1.2 KiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 230  bytes 39857 (38.9 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

4.安装DHCP服务和复制模板

[root@localhost network-scripts]# yum install dhcp -y  //安装DHCP服务

[root@localhost network-scripts]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? yes   //复制模板

5.配置dhcp服务

[root@localhost network-scripts]# vim /etc/dhcp/dhcpd.conf  //配置dhcp服务

subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.20 192.168.100.30;   //地址范围
option routers 192.168.100.100;      //默认网关指向客户端
option domain-name-servers 114.114.114.114;  //地址解析南京的服务器解析
next-server 192.168.100.100;  //指向TFTP服务器是自己的地址
filename "pxelinux.0";            //ftp站点底下的引导程序文件位置
}

#This is a very basic subnet declaration.

:wq

6.安装引导程序文件和TFTP服务

[root@localhost network-scripts]# yum install syslinux -y

[root@localhost network-scripts]# yum install tftp-server -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 tftp-server.x86_64.0.5.2-22.el7 将被 安装
--> 解决依赖关系完成

7.查看tftp软件包文件

[root@localhost network-scripts]# rpm -ql tftp-server
/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     //站点

8.复制引导程序到站点中

cp /usr/share/syslinux/pxelinux.0

[root@localhost network-scripts]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/  //复制引导程序到站点
[root@localhost network-scripts]# ls /var/lib/tftpboot/
pxelinux.0

9.配置TFTP服务(把yes改成no就行)

[root@localhost network-scripts]# 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
disable                 = no      //把yes改成no就行
per_source              = 11
cps                     = 100 2
flags                   = IPv4
}
~
~
~
~
~
~
~
~
~
~
:wq

10.安装VSftpd文件传输协议

安全 容量大 TCP 20(数据传输), 21(连接)

[root@localhost network-scripts]# yum install vsftpd -y //安装站点
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: mirrors.aliyun.com
正在解决依赖关系

11.挂载镜像(服务端要挂载镜像)

[root@localhost network-scripts]# cd /var/ftp
[root@localhost ftp]# ls
pub
[root@localhost ftp]# mkdir centos7 //创建一个文件夹
[root@localhost ftp]# ls
centos7  pub
[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7  //挂载
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ftp]# df -hT
文件系统       类型      容量  已用  可用 已用% 挂载点
/dev/sda2      xfs        10G  4.3G  5.8G   43% /
devtmpfs       devtmpfs  898M     0  898M    0% /dev
tmpfs          tmpfs     912M     0  912M    0% /dev/shm
tmpfs          tmpfs     912M  9.0M  903M    1% /run
tmpfs          tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda5      xfs        10G   37M   10G    1% /home
/dev/sda1      xfs       6.0G  174M  5.9G    3% /boot
tmpfs          tmpfs     183M   20K  183M    1% /run/user/0
/dev/sr0       iso9660   4.3G  4.3G     0  100% /var/ftp/centos7

12.把镜像中的系统内核和初始化文件放到站点中

[root@localhost ftp]# cd centos7/
[root@localhost centos7]# ls
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 centos7]# cd images/
[root@localhost images]# ls
efiboot.img  pxeboot  TRANS.TBL
[root@localhost images]# cd pxeboot/
[root@localhost pxeboot]# ls
initrd.img  TRANS.TBL  vmlinuz
[root@localhost pxeboot]# cp initrd.img vmlinuz /var/lib/tftpboot/  把系统内核和初始化文件放到站点中
[root@localhost pxeboot]# ls /var/lib/tftpboot/
initrd.img  pxelinux.0  vmlinuz
[root@localhost pxeboot]#

13.在站点中配置启动菜单

[root@localhost pxeboot]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  vmlinuz
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  pxelinux.cfg  vmlinuz
[root@localhost tftpboot]# cd pxelinux.cfg
[root@localhost pxelinux.cfg]# vim default  //配置启动菜单
default 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
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq

14.关闭防火墙,增强功能,开启所有服务

[root@localhost pxelinux.cfg]# systemctl stop firewalld.service 关闭防火墙
[root@localhost pxelinux.cfg]# setenforce 0  //关闭增强功能
[root@localhost pxelinux.cfg]# systemctl start dhcpd   //开启这三个服务
[root@localhost pxelinux.cfg]# systemctl start tftp
[root@localhost pxelinux.cfg]# systemctl start vsftpd
[root@localhost pxelinux.cfg]#

15.我们回到服务端安装kickstart 无人值守安装部署

[root@localhost pxelinux.cfg]# yum install system-config-kickstart -y //安装无人值守工具
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile

16.开始配置kickstart 无人值守安装部署

设置中文,时区,ROOT密码

16.1把这个配置文件放到我们的站点中

17.把系统的配置文件模板,放到我们的kickstart配置文件中

[root@localhost pxelinux.cfg]# cd /var/ftp/
[root@localhost ftp]# ls
centos7  ks.cfg  pub
[root@localhost ftp]# vim ks.cfg
[root@localhost ftp]# cd /root
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# vim anaconda-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
kexec-tools

%end

18.用引导程序加载这个模板

加个ks.cfg文件地址就可以了ks=ftp://192.168.100.100/ks.cfg

[root@localhost ftp]# 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

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

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

19.我们验证是否是自动化安装

以上就是我们的所有内容了,绝对详细,绝对正确。

谢谢大家观看

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: