前言:
DHCP服务:提供网络参数(IP、掩码、网关、DNS),告知客户端TFTP服务器的位置(DHCP option 66~67)
TFTP:提供boot loader及kernel file下载路径
HTTP/FTP/NFS: 提供系统镜像与配置文件的存放路径(三种方案用哪种都可以)
工作原理图如下:
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检查
综上经过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命令下载这些文件.
错误内容 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
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
2.3.5 执行cobbler sync让配置生效
[root@localhost conf.d]# cobbler sync
2.3.6 启用cobbler web管理
通过Cobbler WEB我们可以通过图形化的方式对cobbler进行管理, 网址为 http://172.16.70.81/cobbler_web. 默认账号密码均为cobbler
2.3.7 cobbler web相关配置文件查看
[root@localhost web]# cat /etc/cobbler/users.digest
综上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
3.3 镜像导入成功后我们可以查看其相关信息
[root@localhost web]# cobbler list
[root@localhost web]# cobbler report
Sample_end.ks是安装系统时候默认执行的脚本, 这个脚本有可能并不符合我们的需求, 但这个脚本却是可用的, 后续我们可以通过kickstart去生成一个适合我们使用的脚本.
3.4 正式部署操作系统前的准备工作
3.5 开始自动化部署 新建裸虚拟机一台, 开机按F12通过PXE方式进行网络启动
经过一段时间的等待,操作系统部署成功
注:
被安装操作系统的物理机或虚拟机内存必须为2G以上,否则会在安装过程中报错,提示资源不够.
如果想要自定义ks文件,可以安装kickstart服务进行配置生成,安装kickstart后若服务启动失败,并且提示 “Package selection is disabled due to problems downloading package information” 错误,解决办法为创建一个名叫development.repo的仓库文件
添加以下内容: