Cobbler_PXE全自动网络部署Centos7_UEFI&BIOS
1.安装前准备
1.1下载镜像
Centos7.6(系统安装过程略)
Centos7.9
1.2PXE环境
文件服务器 172.17.10.198
PXE服务器 172.17.10.198
注意:此实验共用一台
1.3关闭Vmware软件中的DHCP服务
1.4关闭防火墙及SELINUX
禁用防火墙
systemctl disable firewalld
禁用SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
查看SELinux状态
getenforce
1.4配置yum源
更新yum源
cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-anon.repo
rpm -ivh --force https://mirrors.huaweicloud.com/epel/epel-release-latest-7.noarch.rpm
sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo
sed -i "s/metalink=/#metalink=/g" /etc/yum.repos.d/epel.repo
sed -i "s@http://download.fedoraproject.org/pub@https://mirrors.huaweicloud.com@g" /etc/yum.repos.d/epel.repo
yum clean all
yum makecache
2.安装相关软件包并启动服务
2.1安装cobbler
yum install cobbler -y
会依赖安装 httpd rsync tftp-server 等
2.2安装dhcp
yum install dhcp -y
后面改完配置dhcp文件再启动
2.3启动服务
监听 25151 和 80 端口
systemctl enable cobblerd
systemctl enable httpd
systemctl enable tftp
systemctl start tftp
systemctl start cobblerd
systemctl start httpd
systemctl status tftp
systemctl status cobblerd
systemctl status httpd
3.PXE环境配置
3.1检查安装
cobbler check
需要依次解决以下问题:
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.
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.
3 : change ‘disable’ to ‘no’ in /etc/xinetd.d/tftp
4 : 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.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : ksvalidator was not found, install pykickstart
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
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
Restart cobblerd and then run ‘cobbler sync’ to apply changes.
说明:
1、/etc/cobbler/settings 中配置 server 通常配置为本机IP
2、/etc/cobbler/settings 中配置 next_server 即tftp主机 通常配置为本机IP
3、启用tftp 默认为in.tftpd
4、执行 cobbler get-loaders 下载相关pxe文件
5、启动并开机运行 rsyncd 服务
6、适用于debian系统的配置,处理deb包 忽略
7、安装 pykickstart
8、在/etc/cobbler/settings中配置默认密码
9、安装fence-agents用于实现电源管理 忽略
所有配置完成后,重启cobblerd 并执行 cobbler sync应用变更
3.2检看 /etc/cobbler/settings 配置
3.2.1修改Cobbler配置文件
cp /etc/cobbler/settings /etc/cobbler/settings.bak
sed -ri 's/^(manage_dhcp: ).*/\11/' /etc/cobbler/settings
sed -ri 's/^(next_server: ).*/\110.0.0.199/' /etc/cobbler/settings
sed -ri 's/^(server: ).*/\110.0.0.199/' /etc/cobbler/settings
3.2.2修改Cobbler默认密码
openssl passwd -1 'root123'
/etc/cobbler/settings中搜索default_password
sed -ri 's/^(default_password_crypted: ).*/\1"$1$acW/GvRJ$pqXrTBYvoHyHIFrRens951"/' /etc/cobbler/settings
3.2.3重启cobbler服务,再次执行cobbler check
systemctl restart cobblerd
cobbler check
3.2.4配置DHCP
cp /etc/cobbler/dhcp.template /etc/cobbler/dhcp.template.bak
#先备份
vi /etc/cobbler/dhcp.template
#修改cobbler的自带的dhcp配置文件模板
3.3cobbler sync
#修改完成之后同步模板到/etc/dhcpd.conf
systemctl start dhcpd
systemctl enable dhcpd
3.4下载pxe启动的相关文件
cobbler get-loaders
#这个命令需要联网下载pxe启动的相关文件
3.5cobbler sync
上面的命令下载完成之后需要同步一下文件
#结尾出现*** TASK COMPLETE *** 就表示成功
3.6设置rsync
systemctl enable rsyncd #设置rsync开机自启
systemctl start rsyncd #启动rsync服务
3.7yum install pykickstart -y
3.8再次重启cobbler
systemctl restart cobblerd
cobbler check
剩下最后两项报错,一项是电源管理相关,另外一项是debian安装相关#当然了,这两项无关紧要,忽略掉,继续下一步操作。
3.9挂载映像文件并导入distro
如果读不到光盘
#定义扫盘别名
alias scandisk='echo - - - > /sys/class/scsi_host/host0/scan;echo - - - > /sys/class/scsi_host/host1/scan;echo - - - > /sys/class/scsi_host/host2/scan'
#查看光盘信息
cat /proc/sys/dev/cdrom/info
创建目录并挂载光盘
mkdir /mnt/centos7
mount /dev/sr0 /mnt/centos7
#创建目录并挂载光盘
cobbler import --path=/mnt/centos7 --name=Centos7.9 --arch=x86_64
#导入Centos7
3.10导入自定义的kickstart配置文件
ks文件
此处ks文件:UEFI模式,手动LVM分区
cp centos7.cfg /var/lib/cobbler/kickstarts/
#将配置文件复制到/var/lib/cobbler/kickstarts目录下
cobbler profile list
cobbler profile edit --name=Centos7.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
#导入对应的配置文件
cobbler report
cobbler report | grep "^Kickstart.*cfg$"
#查看一下是否已经导入进去了
cobbler check
cobbler sync
#动了配置文件就重新检查,并且同步
3.11修改pxe引导的菜单
vim /etc/cobbler/pxe/efidefault.template
timeout=60
#修改efidefault.template的菜单超时时间
#修改成60秒,不然太快,看不到菜单
4.其他
4.1UEFI模式下注意修改VM的引导方式
4.2添加其他版本操作系统
重复3.10-3.11步骤,注意不同操作系统不同版本ks文件可能会有差异
4.3 uefi模式下,设置默认从本地盘启动
修改以下配置文件
vi /etc/cobbler/pxe/efidefault.template
原文件内容:
修改为:
default=0
timeout=60
title local
quit
$grub_menu_items
重启和启动相关服务:
systemctl restart cobblerd
cobbler get-loaders
cobbler sync
cobbler check
修改后UEFI模式下PXE启动菜单效果如图: