pxe安装系统 ip获取错误_数据中心操作系统自动化部署

本文详细介绍了使用Cobbler进行自动化操作系统部署时遇到的IP获取错误及相关问题的解决方案。从DHCP服务、TFTP、HTTP/FTP/NFS的配置,到Cobbler的安装、配置,包括解决server字段设置、next_server配置、TFTP服务、rsyncd服务、加载器缺失等问题,最后成功实现自动化部署。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言:

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理机和虚拟机的操作系统。PXE是Preboot Execution Environment的缩写,字面上的意思是开机前的执行环境,它采用了C/S网络架构模型,支持主机通过网络从远端服务器下载系统镜像、bootstrap文件,进而实现操作系统的安装。 Cobbler是以网络PXE形式部署操作系统的解决方案之一,通常用来部署Linux与vmware ESXI系统,对于windows操作系统的部署,微软有自己的解决方案WDS或SCCM,无论是哪种解决方案,其原理都是类似的,想要通过PXE形式部署操作系统,在你的网络中均需要部署如下几个服务:
  • DHCP服务:提供网络参数(IP、掩码、网关、DNS),告知客户端TFTP服务器的位置(DHCP option 66~67)

  • TFTP:提供boot loader及kernel file下载路径

  • HTTP/FTP/NFS:  提供系统镜像与配置文件的存放路径(三种方案用哪种都可以)

工作原理图如下:

9c1c1960f9457c84bd7274fba30e93cf.png

 2 

Cobbler安装与配置

2.1 准备工作

Demo环境介绍:

服务器数量: 1台

IP地址: 172.16.70.81

承担角色: Cobbler、DHCP、TFTP

2.1.1 关闭selinux

[root@localhost ~]# sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config  

2.1.2 关闭防火墙

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

2.1.3 通过rpm的方式在系统中安装epel源

[root@localhost ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

[root@localhost src]# rpm -ivh epel-release-latest-7.noarch.rpm  


2.2 Cobbler安装

2.2.1 安装必须的依赖包

[root@localhost src]# yum install -y ed patch perl perl-Compress-Zlib perl-Digest-SHA1 perl-LockFile-Simple perl-libwww-perl cobbler cobbler-web tftp dhcp httpd cman pykickstart debmirror xinetd

2.2.2 将Cobbler及其所有关联服务加入开机自启动

[root@localhost src]# systemctl enable httpd

[root@localhost src]# systemctl enable dhcpd

[root@localhost src]# systemctl enable xinetd

[root@localhost src]# systemctl enable rsyncd

[root@localhost src]# systemctl enable cobblerd

[root@localhost src]# systemctl restart rsyncd

[root@localhost src]# service  httpd restart


2.3 Cobbler配置2.3.1 执行Cobbler检查

fe87421d67cd8b2d8df6eee35049cbc9.png

综上经过cobbler初始化检测, 为了能够使cobbler能够正常运行, 我们将发现的9个问题解决


错误1:

    The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.

翻译:

    配置文件/etc/cobbler/settings中的server属性值必须设置为localhost之外的值, 并且需要设置为一个可以被解析的主机名或IP地址, 即将进行自动化装机的其他主机都需要用到这个地址.


错误2:

    For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.

翻译:

    在配置文件/etc/cobbler/settings中与PXE启动相关的参数next_server必须设置为非127.0.0.1的值, 需将其指定为网络启动服务器的IP地址


错误3:

    change 'disable' to 'no' in /etc/xinetd.d/tftp

翻译:

    将配置文件/etc/xinetd.d/tftp中的disable配置改为no


错误4:

    enable and start rsyncd.service with systemctl

翻译:

    通过命令启动rsync服务


错误5.

Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.

翻译:

/var/lib/cobbler/loaders中的文件丢失, 需要运行cobbler get-loaders命令下载这些文件. 

130dc2e19c7feaa98f391fa54ec9fea8.png

错误内容 6 ~ 7

    comment out 'dists' on /etc/debmirror.conf for proper debian support

    comment out 'arches' on /etc/debmirror.conf for proper debian support

翻译:

    配置文件/etc/debmirror.conf中的dists、arches是debian系统的相关配置, 由于我们当前是CentOS系统, 所以需将这两个配置注释掉


错误8

    The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one

翻译:。

    在/etc/cobbler/settings配置文件中, 对通过自动化安装的主机设置的默认密码为cobbler, 为了安全性我们需要将它进行修改.

[root@localhost ~]# openssl passwd -1 contoso.com

$1$J25CRUO4$ORndhO3Tway/WvEE/XJH/.

将生成的加密秘钥添加至配置文件/etc/cobbler/settings中, 为自动化方式部署的主机设置默认密码


错误9.

    fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them(可忽略)

翻译:

    fencing设备相关此项可忽略


2.3.2 重启cobbler并重新进程检测, 确保上面的报错都已解决

[root@localhost ~]# systemctl restart cobblerd

[root@localhost ~]# cobbler check

32d8840017cbfb73d9a305f046a4b0a8.png

2.3.3 配置Cobbler托管相关依赖服务

[root@localhost ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/g'  /etc/cobbler/settings

[root@localhost ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings  

注意: 最终应确保/etc/cobbler/settings中有如下配置

manage_dhcp: 1   #cobbler管理DHCP服务

restart_dhcp: 1  #cobbler可重启dhcp服务

manage_tftpd: 1  #cobbler管理tftp服务

pxe_just_once: 1 #支持pxe启动


2.3.4 Cobbler管理DHCP服务

修改cobbler配置目录中的dhcp.templates文件, 内容如下:

[root@localhost ~]# cat /etc/cobbler/dhcp.template 

7274b4b3703675949df82ef64f26d7f1.png

2.3.5 执行cobbler sync让配置生效

[root@localhost conf.d]# cobbler sync

c03e1821a4806976c1b5ee82a73031a3.png

2.3.6 启用cobbler web管理

通过Cobbler WEB我们可以通过图形化的方式对cobbler进行管理, 网址为 http://172.16.70.81/cobbler_web. 默认账号密码均为cobbler

64dcb061861e8c12753815344e14be2d.png

2.3.7 cobbler web相关配置文件查看

[root@localhost web]#  cat /etc/cobbler/users.digest  

a84cdc07fd531f3b50d45df8c8348ea8.png

a2ffae3e5bf0b009de6061b68c0bccb7.png

综上Cobbler自动化装机平台我们就搭建完成了

 3 

CentOS自动化部署

3.1 将CentOS安装盘挂载至Cobbler服务器

[root@localhost web]# mkdir -p /mnt/cdrom

[root@localhost web]# mount /dev/cdrom /mnt/cdrom  


3.2 将系统镜像导入cobbler

[root@localhost web]# cobbler import --path=/mnt/cdrom/ --name=CentOS7_Base --arch=x86_64

0ced760fefdabba3cd312e20257c951c.png

3.3 镜像导入成功后我们可以查看其相关信息

[root@localhost web]# cobbler list

81fe5d3fbb7a63029f75f4a7ea85be19.png

[root@localhost web]# cobbler report

a1409dc71b5d9aa88ae7f55d29083a34.png

23c71efc5acdead407ef1f5373257c6c.png

Sample_end.ks是安装系统时候默认执行的脚本, 这个脚本有可能并不符合我们的需求, 但这个脚本却是可用的, 后续我们可以通过kickstart去生成一个适合我们使用的脚本. 


3.4 正式部署操作系统前的准备工作

ec633f608f3156313679e26dcb38d54d.png

3.5 开始自动化部署 新建裸虚拟机一台, 开机按F12通过PXE方式进行网络启动

2233ecb64cf1eadc21d3f07394b881b9.png

9f9079f1030d51f1b1a2af9811d5f414.png

经过一段时间的等待,操作系统部署成功

e5dd062a47bc42f400304bc7a6ebfeca.png

注:

  • 被安装操作系统的物理机或虚拟机内存必须为2G以上,否则会在安装过程中报错,提示资源不够.

  • 如果想要自定义ks文件,可以安装kickstart服务进行配置生成,安装kickstart后若服务启动失败,并且提示  “Package selection is disabled due to problems downloading package information” 错误,解决办法为创建一个名叫development.repo的仓库文件

添加以下内容:

968b7a185421199fe387f4d12a00004c.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值