cobbler搭建
关闭防火墙
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
[root@localhost ~]# reboot
下载epel源
yum -y install epel-release
下载依赖包
yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart
启动服务并设置开机自启
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start cobblerd
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl enable cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
修改server得ip地址为本机ip地址
修改tftp得ip地址为本机ip地址
开启tftp
[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.100.153/' /etc/cobbler/settings
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.100.153/' /etc/cobbler/settings
[root@localhost ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
启动rsync并设置开机自启
[root@localhost ~]# systemctl start rsyncd
[root@localhost ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
生成加密密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'shenlongfei'
$1$28958$sq1sJFDX0bZo.H8Q.8NLg0 //这是密码加密后的形式
将新生成得密码加入到配置文件
[root@localhost ~]# vim /etc/cobbler/settings
.... //此处为省略内容
default_password_crypted: "$1$28958$sq1sJFDX0bZo.H8Q.8NLg0"
..... //此处为省略内容
重启cobbler
[root@localhost ~]# systemctl restart cobblerd
解决报错(cobbler check)
[root@localhost ~]# yum -y install fence-agents debmirror yum-utils syslinux
[root@localhost ~]# sed -i 's|@dists=.*|#@dists=|' /etc/debmirror.conf
[root@localhost ~]# sed -i 's|@arches=.*|#@arches=|' /etc/debmirror.conf
[root@localhost ~]# systemctl restart cobblerd.service
[root@localhost ks_mirror]# 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, 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. //这个错误可以忽略
Restart cobblerd and then run 'cobbler sync' to apply changes.
[root@localhost ks_mirror]#
在centos8上面把(/var/lib/cobbler/loaders)下面文件copy一份到centos7里面来,路径一样
[root@localhost cobbler]# scp loaders/* root@192.168.100.153:/var/lib/cobbler/loaders/ //在centos8上面执行操作
root@192.168.100.153's password:
COPYING.syslinux 100% 9339 8.7MB/s 00:00
COPYING.yaboot 100% 9339 8.9MB/s 00:00
grub-x86_64.efi 100% 9339 10.9MB/s 00:00
grub-x86.efi 100% 9339 10.6MB/s 00:00
menu.c32 100% 26KB 20.9MB/s 00:00
pxelinux.0 100% 41KB 28.0MB/s 00:00
README 100% 9339 9.8MB/s 00:00
yaboot 100% 9339 9.2MB/s 00:00
[root@localhost cobbler]#
查看centos7是否有这些文件
[root@localhost ks_mirror]# cd /var/lib/cobbler/loaders/
[root@localhost loaders]# ls
COPYING.syslinux COPYING.yaboot grub-x86_64.efi grub-x86.efi menu.c32 pxelinux.0 README yaboot
[root@localhost loaders]# //copy成功
重启并检查配置是否报错
[root@localhost ~]# systemctl restart cobblerd
[root@localhost loaders]# 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, 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.
Restart cobblerd and then run 'cobbler sync' to apply changes.
[root@localhost loaders]# //此报错忽略,因为我们已经把相应的文件copy过来了
配置dchp
[root@localhost ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@localhost ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1
[root@localhost loaders]# vim /etc/cobbler/dhcp.template
略。。。。。。
subnet 192.168.100.0 netmask 255.255.255.0 {
option routers 192.168.100.153;
option domain-name-servers 192.168.100.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.100.100 192.168.100.254;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
略。。。。。。
重启服务并同步配置,改完dhcp必须要sync同步
[root@localhost ~]# systemctl restart cobblerd
[root@localhost loaders]# cobbler sync
task started: 2021-10-13_224857_sync
task started (id=Sync, time=Wed Oct 13 22:48:57 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying distros to tftpboot
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-7-x86_64/initrd.img
Writing template files for centos-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos-7-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/*
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 ***
[root@localhost loaders]#
检查dhcp是否正常
[root@localhost loaders]# netstat -anulp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 105802/dhcpd
[root@localhost loaders]#
导入centos8的镜像
先挂载
[root@localhost ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cobbler import --path=/mnt --name=centos-7 --arch=x86_64
task started: 2021-10-13_193645_import
task started (id=Media import, time=Wed Oct 13 19:36:45 2021)
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-x86_64:
creating new distro: centos-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos-7-x86_64 -> /var/www/cobbler/links/centos-7-x86_64
creating new profile: centos-7-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-x86_64 for centos-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos-7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos-7-x86_64
looking for /var/www/cobbler/ks_mirror/centos-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos-7-x86_64/repodata
*** TASK COMPLETE ***
//说明:
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
//安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败
查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
centos-7-x86_64
profiles:
centos-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
创建kickstarts自动安装脚本
[root@localhost ~]# cat /var/lib/cobbler/kickstarts/centos-7-x86_64.ks
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.153.146/cobbler/ks_mirror/centos-7-x86_64 //此目录为/var/www/cobbler/ks_mirror/centos-7-x86_64/这个cobbler后面的目录
$yum_repo_stanza
reboot
rootpw --iscrypted $6$yjjcqhzrGUFZH4KP$99Dume6ZsJn3IN51w/2lNc2ihRmfddQTEYtvINSl7mXwvtyXzW72xAwSYXYDJaXl2zz7rM1FXNJcwYiRYlwtq0 //改为主机上(anaconda-ks.cfg)的密码
selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr
%packages
@^minimal
@core
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
检查ks文件语是否正确
[root@localhost loaders]# cobbler validateks
task started: 2021-10-13_225231_validateks
task started (id=Kickstart Validation, time=Wed Oct 13 22:52:31 2021)
----------------------------
osversion: rhel7
checking url: http://192.168.100.153/cblr/svc/op/ks/profile/centos-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.100.153/cblr/svc/op/ks/profile/centos-7-x86_64"
received on stdout:
received on stderr:
Potential templating errors:
Unknown variable found at line 16, column 22: '$wtUGWEFcVXliFhg3'
Unknown variable found at line 16, column 39: '$j8BNqzMKLZWNKtovEr8ivMJwvLTJSEOwWhYtpDKaDOtQ2SjaMRlL3RJrbk1mVeOhHRvfbn9DW0S1'
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
[root@localhost loaders]#
修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@localhost ~]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
配置网卡名称为传统网卡名称eth0
[root@localhost ~]# cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
检查cobbler配置信息
[root@localhost ~]# cobbler profile report
Name : centos-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : centos-7-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/centos-7-x86_64.ks
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
同步cobbler
[root@localhost ~]# cobbler sync
task started: 2021-10-13_201500_sync
task started (id=Sync, time=Wed Oct 13 20:15:00 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying distros to tftpboot
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-7-x86_64/initrd.img
Writing template files for centos-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos-7-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/*
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 ***
为避免发生问题,先重启服务
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::443 :::*
LISTEN 0 5 :::873 :::*
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
cp:是否覆盖"/var/lib/cobbler/loaders/pxelinux.0"? y
[root@localhost ~]#
[root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
cp:是否覆盖"/var/lib/cobbler/loaders/menu.c32"? y
[root@localhost ~]# systemctl restart cobblerd //解决安装虚拟机打开考试tftp
创建虚拟机测试,虚拟机不用给镜像
密码用户都是cobbler