环境: CentOS 7 VMware Workstation Pro 14
介绍:
Cobbler 的优点:自动管理各个服务器间的配置,更强大的管理功能。而且它还有 Web 管理界面,可以通过点一点鼠标就可以安装一台主机。Kickstart 的模板文件可以配置多个。
Cobbler 运行流程
Server 端: 第一步:启动 Cobbler 服务 第二步:进行 Cobbler 错误检查,执行 Cobbler check 命令 第三步:进行配置同步,执行 Cobbler sync 命令 第四步:复制相关启动文件文件到 TFTP 目录中 第五步:启动 DHCP 服务,提供地址分配 第六步:DHCP 服务分配 IP 地址 第七步:TFTP 传输启动文件 第八步:Server 端接收安装信息 第九步:Server 端发送 ISO 镜像不 Kickstart 文件
Client 端: 第一步:客户端以 PXE 模式启动 第二步:客户端获取 IP 地址 第三步:通过 TFTP 服务器获取启动文件 第四步:进入 Cobbler 安装选择界面 第五步:客户端确定加载信息 第六步:根据配置信息准备安装系统 第七步:加载 Kickstart 文件 第八步:传输系统安装的其它文件 第九步:进行安装系统
实战:
IP地址:192.168.20.104
Cobbler 服务端对内存的要求不高,只要能把Cobbler服务跑起来就行。但是客户端对内存有要求,文章后面会说。
1、关闭selinux和防火墙
systemctl stop firewalld.service && systemctl disable firewalld.service && iptables -F && setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
2、配置好网络源
cat >> /etc/yum.repos.d/CentOS-Base.repo << EOF
[aliyun-os]
name=aliyun-os
baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
enabled=1
gpgcheck=0
[aliyun-epel]
name=aliyun-epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0
[aliyun-extra]
name=aliyun-extra
baseurl=https://mirrors.aliyun.com/centos/7/extras/x86_64/
enabled=1
gpgcheck=0
EOF
yum install -y epel-release #Cobbler 和 tftp-server 在 base 源中是没有的
yum install -y cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd
软件作用说明 cobbler #Cobbler 程序包 cobbler-web #Cobbler 的 Web 服务包 pykickstart #Cobbler 检查 kickstart 语法错误 httpd #Apache Web 服务
Cobbler 工作目录介绍
[root@server104 ~]# ls /etc/cobbler/
auth.conf genders.template named.template secondary.template zone.template cheetah_macros import_rsync_whitelist power settings zone_templates cobbler_bash iso pxe tftpd.template completions ldap reporting users.conf dhcp.template modules.conf rsync.exclude users.digest dnsmasq.template mongodb.conf rsync.template version
/etc/cobbler # 配置文件目录
/etc/cobbler/settings # Cobbler 主配置文件,这个文件是 YAML 格式,Cobbler 是 python 写的程序。
/etc/cobbler/dhcp.template # DHCP服务的配置模板
/etc/cobbler/tftpd.template # tftp 服务的配置模板
/etc/cobbler/rsync.template # rsync 服务的配置模板
/etc/Cobbler/iso # iso 模板配置文件目录
/etc/cobbler/pxe # pxe 模板文件目录
/etc/cobbler/power # 电源的配置文件目录
/etc/cobbler/users.conf # Web 服务授权配置文件
/etc/cobbler/users.digest # 用于 Web 访问的用户名密码配置文件 /etc/cobbler/dnsmasq.template # DNS 服务的配置模板
/etc/cobbler/modules.conf # Cobbler 模块配置文件
/var/lib/cobbler # Cobbler 数据目录
/var/lib/cobbler/config # 配置文件
/var/lib/cobbler/kickstarts # 默认存放 kickstart 文件
/var/lib/cobbler/loaders # 存放的各种引导程序
/var/www/cobbler # 系统安装镜像目录
/var/www/cobbler/ks_mirror # 导入的系统镜像列表
/var/www/cobbler/images # 导入的系统镜像启动文件
/var/www/cobbler/repo_mirror # yum 源存储目录
/var/log/cobbler # 日志目录
/var/log/cobbler/install.log # 客户端系统安装日志
/var/log/cobbler/cobbler.log # Cobbler 日志
3、启动 Cobbler 和 httpd 服务
systemctl start cobblerd httpd
检查 Cobbler 配置
cobbler check
[root@server104 ~]$ cobbler check
The following are potential configuration items that you may want to fix:
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. 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.
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 : 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
8 : 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.
我们会发现出现了8个问题,需要去逐条解决
问题1:
vim /etc/cobbler/settings
将 390 行的 server 地址改为服务端的 IP (192.168.20.104)
问题2:
vim /etc/cobbler/settings
将 278 行的 next_server 地址改为服务端的 IP (192.168.20.104)
问题3:修改 tftp 服务被 xinetd 服务管理
vim /etc/xinetd.d/tftp
将 14 行的 disable = yes 改为 disable = no
顺便修改 xinetd 和 tftpd 服务开机启动
systemctl start xinetd tftp && systemctl enable xinetd tftp
问题4:下载操作系统引导文件
cobbler get-loaders
我们发现会报错:No such command: get-loaders
还有一个解决方法:即安装syslinux,我们可以直接通过YUM的方式进行安装,安装后,尽管cobbler check命令依然报错,但是我们可以不用理会该报错,直接进行cobbler的下一步配置即可!
问题5:修改 rsyncd 服务为开机自启动状态并启用它。
systemctl start rsyncd && systemctl enable rsyncd
问题6:debmirror package is not installed, it will be required to manage debian deployments and repositories
关于 debian 相关部署管理配置,忽略。
问题7:修改操作系统默认密码
openssl passwd -1 -salt 'root' '7777777'
$1$root$lUk924UEnkkVfR5NXuBYn.
vim /etc/cobbler/settings
将 101 行 单引号里面的一串字符改为上面输出的那一行:$1$root$lUk924UEnkkVfR5NXuBYn.
注:root 为用户描述,7777777 为密码
问题8:fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
电源管理相关服务,忽略
4、接下来检查 DHCP 配置,由于 Cobbler 自动管理 DHCP 服务,我们只需要修改 Cobbler 中的模板配置文件即可。
vim /etc/cobbler/dhcp.template
将 21 行开始的 IP 改为我们自己使用的服务器的实际 IP
参考如下:
21 subnet 192.168.20.0 netmask 255.255.255.0 {
22 option routers 192.168.20.2;
23 option domain-name-servers 114.114.114.114;
24 option subnet-mask 255.255.255.0;
25 range dynamic-bootp 192.168.20.100 192.168.20.254;
26 default-lease-time 21600; 27 max-lease-time 43200; 28 next-server $next_server;
修改 Cobbler 管理 dhcp 服务
vim /etc/cobbler/settings
将 242 行的 manage_dhcp: 0 改为 manage_dhcp: 1
同步配置文件,需要先重启 Cobblerd
systemctl restart cobblerd
cobbler sync
task started: 2023-01-02_033213_sync
task started (id=Sync, time=Mon Jan 2 03:32:13 2023)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart dhcpd.servicerunning shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
如果出现上面这样的输出,那么表明这一步就成功了
重新检查一下 Cobbler
cobbler check
The following are potential configuration items that you may want to fix:
1 : Some network boot-loaders are missing from /var/lib/cobbler/loaders. 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.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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.
发现有这三个问题,都可以忽略。
现在,Cobbler 服务配置完成。
技术交流:🐧 748360476
5、导入镜像以及配置
添加镜像
打开设置
找到对应的镜像放上来
注意:下面一步可以后面再执行,因为操作完后就不能在 Xshell 上操作了,只能在 VMware Workstation 上操作了,减少了方便性
1、选择网络适配器
2、选择 LAN 区段
3、点击 LAN 区段
4、添加全局 LAN 区段
5、添加完后点击确定
6、选择自己想要的 LAN 区段
7、点击确定
挂载光驱
1、暂时挂载(重启便失效)
mkdir /yum
mount /dev/sr0 /yum
2、永久挂载(重启还有效)
echo /dev/cdrom /yum iso9660 defaults 0 0 >> /etc/fstab
mount -a
df -h #查看是否挂载成功
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 37G 1.4G 36G 4% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.6M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 143M 872M 15% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /yum
导入镜像(时间较长)
cobbler import --path=/yum/ --name=CentOS-7.6 --arch=x86_64
task started: 2023-01-02_040012_import
task started (id=Media import, time=Mon Jan 2 04:00:12 2023)
Found a candidate signature: breed=suse, version=opensuse15.0
Found a candidate signature: breed=suse, version=opensuse15.1
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64:
creating new distro: CentOS-7.6-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64 -> /var/www/cobbler/links/CentOS-7.6-x86_64
creating new profile: CentOS-7.6-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64 for CentOS-7.6-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7.6-x86_64/repodata
*** TASK COMPLETE ***
查看镜像,上面是镜像名称,下面是启动菜单。
cobbler list
distros: CentOS-7.6-x86_64
profiles: CentOS-7.6-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
同步 Cobbler 配置
systemctl restart cobblerd
cobbler sync
6、安装主机
当前为虚拟机操作,虚拟机默认为 PXE 引导,如果是生产环境请进入 BIOS 修改 PXE 引导。
新建虚拟机
这里最好将内存调大一点,然后在网络适配器选项里选择 LAN 区段 ,要跟服务器的 LAN 区段一样
启动刚创建的新机器,看看会不会自动安装
选择CentOS-7.6-x86_64
回车
这时在加载引导文件
已经在安装中了, 默认是最小化安装,大概 311个包(数量不一定是311)
可能会出现的问题
如果遇到 write error: No space left on device 报错,则需要把虚拟机的内存调大一点:
关机,将内存调大一点
用户名:root
密码:7777777
可以 ping 通服务器的IP:192.168.20.104 ,但是不能 ping 通外网 ,想要 ping 通外网,需要将 LAN1 模式,改为桥接,就可以了。
至此,cobbler 无人值守安装服务已经完成了