Cobbler部署与配置
//关闭防火墙
[root@php ~]# systemctl disable --now firewalld.service
[root@php ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@php ~]# setenforce 0
setenforce: SELinux is disabled
//配置yum源
[root@php ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2595 100 2595 0 0 13657 0 --:--:-- --:--:-- --:--:-- 13657
[root@php ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
//配置epel源
[root@php ~]# yum -y install epel-release
//安装依赖包
[root@php ~]# dnf module enable cobbler
[root@php ~]# dnf -y install httpd dhcp-* tftp xinetd pykickstart cobbler cobbler-web rsync-daemon python3 tftp-server
//启动
[root@php ~]# systemctl enable --now httpd cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
//修改server的ip地址为本机ip
[root@php ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.47.129/' /etc/cobbler/settings.yaml
//设置tftp的ip地址为本机ip
[root@php ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.47.129/' /etc/cobbler/settings.yaml
//下载缺失文件
[root@php ~]# cobbler get-loaders
task started: 2021-10-13_024304_get_loaders
task started (id=Download Bootloader Content, time=Wed Oct 13 02:43:04 2021)
running python triggers from /var/lib/cobbler/triggers/task/get_loaders/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/get_loaders/pre/*
shell triggers finished successfully
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
//启动rsync并设置开机自启
[root@php ~]# systemctl enable --now rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
//生成加密的密码
[root@php ~]# openssl passwd -1 -salt "$RANDOM" '123456'
$1$5737$x7ovYIxKR02aelaEOFzI21 //加密后的密码
//将新生成的加密密码加入到配置文件
[root@php ~]# vim /etc/cobbler/settings.yaml
....
default_password_crypted: "$1$5737$x7ovYIxKR02aelaEOFzI21"
....
//重启cobbler
[root@php ~]# systemctl restart cobblerd
[root@php ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 0.0.0.0:873 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:443 0.0.0.0:*
LISTEN 0 5 127.0.0.1:25151 0.0.0.0:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
//检查问题 出现四个
[root@php ~]# cobbler check
The following are potential configuration items that you may want to fix:
1: reposync is not installed, install yum-utils or dnf-plugins-core
2: yumdownloader is not installed, install yum-utils or dnf-plugins-core
3: debmirror package is not installed, it will be required to manage debian deployments and repositories
4: 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.
#以上3、4是关于debian系统的错误,请忽略
//1、2问题解决方案
[root@php ~]# wget -P /etc/yum.repos.d/ https://copr.fedoraproject.org/coprs/jkastner/dnf-plugins-core/repo/epel-7/jkastner-dnf-plugins-core-epel-7.repo && yum install dnf-plugins-core
//再次查看
[root@php ~]# cobbler check
The following are potential configuration items that you may want to fix:
1: debmirror package is not installed, it will be required to manage debian deployments and repositories
2: 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配置文件,让cobbler控制dhcp
[root@php ~]# sed -i 's/^manage_dhcp: false/manage_dhcp: true/g' /etc/cobbler/settings.yaml #修改此处的值为true,表示让cobbler控制dhcp
//配置dhcp
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.47.0 netmask 255.255.255.0 {
option routers 192.168.47.129; #本地主机网段
option domain-name-servers 114.114.114.114; #本机IP
option subnet-mask 255.255.255.0; #子网掩码
range dynamic-bootp 192.168.47.20 192.168.47.200; #dhcp服务器分配的IP地址范围
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
class "pxeclients" {
//重启服务并同步配置,改完dhcp必须要sync同步配置
[root@php ~]# systemctl restart cobblerd
[root@php ~]# cobbler sync
task started: 2021-10-13_032729_sync
task started (id=Sync, time=Wed Oct 13 03:27:29 2021)
running python triggers from /var/lib/cobbler/triggers/task/sync/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/sync/pre/*
shell triggers finished successfully
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/redhat-8-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/system
removing: /var/lib/tftpboot/grub/system_link
removing: /var/lib/tftpboot/grub/grub.cfg
removing: /var/lib/tftpboot/grub/local_efi.cfg
removing: /var/lib/tftpboot/grub/local_legacy.cfg
removing: /var/lib/tftpboot/grub/local_powerpc-ieee1275.cfg
removing: /var/lib/tftpboot/images/redhat-8-x86_64
copying bootloaders
running: ['rsync', '-rpt', '--copy-links', '--exclude=.cobbler_postun_cleanup', '/var/lib/cobbler/loaders/', '/var/lib/tftpboot']
received on stdout:
received on stderr:
running: ['rsync', '-rpt', '--copy-links', '--exclude=README.grubconfig', '/var/lib/cobbler/grub_config/', '/var/lib/tftpboot']
received on stdout:
received on stderr:
copying distros to tftpboot
copying files for distro: redhat-8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/redhat-8-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/redhat-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/redhat-8-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/redhat-8-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: redhat-8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/redhat-8-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/redhat-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/redhat-8-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/redhat-8-x86_64/initrd.img
Writing template files for redhat-8-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
processing boot_files for distro: redhat-8-x86_64
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.service
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
shell triggers finished successfully
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running python trigger cobbler.modules.managers.genders
running shell triggers from /var/lib/cobbler/triggers/change/*
shell triggers finished successfully
*** TASK COMPLETE ***
//检查dhcp是否正常
[root@php ~]# ss -anulp| grep dhcp
UNCONN 0 0 0.0.0.0:40348 0.0.0.0:* users:(("dhcpd",pid=146845,fd=20))
UNCONN 0 0 0.0.0.0:67 0.0.0.0:* users:(("dhcpd",pid=146845,fd=10))
UNCONN 0 0 [::]:52014 [::]:* users:(("dhcpd",pid=146845,fd=21))
//导入安装镜像
[root@php ~]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
#参数说明
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
#安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:redhat-8.2-x86_64,如果重复,系统会提示导入失败